Hi,
I tried to extend the Sale module such that if a carrier is selected, a suitable shipping line is automatically added (staying in draft state without quotation).
@fields.depends('carrier')
def on_change_carrier(self):
pool = Pool()
SaleLine = pool.get('sale.line')
if self.carrier:
line = SaleLine(type='line')
line.sale = self
line.product = self.carrier.carrier_product
line.quantity = 1
line.on_change_product()
self.lines = self.lines + (line,)
However, this gives me the following assertion error:
What I meant is adding the default carrier product with standard price which in my case is mostly sufficient and if not it can easily be adjusted.
I tried to add lines to the decorator but get the same error.
This happens when I call the on_change_product() as above:
File "/home/tryton/trytond/trytond/protocols/wrappers.py", line 208, in wrapper
result = func(request, pool, *args, **kwargs)
File "/home/tryton/trytond/trytond/protocols/dispatcher.py", line 221, in _dispatch
result = rpc.result(meth(inst, *c_args, **c_kwargs))
File "/home/tryton/trytond/trytond/model/fields/field.py", line 195, in on_change_result
return record._changed_values
File "/home/tryton/trytond/trytond/model/modelview.py", line 919, in _changed_values
added_values = target._changed_values
File "/home/tryton/trytond/trytond/model/modelview.py", line 891, in _changed_values
assert hasattr(init_record, fname), (init_record, fname)