diff --git a/fix_mo_decimals.py b/fix_mo_decimals.py index 87f98d0..fee436a 100644 --- a/fix_mo_decimals.py +++ b/fix_mo_decimals.py @@ -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)")