mrp_packaging_qty/fix_mo_decimals.py

28 lines
1.4 KiB
Python

# 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', '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:
clean_qty = round(move.product_uom_qty, 2)
if 0.0001 < abs(move.product_uom_qty - clean_qty) < 0.01:
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! (Includes draft, confirmed, and In Progress)")