[FIX] account: Fixes the losing of company_id in account move
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#68886 X-original-commit: c3c6ec69a0c50daf0b33df62144b6cd2f254a4f5 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com> Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Nicolas Viseur <vin-odoo@users.noreply.github.com>
This commit is contained in:
@@ -168,10 +168,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',
|
||||
@@ -689,8 +690,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 = {
|
||||
@@ -1040,6 +1041,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
|
||||
|
||||
Reference in New Issue
Block a user