Hello there,
I need to override the write function and from inside it, to write in an other record (after the current record has been saved). This code creates a "maximal recursion depth exceeded" because the write function is calling itself from the write function. I read on stark overflow that you can get around this by doing something like this:
@api.multi
def write(self, vals):
if 'custom_field' not in vals:
vals['custom_field'] = 37
return super(self).write(vals)
but this only writes in the current record. I need the values of some other records (of the same model -hr.expense-) to be updated as well. If using "update" instead of "write, it doesn't update the field total amount. Here is my code.
How can i fix this?
[infos: v9 community, module concerned: hr. expense]
@api.multi
def write(self, vals):
self.update_other_dest_ids()
value = super(Expenses, self).write(vals)
self.search_and_modify_connected_travel()
for tagx in self.expenses_summary_ids
if tagx.time is not '24:00':
exps = self.find_all_expenses_on_same_day(tagx.day)
for each in exps:
each._update_unit_price()
return value
@api.one
@api.depends('expenses_summary_ids.amount_due')
def _update_unit_price(self):
if self.expenses_calculator:
table_sum = 0.0
for expense in self:
for line in expense.expenses_summary_ids:
table_sum += line.amount_due
if self.calculated_unit_amount != table_sum:
self.write({'calculated_unit_amount' : table_sum})
if self.unit_amount != table_sum:
self.write({'unit_amount' : self.calculated_unit_amount})