From d424f49ae7b3a2e9de040bde5e7ca57c9cdf67ad Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Wed, 28 Mar 2018 08:59:38 +1100 Subject: [PATCH] [FIX 10.0] readonly company on account.move.line Account move line link to company_id (related from account.account) is not readonly in the base. Some writes are causing an unnecessary write to account.account on company_id (even though company_id is not changing), which causes the constraint validation - which is quite resource hungry given the large number of searches. Besides being an unnecessary overhead, it fails when this module has been installed on an existing database and there is history that was not aligned. --- mcfix_account/models/account_move.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mcfix_account/models/account_move.py b/mcfix_account/models/account_move.py index 979b2fd1..c5d30398 100644 --- a/mcfix_account/models/account_move.py +++ b/mcfix_account/models/account_move.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from odoo import api, models, _ +from odoo import api, models, fields, _ from odoo.exceptions import UserError, ValidationError @@ -101,6 +101,12 @@ def _check_company_dummy_account_id(self): class AccountMoveLine(models.Model): _inherit = "account.move.line" + # It is non-sensical for account_move_lines to be + # have a write access to company_id on account.account. + # It causes unnecessary write calls to account.account + # and constraint validations. + company_id = fields.Many2one(readonly=True) + @api.multi @api.depends('company_id') def name_get(self):