From 6815eb08944bab72508689fc710646bd9d64d1e3 Mon Sep 17 00:00:00 2001 From: late-odoo Date: Tue, 9 Jan 2024 17:05:32 +0530 Subject: [PATCH] [FIX] account: prevent error when selecting company while journal is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently an error occurs when the user is creating a new invoice and selects the 'Customer' while the 'Journal' field is empty. Steps to Reproduce: - Install 'Accounting' module. - Go to Accounting > Customer > Invoices and then click on New. - Empty the 'Journal' field and then select any 'Customer'. - The error will be generated. Error: ValueError: Expected singleton: res.company() This error arises at [1] when the company is selected, but the 'journal_id' field is left empty, This commit fixes the above issue by ensuring that the company is selected based on the accessible branches of the associated journal, or falls back to the default company if no journal is specified. Link: [1]-https://github.com/odoo/odoo/blob/ad9cd949168e3be3db6e9a4983faa6b02626b0a2/addons/account/models/account_move.py#L1771 sentry-4835188267 closes odoo/odoo#149707 X-original-commit: aa645cfde60644eec05a120e434da4e94ff0da75 Signed-off-by: de Wouters de Bouchout Jean-BenoƮt (jbw) Signed-off-by: Lavina Tekwani (late) --- addons/account/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b006b4c2904..d7615838a11 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1735,7 +1735,7 @@ class AccountMove(models.Model): @api.onchange('partner_id') def _onchange_partner_id(self): - self = self.with_company(self.journal_id.company_id._accessible_branches()[:1]) + self = self.with_company((self.journal_id.company_id or self.env.company)._accessible_branches()[:1]) warning = {} if self.partner_id: