From 845bb814e9941ba57cb1009dd3b7a1985e4a2776 Mon Sep 17 00:00:00 2001 From: Leonardo Rochael Almeida Date: Thu, 6 Apr 2017 17:13:13 -0300 Subject: [PATCH] Allow reloading account.account from CSV files Work around code in `account.account` that forbids writing to certain fields even if they are unchanged by not trying to write to them in that case. This allows updating modules that contain accounts in CSV files, since CSV files don't allow specifying noupdate. This is temporary workaround until the PR below is accepted: https://github.com/odoo/odoo/pull/16188 --- l10n_br_account/models/account.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/l10n_br_account/models/account.py b/l10n_br_account/models/account.py index eb10ffbb49b8..b5c59cc320f3 100644 --- a/l10n_br_account/models/account.py +++ b/l10n_br_account/models/account.py @@ -180,6 +180,25 @@ def execute(self, cr, uid, ids, context=None): class AccountAccount(models.Model): _inherit = 'account.account' + _checked_fields = {'company_id', 'active', 'type', 'code'} + + @api.multi + def write(self, vals): + """ + Hack to implement the PR below until it's approved: + https://github.com/odoo/odoo/pull/16188 + + Allows reload of accounts from CSV files. + """ + vals = dict(vals) + checked_fields = self._checked_fields.intersection(vals) + records = self.read(fields=checked_fields) + for field in checked_fields: + if {record[field] for record in records} == {vals[field]}: + # don't try to write unchanged fields. + del vals[field] + return super(AccountAccount, self).write(vals) + @api.v7 def _check_allow_type_change(self, cr, uid, ids, new_type, context=None): """Hack to allow re-shaping demo chart of account in demo mode"""