From 7afe6d28b6eea2d2ca20b491afd2fb46dbea5615 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 8 May 2017 11:37:54 +0200 Subject: [PATCH] [FIX] account: do not display unused field The field move_line_ids was present in the view and used only for display purposes. However modifying another field triggering an onchange (e.g. a payment line) was recreating the move lines. Recreating the accounting entries may trigger an error if the entries are already posted. The entries are recreated because: 1. the move_line_ids is loaded with the default tree & form view for account.move.line records, displaying several fields 2. some of the fields (e.g. reconciled) are computed 3. the initial onchange recomputes all the computed field, including the one on the one2many (e.g. recomputing move_line_ids.reconciled) 4. the field being dirty, the onchange returns the value of move_line_ids with [(5,),(1,id,{...}),...] 5. trying to save the modified lines may fail Replace the field by a simple readonly integer field. opw-741205 --- addons/account/models/account_bank_statement.py | 7 +++++++ addons/account/views/account_view.xml | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 0a510fe0c9c..fc2a4bd0c36 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -93,6 +93,11 @@ class AccountBankStatement(models.Model): def _check_lines_reconciled(self): self.all_lines_reconciled = all([line.journal_entry_ids.ids or line.account_id.id for line in self.line_ids]) + @api.depends('move_line_ids') + def _get_move_line_count(self): + for payment in self: + payment.move_line_count = len(payment.move_line_ids) + @api.model def _default_journal(self): journal_type = self.env.context.get('journal_type', False) @@ -146,6 +151,8 @@ class AccountBankStatement(models.Model): line_ids = fields.One2many('account.bank.statement.line', 'statement_id', string='Statement lines', states={'confirm': [('readonly', True)]}, copy=True) move_line_ids = fields.One2many('account.move.line', 'statement_id', string='Entry lines', states={'confirm': [('readonly', True)]}) + move_line_count = fields.Integer(compute="_get_move_line_count") + all_lines_reconciled = fields.Boolean(compute='_check_lines_reconciled') user_id = fields.Many2one('res.users', string='Responsible', required=False, default=lambda self: self.env.user) cashbox_start_id = fields.Many2one('account.bank.statement.cashbox', string="Starting Cashbox") diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index e92b0b73443..b195540e548 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -523,8 +523,9 @@