Skip to content

[18.0][OU-FIX] account: fill company_id and journal_id for all existing payments#22

Open
eantones wants to merge 1 commit into
18.0from
18.0-ou-fix-account_payment_fill
Open

[18.0][OU-FIX] account: fill company_id and journal_id for all existing payments#22
eantones wants to merge 1 commit into
18.0from
18.0-ou-fix-account_payment_fill

Conversation

@eantones

Copy link
Copy Markdown
Member

At 18.0 account.payment stops delegating to its move (_inherits dropped) and journal_id / company_id become the payment's own stored required fields (both compute=..., store=True, required=True).

The current fill_account_payment():

  • sets journal_id from the move only when the move's journal is of type bank/cash/credit — payments whose move lives in any other journal type (e.g. general, common for netting/compensation flows) are left with journal_id = NULL;
  • never sets company_id at all (the analogous fill_statement_line_fields() does fill it for statement lines).

Consequences on a real 14→18 chain (measured on a production-size database: 164,706 payments):

  • company_id NULL on 119,930 rows (73%) and journal_id NULL on 38,968 → unable to set NOT NULL on column company_id/journal_id at load, so both required columns end up without their NOT NULL constraint;
  • with standard multi-company record rules, company_id = NULL payments behave as shared records, visible from every company;
  • worse, _compute_company_id() falls back to self.env.company — the first user who edits a legacy payment silently stamps their own active company on it.

Both values are fully derivable from the payment's move (move_id and move.company_id are never NULL for legacy payments). This patch:

  • adds the account.payment.company_id column in pre (it did not exist in ≤17.0) and fills it from the move for every payment;
  • falls back to the move's journal for payments whose move sits outside bank/cash/credit journals, so historical rows keep their true journal.

After the fill, both SET NOT NULL succeed and the schema warnings disappear.

…ng payments

account.payment at 18.0 turns journal_id and company_id into its own stored
required fields (in <=17.0 they were delegated to the move). The existing
fill only set journal_id when the move journal is bank/cash/credit, and
never set company_id at all, leaving legacy payments with NULLs in required
columns: the SET NOT NULL of both columns fails at load, and the lazy ORM
compute of company_id falls back to self.env.company on first edit,
silently assigning the editing user company.

Both values are fully derivable from the payment move: fill company_id for
every payment, and fall back to the move journal for payments whose move
lives outside bank/cash/credit journals, so historical rows keep their
real journal and both NOT NULL constraints can install.
@eantones eantones added the local-only Contains commits that stay in this repo forever (customer-private modules, local policy). label Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

local-only Contains commits that stay in this repo forever (customer-private modules, local policy).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant