Sorting Model List in proteus

89 views
Skip to first unread message

Maxime Richez

unread,
Sep 25, 2017, 10:58:45 AM9/25/17
to tryton
Hi,

I'm trying to sort a model list in proteus with sorted function... so i apply sort on each element of my model list and store them in a list, pop each record of my "unordered" model list, then try to append each record in my empty model list but get an error "assert record._parent is None"...
What's wrong with my scenario ?

https://pastebin.com/mcd2iTAA

Thanks for help !

Cédric Krier

unread,
Sep 26, 2017, 3:35:08 AM9/26/17
to tryton
On 2017-09-25 07:58, Maxime Richez wrote:
> Hi,
>
> I'm trying to sort a model list in proteus with sorted function... so
> i apply sort on each element of my model list and store them in a
> list, pop each record of my "unordered" model list, then try to append
> each record in my empty model list but get an error "assert
> record._parent is None"...

It is strange because .pop set the _parent attribute to None.
Are you sure you remove all the records?

Indeed I would write the code like this:

while request.quotation_lines:
request.quotation_lines.pop()
request.quotation_lines.extend(sorted_quotations)

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Maxime Richez

unread,
Sep 26, 2017, 5:55:27 AM9/26/17
to tryton
> It is strange because .pop set the _parent attribute to None.
> Are you sure you remove all the records?
>
> Indeed I would write the code like this:
>
> while request.quotation_lines:
> request.quotation_lines.pop()
> request.quotation_lines.extend(sorted_quotations)
>

Thanks !
I applied your code, now i get an error on a required field...
"UserError: The field "Request" on "Purchase Request For Quotation Line" is required."
Is there a bug ?

Cédric Krier

unread,
Sep 26, 2017, 6:35:06 AM9/26/17
to tryton
It seems. I think the record_removed and record_deleted are not updated
when adding back the same record.

Maxime Richez

unread,
Sep 26, 2017, 7:43:28 AM9/26/17
to tryton

> It seems. I think the record_removed and record_deleted are not updated
> when adding back the same record.
>
Indeed, it works if i remove "self.record_removed.add(self[index])" in pop method (line 569 - proteus/__init__.py)

Maxime Richez

unread,
Sep 26, 2017, 7:52:02 AM9/26/17
to tryton
Is clearing record_removed and record_deleted sets in extend method a good solution?

Cédric Krier

unread,
Sep 26, 2017, 8:15:06 AM9/26/17
to tryton
Proteus should do it transparently.

Maxime Richez

unread,
Sep 26, 2017, 9:15:32 AM9/26/17
to tryton

> Proteus should do it transparently.
>
I create an issue:

https://bugs.tryton.org/issue6784

Reply all
Reply to author
Forward
0 new messages