From 581c16ef94798efc8f3720829b97e63354ce948b Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Thu, 3 Jan 2019 13:52:01 +0000 Subject: [PATCH] [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 17c9b7afee219e86e48035044570939a70fb18f3 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 --- addons/sale/models/sale.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 0c42e2bc529..b59f19623ac 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -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):