summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNicolas (vin) <vin@odoo.com>2020-11-26 08:37:48 +0000
committerNicolas (vin) <vin@odoo.com>2021-04-07 05:47:23 +0000
commitc3c6ec69a0c50daf0b33df62144b6cd2f254a4f5 (patch)
tree7626908aea020b1b78e72e3121cd10a7676a6fa2 /addons
parent365da2a0aca1503133433f9dc66b6866e7867974 (diff)
[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#67238 X-original-commit: 296cf6cca4055fbd3c91189c2a45b90ab1dc420f Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com> Signed-off-by: William André (wan) <wan@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/account_move.py16
1 files changed, 11 insertions, 5 deletions
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