# SCRIPT TO DELETE INCORRECT VALUATION LAYER # Run this in: ./odoo-bin shell -d def fix_valuation(): print("Searching for remaining candidate layers...") # Broaden search to include the 420,000 one and any others similar layer_domain = [ ('product_id.name', 'ilike', 'Kotak Imlek Pink'), ('quantity', '=', 0), ('value', '!=', 0), ('description', 'like', 'Valuation correction%') # Safety check ] layers = env['stock.valuation.layer'].search(layer_domain) print(f"Found {len(layers)} remaining layers with 0 quantity and non-zero value.") if not layers: print("No more incorrect layers found!") return for layer in layers: print(f"\n---------------------------------------------------") print(f"Layer ID: {layer.id}") print(f"Product: {layer.product_id.display_name}") print(f"Description: {layer.description}") print(f"Value: {layer.value}") print(f"Linked Account Move: {layer.account_move_id.name if layer.account_move_id else 'None'}") # We can just proceed to delete since we confirmed these are the bad ones # But let's check values to be sure it matches the 420k one or similar print(">>> DELETING <<<") # UNLINK ACCOUNT MOVE if layer.account_move_id: print(f"Deleting associated account move: {layer.account_move_id.name}") try: if layer.account_move_id.state == 'posted': layer.account_move_id.button_draft() layer.account_move_id.unlink() except Exception as e: print(f"Could not delete account move: {e}") # UNLINK LAYER print("Deleting layer...") layer.unlink() print("Layer deleted successfully.") env.cr.commit() print("\nAll changes committed to database.") fix_valuation()