odoo_stock_initial_opening_journal
Book a posted opening balance journal entry for initial stock, grouping debit lines by valuation account and crediting retained earnings. Includes duplicate guard and dry-run mode.
Instructions
Book the opening-balance journal entry for a previous SQL-inserted initial stock (complements odoo_stock_initial_import — SVL/stock.move written via raw SQL do NOT auto-create account.move even for real_time valuation). Creates ONE account.move (MISC journal, state=posted) with: DR lines grouped by category.property_stock_valuation_account_id (e.g. 302 Materials, 303 Products); CR contra account (default: code '122000' Retained earnings from prior years). Version-aware: v14-v18 reads stock.valuation.layer for the date; v19 reads stock.move (is_inventory=true, is_valued=true) for the same date — totals the 'value' column. DUPLICATE GUARD: before create, scans account.move.line for the same accounts on the same date — if any posted lines found, refuses and returns them (Alpinter lesson: comprehensive opening entries often already include the stock lines). ALWAYS use dry_run=true first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | default | |
| company_id | Yes | ||
| accounting_date | Yes | YYYY-MM-DD — date of the opening balance (matches the SQL-inserted stock records) | |
| tz | Yes | IANA timezone of the caller (used to bracket the date for UTC query). | |
| contra_account_id | No | Contra account (CR side). If omitted, searches for account with code '122000' in this company. | |
| journal_id | No | Journal for the entry. If omitted, searches for first general-type journal (MISC) in this company. | |
| ref | No | account.move.ref value. Default: 'Opening balance initial stock <date>'. | |
| skip_if_exists_on_date | No | If true, refuse when posted account.move.line exist on accounting_date for any of the stock valuation accounts. | |
| dry_run | No | If true, only preview the lines + duplicate check. Set false to create + post. |