Trying to remove values from on_change One2Many field causes error when field has no value
I found this issue while using the sale_cost_plan [1] module.
When trying to create a cost_plan from the sale_line form i get the following traceback:
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py", line 216, in sig_new
WinForm(screen, callback, new=True, save_current=True)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/win_form.py", line 35, in __init__
self.screen.new()
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/screen/screen.py", line 448, in new
record = group.new(default)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/group.py", line 313, in new
record.default_get()
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/record.py", line 376, in default_get
self.set_default(vals)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/record.py", line 434, in set_default
self.validate(softvalidation=True)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/record.py", line 403, in validate
if not field.validate(self, softvalidation):
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/field.py", line 116, in validate
self.set_client(record, value)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/field.py", line 404, in set_client
force_change=force_change)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/field.py", line 141, in set_client
self.sig_changed(record)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/field.py", line 41, in sig_changed
record.on_change(self.name, self.attrs['on_change'])
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/record.py", line 540, in on_change
self.set_on_change(res)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/record.py", line 487, in set_on_change
field_x2many.set_on_change(self, value)
File "/home/sergi/nan/projectes/virtualenv/teb/tryton/tryton/gui/window/view_form/model/field.py", line 697, in set_on_change
for record2 in record.value[self.name]:
This is because the domain inversion sets the product value, and so calls the on_change_product [2] of cost_plan, which returns the following values:
{
'bom': None,
'uom': 2,
'boms': {'remove': [], 'add': []}
}
Then it tries to set the values for the fields, which breaks on boms as it's not defined for the current record.
I'm was not able to reproduce it on sao (as I can not create sale_lines), but reading the code it seems that the bug is also there.
This also affects 3.2 (so it will be great if it can be backported) and maybe too to older versions.
[1] https://bitbucket.org/nantic/trytond-sale_cost_plan
[2] https://bitbucket.org/nantic/trytond-product_cost_plan/src/a7ef5b1c6bb447ada36b45d48703047602656dfe/plan.py?at=default#cl-109
Files
Download | Creator | Timestamp | Type |
---|---|---|---|
issue4258.patch | @pokoli | 2014-10-20 13:50:45.335000 UTC | text/plain |