mrp_packaging_qty/fix_mo_decimals.py

21 lines
909 B
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'])])
fixed_count = 0
for mo in mos:
for move in mo.move_raw_ids:
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}")
move.write({'product_uom_qty': clean_qty})
fixed_count += 1
env.cr.commit()
print(f"\\nPerfectly cleaned and committed {fixed_count} dirty components!")