From 5fea243e1a50fe2df7957b5f0d3b5b70146da56f Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 28 Oct 2021 14:26:36 +0200 Subject: [PATCH] [IMP] sale: Convert _onchange_pricelist_id into compute method --- addons/sale/models/sale_order.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 588f26c23e1..bdfef64c6e4 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -282,9 +282,11 @@ class SaleOrder(models.Model): string='Transactions', copy=False, readonly=True) authorized_transaction_ids = fields.Many2many('payment.transaction', compute='_compute_authorized_transaction_ids', string='Authorized Transactions', copy=False) - show_update_pricelist = fields.Boolean(string='Has Pricelist Changed', - help="Technical Field, True if the pricelist was changed;\n" - " this will then display a recomputation button") + show_update_pricelist = fields.Boolean( + string='Has Pricelist Changed', + compute='_compute_show_update_pricelist', store=True, readonly=True, + help="Technical Field, True if the pricelist was changed;\n" + " this will then display a recomputation button") tag_ids = fields.Many2many('crm.tag', 'sale_order_tag_rel', 'order_id', 'tag_id', string='Tags') # UTMs - enforcing the fact that we want to 'set null' when relation is unlinked campaign_id = fields.Many2one(ondelete='set null') @@ -513,12 +515,10 @@ class SaleOrder(models.Model): } } - @api.onchange('pricelist_id', 'order_line') - def _onchange_pricelist_id(self): - if self.order_line and self.pricelist_id and self._origin.pricelist_id != self.pricelist_id: - self.show_update_pricelist = True - else: - self.show_update_pricelist = False + @api.depends('pricelist_id', 'order_line') + def _compute_show_update_pricelist(self): + for order in self: + order.show_update_pricelist = order.order_line and order.pricelist_id and order._origin.pricelist_id != self.pricelist_id def update_prices(self): self.ensure_one()