feat: Introduce _clean_lingering_decimals method to round raw material move quantities and integrate it into relevant quantity update hooks.

This commit is contained in:
Suherdy Yacob 2026-03-05 13:07:08 +07:00
parent 070f932b8d
commit c25da22149

View File

@ -109,16 +109,19 @@ class MrpProduction(models.Model):
def _onchange_qty_producing(self):
super()._onchange_qty_producing()
self._merge_finished_move_lines()
self._clean_lingering_decimals()
def write(self, vals):
res = super().write(vals)
if 'qty_producing' in vals or 'qty_producing_packaging' in vals:
if 'qty_producing' in vals or 'qty_producing_packaging' in vals or 'product_qty' in vals:
self._merge_finished_move_lines()
self._clean_lingering_decimals()
return res
def _set_qty_producing(self, *args, **kwargs):
res = super()._set_qty_producing(*args, **kwargs)
self._merge_finished_move_lines()
self._clean_lingering_decimals()
return res
def _post_inventory(self, *args, **kwargs):
@ -126,6 +129,19 @@ class MrpProduction(models.Model):
self._merge_finished_move_lines()
return res
def _clean_lingering_decimals(self):
for production in self:
for move in production.move_raw_ids:
if move.product_uom_qty:
clean_qty = round(move.product_uom_qty, 2)
if 0.0001 < abs(move.product_uom_qty - clean_qty) < 0.01:
move.product_uom_qty = clean_qty
for ml in move.move_line_ids:
if ml.quantity:
clean_done = round(ml.quantity, 2)
if 0.0001 < abs(ml.quantity - clean_done) < 0.01:
ml.quantity = clean_done
def _merge_finished_move_lines(self):
for production in self:
# Process ALL finished moves, even DONE ones, to catch splits that happened during validation
@ -181,6 +197,7 @@ class MrpProduction(models.Model):
def _onchange_product_qty(self):
# Merge finished move lines if quantity changes
self._merge_finished_move_lines()
self._clean_lingering_decimals()
@api.onchange('bom_id')
def _onchange_bom_id(self):