import xmlrpc.client import ssl url = "https://trialerp.mapan.co.id" username = 'suherdy.yacob' api_key = '27aa1dfc979d5507973b190018329d0690400c66' selected_db = 'mapangroup_trial_o19' context = ssl._create_unverified_context() try: common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common', context=context) uid = common.authenticate(selected_db, username, api_key, {}) models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url), context=context) # Search for all draft or confirmed MOs. mo_ids = models.execute_kw(selected_db, uid, api_key, 'mrp.production', 'search', [[('state', 'in', ['draft', 'confirmed'])]]) print(f"Found {len(mo_ids)} active MOs.") for mo_id in mo_ids: mo = models.execute_kw(selected_db, uid, api_key, 'mrp.production', 'read', [[mo_id]], {'fields': ['name', 'product_qty', 'move_raw_ids']})[0] move_ids = mo.get('move_raw_ids', []) if not move_ids: continue print(f"Checking MO {mo['name']}...") moves = models.execute_kw(selected_db, uid, api_key, 'stock.move', 'read', [move_ids], {'fields': ['product_uom_qty']}) for move in moves: current_qty = move.get('product_uom_qty') or 0.0 # Detect +0.001 to +0.009 floating point noise # by comparing it against its cleanly rounded 2-decimal version. clean_qty = round(current_qty, 2) fraction_diff = abs(current_qty - clean_qty) if 0.0001 < fraction_diff < 0.01: print(f" - Fixing move {move['id']}: qty {current_qty} -> clean {clean_qty}") models.execute_kw(selected_db, uid, api_key, 'stock.move', 'write', [[move['id']], {'product_uom_qty': clean_qty}]) print("Finished checking MOs.") except Exception as e: print("Error:", e)