From c9ab9e0a4337ff496834796e164fddfa203575a8 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 24 Feb 2022 14:45:03 +0000 Subject: [PATCH] [REV] sale: keep show_update_pricelist logic in onchange Recently, onchanges have been converted to computed fields in sale scope (See #79093). But we noticed the conversion of the logic allowing users to update the prices of existing lines if the pricelist was modified didn't behave correctly as a precomputed computed field. This commit reverts this change and brings back the behavior of show_update_pricelist as a field update through onchange. Fixes two problem: * Show_update_pricelist value on new sales orders was not saved * SO created programmatically (not through the interface) always had show_update_pricelist set as True, even if the pricelist wasn't modified. This meant that orders created by a connector (ebay, amazon, ...) showed the "Update Prices" button even when it made no sence because the prices were specified by the connector. closes odoo/odoo#85506 X-original-commit: 99313bcff9f99215fda176f3e92516b1da16e579 Signed-off-by: Victor Feyens (vfe) --- addons/sale/models/sale_order.py | 9 ++++----- addons/sale/views/sale_order_views.xml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 8e644c6ff27..ee8b21a5201 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -289,7 +289,6 @@ class SaleOrder(models.Model): string='Authorized Transactions', copy=False) show_update_pricelist = fields.Boolean( string='Has Pricelist Changed', - compute='_compute_show_update_pricelist', store=True, readonly=True, precompute=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') @@ -555,10 +554,10 @@ class SaleOrder(models.Model): } } - @api.depends('pricelist_id') - 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 + @api.onchange('pricelist_id') + def _onchange_pricelist_id_show_update_prices(self): + if self.order_line and self.pricelist_id and self._origin.pricelist_id != self.pricelist_id: + self.show_update_pricelist = True def update_prices(self): self.ensure_one() diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index 90747f8afe0..ce336efcb37 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -257,7 +257,7 @@