From fb323d0068e673167ad7c89f5bd1732088c4ab3d Mon Sep 17 00:00:00 2001
From: jem-odoo <jem@openerp.com>
Date: Thu, 12 Apr 2018 10:10:30 +0200
Subject: [PATCH] [FIX] uom: avoid context key, and rather use parameter

When converting UoM, the conversion can fail if the source and destination
uoM are not in the same category. By default, and error is raised, but using
a context key, we can receive the initial quantity.
To avoid the context key (which is not used anymore), we prefer use a dedicated
parameter to be more explicit.
---
 addons/uom/models/uom_uom.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py
index 0baf13b68fe7..6573c7541fbf 100644
--- a/addons/uom/models/uom_uom.py
+++ b/addons/uom/models/uom_uom.py
@@ -122,12 +122,19 @@ class UoM(models.Model):
         return new_uom.name_get()[0]
 
     @api.multi
-    def _compute_quantity(self, qty, to_unit, round=True, rounding_method='UP'):
+    def _compute_quantity(self, qty, to_unit, round=True, rounding_method='UP', raise_if_failure=True):
+        """ Convert the given quantity from the current UoM `self` into a given one
+            :param qty: the quantity to convert
+            :param to_unit: the destination UoM record (uom.uom)
+            :param raise_if_failure: only if the conversion is not possible
+                - if true, raise an exception if the conversion is not possible (different UoM category),
+                - otherwise, return the initial quantity
+        """
         if not self:
             return qty
         self.ensure_one()
         if self.category_id.id != to_unit.category_id.id:
-            if self._context.get('raise-exception', True):
+            if raise_if_failure:
                 raise UserError(_('Conversion from Product UoM %s to Default UoM %s is not possible as they both belong to different Category!.') % (self.name, to_unit.name))
             else:
                 return qty
-- 
GitLab