fix: extend decimal cleaning to include 'progress' MOs and 'consumed' quantities.
This commit is contained in:
parent
a22e49faf8
commit
070f932b8d
@ -1,20 +1,27 @@
|
||||
# Run this script using your odoo shell on the server:
|
||||
# ./odoo-bin shell -c odoo.conf -d mapangroup_trial_o19 < /home/bukanadmin/odoo19/customaddons/mrp_packaging_qty/fix_mo_decimals.py
|
||||
|
||||
mos = env['mrp.production'].search([('state', 'in', ['draft', 'confirmed'])])
|
||||
mos = env['mrp.production'].search([('state', 'in', ['draft', 'confirmed', 'progress'])])
|
||||
fixed_count = 0
|
||||
|
||||
for mo in mos:
|
||||
for move in mo.move_raw_ids:
|
||||
# 1. Clean the 'To Consume' (product_uom_qty)
|
||||
if move.product_uom_qty:
|
||||
# Round to two decimals cleanly
|
||||
clean_qty = round(move.product_uom_qty, 2)
|
||||
|
||||
# If the quantity is dirty by .001 or .009 etc...
|
||||
if 0.0001 < abs(move.product_uom_qty - clean_qty) < 0.01:
|
||||
print(f"Fixing {mo.name} component {move.product_id.name}: {move.product_uom_qty} -> {clean_qty}")
|
||||
print(f"Fixing To Consume {mo.name} component {move.product_id.name}: {move.product_uom_qty} -> {clean_qty}")
|
||||
move.write({'product_uom_qty': clean_qty})
|
||||
fixed_count += 1
|
||||
|
||||
# 2. Clean the 'Consumed' quantities (quantity on move lines)
|
||||
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:
|
||||
print(f"Fixing Consumed {mo.name} component {ml.product_id.name}: {ml.quantity} -> {clean_done}")
|
||||
ml.write({'quantity': clean_done})
|
||||
fixed_count += 1
|
||||
|
||||
env.cr.commit()
|
||||
print(f"\\nPerfectly cleaned and committed {fixed_count} dirty components!")
|
||||
print(f"\\nPerfectly cleaned and committed {fixed_count} dirty components! (Includes draft, confirmed, and In Progress)")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user