on_change - show records and remove records in o2m field

39 views
Skip to first unread message

Raimon Esteve

unread,
Nov 17, 2015, 5:59:38 AM11/17/15
to try...@googlegroups.com
Hie,

I have this code (is a wizard view)

class ShipmentOutPicking(ModelView):
__name__ = 'stock.shipment.out.picking'
shipment = fields.Many2One('stock.shipment.out', 'Shipment', required=True)
moves = fields.One2Many('stock.move', None, 'Moves', readonly=True)

def on_change_shipment(self, name=None):
res = {}
if self.shipment:
res['moves'] = [m.id for m in self.shipment.inventory_moves]
return res


1- Show moves

When select a shipment, add all shipment inventory moves in moves
field. I show moves in this field.

- v3.4

This code work successfully. It's ok.

- v3.8

This code doesn't work successfully

When on_change, the client get record2.id a negative id and add in
to_create list.
In v3.4 I recibe a positive id and add in to_add. Is the reason v3.4
work successfully and v3.8 not.

(1) to_add/to_create when record2.id > 0

Why am I missing in v3.8? or is a bugin v3.8?

Finally I changed "on_change_shipment()" to "on_change_with_moves()"
and v3.4 and v3.8 are working successfully.

2- Remove moves

How to remove records in moves filed (o2m) ?

I try this code:

@fields.depends('shipment')
def on_change_with_moves(self, name=None):
if self.shipment:
return [m.id for m in self.shipment.inventory_moves]
else:
return [] # what am I missing?

- v3.4

When remove shipment call "on_change" and enter in else.
But don't remove records. (nothing).

- v3.8

When remove shipment call "on_change" and enter in else.
Change black moves records to grey color (remove).

My wish list:

Is it possible to delete records in moves field when deselect a
shipment (reload)?

(1) http://hg.tryton.org/tryton/file/ed92378d8fdc/tryton/gui/window/view_form/model/field.py#l527

Thanks

--
Raimon

Cédric Krier

unread,
Nov 21, 2015, 8:35:08 AM11/21/15
to try...@googlegroups.com
No it is not a bug. on_change must update the record values and no more
return something. And if you had set the correct fields.depends
decorator it will have raise an error because you can no more return
something.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages