Skip to content

fix: allow draft journal entry creation with validated lines - #71

Open
siddolo wants to merge 2 commits into
erpipe-org:mainfrom
r00ters:fix/journal-entry-create-validation
Open

siddolo wants to merge 2 commits into
erpipe-org:mainfrom
r00ters:fix/journal-entry-create-validation

Conversation

@siddolo

@siddolo siddolo commented Oct 5, 2026 •

Copy link
Copy Markdown

Summary

Allow draft manual journal entries to be created through preview_write -> validate_write -> execute_approved_write with validated new journal items, despite Odoo's UI-readonly metadata. Support single and atomic batch creates without merging distinct items on the same account.

Note: Compatibility with #78 (ir.attachment resource linking) has been reconciled on #78's branch — see the comment below for integration details.

Reproduction and cause

On Odoo 16, preview and then validate this shape using valid journal/account IDs:

{
  "model": "account.move",
  "operation": "create",
  "values": {
    "move_type": "entry",
    "journal_id": 7,
    "line_ids": [
      [0, 0, {"name": "Item A", "account_id": 11, "debit": 10}],
      [0, 0, {"name": "Item B", "account_id": 11, "debit": 20}],
      [0, 0, {"name": "Counterpart", "account_id": 12, "credit": 30}]
    ]
  }
}

The existing validator rejects line_ids and move_type as readonly, even though Odoo's ORM supports this atomic draft creation. The flag describes UI behavior rather than an absolute ORM create prohibition. In the tested Odoo 17–19 images, line_ids is writable but move_type remains readonly, so explicit move_type="entry" also needs the narrow exception.

Changes and scope

  • Limit the readonly exception to line_ids and move_type on account.move creates whose effective type/state are entry/draft. Explicit values take precedence over context defaults.
  • Require the parent relation to be a one2many to account.move.line and fetch live child metadata from the same resolved instance.
  • Validate every line against that metadata, including when the parent relation is UI-writable. Accept only nonempty new-item [0, 0, values] commands; reject unknown/readonly line fields, explicit move_id, and nested one2many/many2many mutations.
  • Reject context.default_line_ids and disabling check_move_validity for this creation contract.
  • Preserve canonical payloads, approval tokens, command order, and distinct same-account items for both values and values_list.
  • Add 54 journal-entry regression test cases and a disposable accounting smoke script using the existing Compose/MCP helpers, covering real single and batch creates on XML-RPC and JSON-2.
  • Document the contract, posting, supported transports, verified compatibility, and reconciliation serialization limitation in README.md, docs/, and the Unreleased CHANGELOG.md section.

Preserved gates and Odoo accounting checks

The existing write approval workflow is preserved: live metadata, validation in the same server session, a matching payload and token, approval expiry, explicit confirmation, and enabled writes. Client-supplied metadata cannot authorize execution. Direct create, write, and unlink remain blocked in execute_method; field access controls and side-effect method policies are unchanged.

Validation checks metadata and command structure, not a simulated accounting transaction. Odoo remains responsible for ACLs, record rules, company/journal/account compatibility, currencies, rounding, and balance. A failed single create or batch create rolls back its moves and items atomically. action_post remains a separate transaction under the existing side-effect method policy.

Verified compatibility

Official disposable Odoo Community Docker images; Python 3.12.12; package version unchanged at 1.3.2.

Odoo Odoo transport Accounting over MCP stdio: single Accounting over MCP stdio: batch General MCP stdio General Streamable HTTP Inspector
16.0 XML-RPC Passed Passed Passed Not run stdio passed
17.0 XML-RPC Passed Passed Passed Not run stdio passed
18.0 XML-RPC Passed Passed Passed Not run stdio passed
19.0 XML-RPC Passed Passed Passed Not run Not run on this backend
19.0 JSON-2 Passed Passed Passed Passed stdio and HTTP passed

All 10 accounting scenarios verify the approval workflow, live metadata, unchanged payloads and tokens, distinct same-account items, posting, rollback on imbalance, and independent reconciliation. Batch tests also verify that an unbalanced second entry rolls back the whole batch and that reconciling one entry leaves the other untouched. Invalid fields, commands, and context values are rejected; missing validation, missing confirmation, tampered approvals, and direct creation are blocked.

The general smoke suite also verifies direct transport access, read/diagnostic tools, disabled standard writes, restricted-user access, complex record rules, packaged addon install/update, and locale plumbing.

Verification commands and results

uv sync --python 3.12 --extra dev
uv run python -m ruff check .
uv run python -m mypy src
uv run python -m pytest
PYTHONPATH=src uv run --with import-linter lint-imports
git diff --check

uv run --python 3.12 --with-editable . scripts/odoo_journal_entry_smoke.py \
  --versions 16.0 17.0 18.0 19.0 --timeout 360

uv run --python 3.12 --with-editable . scripts/odoo_compose_smoke.py \
  --versions 16.0 17.0 18.0 19.0 --timeout 360 --inspector-smoke
  • Ruff, mypy (34 source files), and whitespace checks: passed.
  • Pytest: 985 passed, including 54 journal-entry cases; one existing runpy warning in the CLI entrypoint test.
  • Import-linter: 2 contracts kept, 0 broken.
  • Accounting smoke: 10 scenarios passed, 0 failures.
  • General smoke: 4 versions passed, 0 failures, including Odoo 19 JSON-2/Streamable HTTP and MCP Inspector.

Limits

  • On Odoo 16 XML-RPC, account.move.line.reconcile commits successfully but its recordset-valued response fails serialization. Both accounting scenarios confirm the committed outcome by readback without retrying the operation. This PR does not fix that separate serialization issue.
  • Accounting writes themselves are verified over MCP stdio; Streamable HTTP coverage is provided by the general smoke suite on Odoo 19 JSON-2.
  • Enterprise modules, custom addons, and additional accounting localizations are outside this test matrix. Odoo remains authoritative for their defaults and constraints.

@siddolo

siddolo commented Oct 31, 2026 •

Copy link
Copy Markdown
Author

Compatibility with #78 has been reconciled and pushed to #78's branch at 76928e2 (this PR's head and both base branches remain unchanged).

Because the original heads (e38e11d and 028f173) conflict in src/odoo_mcp/agent_tools.py and CHANGELOG.md, #78 now merges both branches (8b561eb) and adds nine cross-contract regression tests plus an accounting smoke check that links an attachment to the newly created move in the same MCP session.

The shared readonly_allowed_fields parameter is recomputed per entry and selected by mutually exclusive model/operation guards. The account.move create-only entry/draft contract, trusted live child metadata, attachment create/write explicit resource pair, approval/token/TTL/confirmation/write-enable gates, and Odoo ACLs/record rules all remain intact.

Verification on the combined branch:

  • 1,036 unit tests passed; Ruff, mypy, and both import-linter contracts passed.
  • 10 accounting scenarios and 5 attachment scenarios passed on Odoo 16–19 XML-RPC and Odoo 19 JSON-2.
  • General smoke passed on all four versions, including restricted-user/record-rule checks, addon install/update, Inspector, and Odoo 19 Streamable HTTP.

Integration options:
Since #78 now contains this PR's commits, you can either merge the combined #78 directly, or merge #71 first (preserving its commits via merge commit) and then #78. Note that squashing or rebasing #71 separately will break the shared commit ancestry and require rebasing #78 onto main afterward.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant