11# Copyright 2021 Tecnativa - Sergio Teruel
22# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33from odoo import api , fields , models
4- from odoo .tools .float_utils import float_round
4+ from odoo .tools .float_utils import float_is_zero , float_round
55
66
77class ProductSecondaryUnitMixin (models .AbstractModel ):
@@ -76,7 +76,11 @@ def _get_secondary_uom_qty_depends(self):
7676 def _compute_secondary_uom_qty (self ):
7777 for line in self :
7878 if not line .secondary_uom_id :
79- line .secondary_uom_qty = 0.0
79+ if not float_is_zero (
80+ line .secondary_uom_qty , precision_digits = line ._get_uom_precision ()
81+ ):
82+ # Only set to 0.0 if it's not already 0.0
83+ self .secondary_uom_qty = 0.0
8084 continue
8185 elif line .secondary_uom_id .dependency_type == "independent" :
8286 continue
@@ -88,6 +92,9 @@ def _compute_secondary_uom_qty(self):
8892 )
8993 line .secondary_uom_qty = qty
9094
95+ def _get_uom_precision (self ):
96+ return self .env ["decimal.precision" ].precision_get ("Product Unit of Measure" )
97+
9198 def _get_default_value_for_qty_field (self ):
9299 return self .default_get ([self ._secondary_unit_fields ["qty_field" ]]).get (
93100 self ._secondary_unit_fields ["qty_field" ]
@@ -126,7 +133,11 @@ def _onchange_helper_product_uom_for_secondary(self):
126133 target model.
127134 """
128135 if not self .secondary_uom_id :
129- self .secondary_uom_qty = 0.0
136+ if not float_is_zero (
137+ self .secondary_uom_qty , precision_digits = self ._get_uom_precision ()
138+ ):
139+ # Only set to 0.0 if it's not already 0.0
140+ self .secondary_uom_qty = 0.0
130141 return
131142 elif self .secondary_uom_id .dependency_type == "independent" :
132143 return
0 commit comments