[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) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2022-02-28 13:53:28 +00:00
parent 4f7d833cf0
commit c9ab9e0a43
2 changed files with 5 additions and 6 deletions
+4 -5
View File
@@ -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()
+1 -1
View File
@@ -257,7 +257,7 @@
<label for="date_order" string="Order Date"/>
</div>
<field name="date_order" attrs="{'required': [('state', 'in', ['sale', 'done'])], 'invisible': [('state', 'in', ['draft', 'sent'])]}" nolabel="1"/>
<field name="show_update_pricelist" invisible="1" force_save="1"/>
<field name="show_update_pricelist" invisible="1"/>
<label for="pricelist_id" groups="product.group_product_pricelist"/>
<div groups="product.group_product_pricelist" class="o_row">
<field name="pricelist_id" options="{'no_open':True,'no_create': True}"/>