Skip to content
Snippets Groups Projects
Commit 37cd2a19 authored by Victor Feyens's avatar Victor Feyens
Browse files

[FIX] sale: correct ordering of onchange updates


Since e9ad3442, on product change,
the uom & qty were only reset to defaults after the price & tax
recomputation.

This commit brings back the previous (and correct) behavior, by updating
the uom & qty alongside the description, before the taxes & price updates.

closes odoo/odoo#121883

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: default avatarDuong Kim <81897633+kimduong986@users.noreply.github.com>
parent 48b83351
No related branches found
No related tags found
No related merge requests found
......@@ -606,6 +606,15 @@ class SaleOrderLine(models.Model):
@api.onchange('product_id')
def product_id_change(self):
if not self.product_id:
return
if not self.product_uom or (self.product_id.uom_id.id != self.product_uom.id):
self.update({
'product_uom': self.product_id.uom_id,
'product_uom_qty': self.product_uom_qty or 1.0
})
self._update_description()
self._update_taxes()
......@@ -623,6 +632,7 @@ class SaleOrderLine(models.Model):
def _update_description(self):
if not self.product_id:
return
valid_values = self.product_id.product_tmpl_id.valid_product_template_attribute_line_ids.product_template_value_ids
# remove the is_custom values that don't belong to this template
for pacv in self.product_custom_attribute_value_ids:
......@@ -634,49 +644,39 @@ class SaleOrderLine(models.Model):
if ptav._origin not in valid_values:
self.product_no_variant_attribute_value_ids -= ptav
vals = {}
if not self.product_uom or (self.product_id.uom_id.id != self.product_uom.id):
vals['product_uom'] = self.product_id.uom_id
vals['product_uom_qty'] = self.product_uom_qty or 1.0
lang = get_lang(self.env, self.order_id.partner_id.lang).code
product = self.product_id.with_context(
lang=lang,
)
self.update({'name': self.with_context(lang=lang).get_sale_order_line_multiline_description_sale(product)})
self.update({
'name': self.with_context(lang=lang).get_sale_order_line_multiline_description_sale(product)
})
def _update_taxes(self):
if not self.product_id:
return
vals = {}
if not self.product_uom or (self.product_id.uom_id.id != self.product_uom.id):
vals['product_uom'] = self.product_id.uom_id
vals['product_uom_qty'] = self.product_uom_qty or 1.0
product = self.product_id.with_context(
partner=self.order_id.partner_id,
quantity=vals.get('product_uom_qty') or self.product_uom_qty,
date=self.order_id.date_order,
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id
)
self._compute_tax_id()
if self.order_id.pricelist_id and self.order_id.partner_id:
vals['price_unit'] = product._get_tax_included_unit_price(
self.company_id,
self.order_id.currency_id,
self.order_id.date_order,
'sale',
fiscal_position=self.order_id.fiscal_position_id,
product_price_unit=self._get_display_price(product),
product_currency=self.order_id.currency_id
product = self.product_id.with_context(
partner=self.order_id.partner_id,
quantity=self.product_uom_qty,
date=self.order_id.date_order,
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id
)
self.update(vals)
self.update({
'price_unit': product._get_tax_included_unit_price(
self.company_id,
self.order_id.currency_id,
self.order_id.date_order,
'sale',
fiscal_position=self.order_id.fiscal_position_id,
product_price_unit=self._get_display_price(product),
product_currency=self.order_id.currency_id
)
})
@api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment