From 694193ce189eedb1a7072b1bec6e424a30e470b9 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Sun, 19 Jul 2026 13:02:40 +0200 Subject: [PATCH] [18.0][OU-FIX] account: fill company_id and journal_id for all existing 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. --- .../scripts/account/18.0.1.3/pre-migration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openupgrade_scripts/scripts/account/18.0.1.3/pre-migration.py b/openupgrade_scripts/scripts/account/18.0.1.3/pre-migration.py index 9acf7da585e7..ffdadd9c7069 100644 --- a/openupgrade_scripts/scripts/account/18.0.1.3/pre-migration.py +++ b/openupgrade_scripts/scripts/account/18.0.1.3/pre-migration.py @@ -39,6 +39,7 @@ ("account.payment", "memo", "char"), ("account.payment", "state", "selection"), ("account.payment", "is_sent", "boolean"), + ("account.payment", "company_id", "many2one"), ("account.move", "made_sequence_gap", "boolean", True), ] @@ -171,10 +172,10 @@ def fill_account_payment(env): ELSE 'Draft Payment' END, date = am.date, journal_id = CASE WHEN ap.journal_id IS NULL - AND aj.type in ('bank', 'cash', 'credit') - THEN am.journal_id ELSE ap.journal_id END + THEN am.journal_id ELSE ap.journal_id END, + company_id = CASE WHEN ap.company_id IS NULL + THEN am.company_id ELSE ap.company_id END FROM account_move am - LEFT JOIN account_journal aj ON am.journal_id = aj.id WHERE ap.move_id = am.id""", )