From c3c6ec69a0c50daf0b33df62144b6cd2f254a4f5 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Thu, 26 Nov 2020 08:37:48 +0000 Subject: [FIX] account: Fixes the losing of company_id in account move MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the company_id of an account move is related to its journal. This means that if you empty the journal field, the company_id is also emptied. This is then causing a traceback when adding a new line, for example. This change will transform the related company_id in a computed field, making sure to not lose the company_id if the journal_id is emptied. task id #2392004 closes odoo/odoo#67238 X-original-commit: 296cf6cca4055fbd3c91189c2a45b90ab1dc420f Signed-off-by: Quentin De Paoli (qdp) Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'addons/account') diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index c8c49f274c1..3d0c034cd41 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -159,10 +159,11 @@ class AccountMove(models.Model): check_company=True, domain="[('id', 'in', suitable_journal_ids)]", default=_get_default_journal) suitable_journal_ids = fields.Many2many('account.journal', compute='_compute_suitable_journal_ids') - company_id = fields.Many2one(string='Company', store=True, readonly=True, - related='journal_id.company_id', change_default=True, default=lambda self: self.env.company) + company_id = fields.Many2one(comodel_name='res.company', string='Company', + store=True, readonly=True, + compute='_compute_company_id') company_currency_id = fields.Many2one(string='Company Currency', readonly=True, - related='journal_id.company_id.currency_id') + related='company_id.currency_id') currency_id = fields.Many2one('res.currency', store=True, readonly=True, tracking=True, required=True, states={'draft': [('readonly', False)]}, string='Currency', @@ -686,8 +687,8 @@ class AccountMove(models.Model): balance = currency._convert( taxes_map_entry['amount'], - self.journal_id.company_id.currency_id, - self.journal_id.company_id, + self.company_currency_id, + self.company_id, self.date or fields.Date.context_today(self), ) to_write_on_line = { @@ -1037,6 +1038,11 @@ class AccountMove(models.Model): if invoice != invoice._origin: invoice.invoice_line_ids = invoice.line_ids.filtered(lambda line: not line.exclude_from_invoice_tab) + @api.depends('journal_id') + def _compute_company_id(self): + for move in self: + move.company_id = move.journal_id.company_id or move.company_id or self.env.company + def _get_lines_onchange_currency(self): # Override needed for COGS return self.line_ids -- cgit v1.2.3