odoo_stock_initial_delete
Delete wrong opening stock balances: cascade-removes inventory stock moves, lines, and valuation layers, zeros stock quants. Includes pre-flight validation and automatic backup before deletion.
Instructions
Delete wrong opening stock balances — cascade-removes stock.move (is_inventory=TRUE) records, their stock.move.line, and (v14-v18) stock.valuation.layer; then zeros out stock.quant on affected (product, location, lot). Bypasses Odoo's ORM guard 'You can not delete product moves if the picking is done' via raw SQL in an ir.actions.server + env.cr.commit(). Version-aware: v14-v18 DELETEs SVL→SML→SM; v19 DELETEs SML→SM (SVL doesn't exist). PRE-FLIGHT: refuses if any affected SVL/stock.move has account_move_id set (orphan journal entries would remain). Caller must reverse those first. ALWAYS writes a full JSON backup to /backups// BEFORE any delete. ALWAYS use dry_run=true first to see the impact scope.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | default | |
| company_id | Yes | Company scope — only records with this company_id are touched | |
| tz | Yes | IANA timezone of the caller. Used to interpret date_from/date_to (start_of_day / end_of_day in this tz → UTC). | |
| date_from | No | Optional YYYY-MM-DD, start-of-day in tz. Filters stock.move.date >= UTC(date_from 00:00 tz). | |
| date_to | No | Optional YYYY-MM-DD, end-of-day in tz. Filters stock.move.date <= UTC(date_to 23:59:59 tz). | |
| location_ids | No | Optional list of stock.location IDs to filter by (either src or dst). If omitted, all locations in company. | |
| dry_run | No | If true, only preview + backup preview. Set false to execute (backup is still written). |