[FIX] sale: only create one activity to upsell a SO

Create a Sale Order linked to a timesheet, for k hours.
Add the a line for the k hours, invoice the SO.
Then, next time you add a line or modify the value of an existing line,
the SO invoice_status becomes "upselling".
Then, everytime you do it again, it triggers a recompute which writes the
invoice_status "upselling" on the SO.

Now since commit 17c9b7afee every time you write
an invoice_status as "upselling" this creates a new activity to upsell the SO.
However it was intended to run only once, the first time the status changes.

Before creating an activity, we check what was the invoice_status to ignore
records that were already in that state.

opw 1911642
opw 1919283
opw 1919284

closes odoo/odoo#29891
This commit is contained in:
Nans Lefebvre
2019-01-03 13:52:04 +00:00
parent 62221bc3f9
commit 581c16ef94
+6 -4
View File
@@ -391,11 +391,13 @@ class SaleOrder(models.Model):
if self.env.context.get('mail_activity_automation_skip'):
return super(SaleOrder, self)._write(values)
res = super(SaleOrder, self)._write(values)
if 'invoice_status' in values:
self.activity_unlink(['sale.mail_act_sale_upsell'])
if values['invoice_status'] == 'upselling':
for order in self.filtered('user_id'):
filtered_self = self.search([('id', 'in', self.ids),
('user_id', '!=', False),
('invoice_status', '!=', 'upselling')])
filtered_self.activity_unlink(['sale.mail_act_sale_upsell'])
for order in filtered_self:
order.activity_schedule(
'sale.mail_act_sale_upsell',
user_id=order.user_id.id,
@@ -403,7 +405,7 @@ class SaleOrder(models.Model):
order._name, order.id, order.name,
order.partner_id._name, order.partner_id.id, order.partner_id.display_name))
return res
return super(SaleOrder, self)._write(values)
@api.multi
def copy_data(self, default=None):