Skip to content
Snippets Groups Projects
Commit a122db22 authored by Ivan Yelizariev's avatar Ivan Yelizariev
Browse files

[FIX] uom: avoid unneeded qty conversion and fields fetching


This could save some time when `_compute_quantity` is used thousands times in
request and there are thousands UOMs in the system

* if qty is zero, then result is zero
* if to_unit is the same, then result is `round((qty / factor) * factor) = round(qty)`

---

opw-2549026

closes odoo/odoo#72433

Signed-off-by: default avatarNicolas Lempereur (nle) <nle@odoo.com>
parent 5182be96
Branches
Tags
No related merge requests found
......@@ -143,19 +143,26 @@ class UoM(models.Model):
- if true, raise an exception if the conversion is not possible (different UoM category),
- otherwise, return the initial quantity
"""
if not self:
if not self or not qty:
return qty
self.ensure_one()
if self.category_id.id != to_unit.category_id.id:
if self != to_unit and self.category_id.id != to_unit.category_id.id:
if raise_if_failure:
raise UserError(_('The unit of measure %s defined on the order line doesn\'t belong to the same category than the unit of measure %s defined on the product. Please correct the unit of measure defined on the order line or on the product, they should belong to the same category.') % (self.name, to_unit.name))
else:
return qty
amount = qty / self.factor
if to_unit:
amount = amount * to_unit.factor
if round:
amount = tools.float_round(amount, precision_rounding=to_unit.rounding, rounding_method=rounding_method)
if self == to_unit:
amount = qty
else:
amount = qty / self.factor
if to_unit:
amount = amount * to_unit.factor
if to_unit and round:
amount = tools.float_round(amount, precision_rounding=to_unit.rounding, rounding_method=rounding_method)
return amount
@api.multi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment