summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2017-05-08 11:37:54 +0200
committerMartin Trigaux <mat@odoo.com>2017-05-08 16:56:36 +0200
commit7afe6d28b6eea2d2ca20b491afd2fb46dbea5615 (patch)
treeaab6d5df77283e172b515b785a7edc18a9a46b5f
parent47dab7d3b4aae8cbb29c56b695ba270c8f6923b4 (diff)
[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
-rw-r--r--addons/account/models/account_bank_statement.py7
-rw-r--r--addons/account/views/account_view.xml7
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 @@
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="button_journal_entries"
string="Journal Entries" type="object"
- attrs="{'invisible':[('move_line_ids','=',[])]}" icon="fa-bars"/>
- <field name="move_line_ids" invisible="1"/>
+ attrs="{'invisible':[('move_line_count','=', 0)]}" icon="fa-bars" />
+ <field name="move_line_count" invisible="1"/>
+
</div>
<div class="oe_title oe_inline">
<label for="name" class="oe_edit_only"/>
@@ -535,7 +536,7 @@
<field name="journal_type" invisible="1"/>
<field name="cashbox_start_id" invisible="1"/>
<field name="cashbox_end_id" invisible="1"/>
- <field name="journal_id" domain="[('type', '=', journal_type)]" attrs="{'readonly': [('move_line_ids', '!=', [])]}" widget="selection"/>
+ <field name="journal_id" domain="[('type', '=', journal_type)]" attrs="{'readonly': [('move_line_count','!=', 0)]}" widget="selection"/>
<field name="date"/>
<field name='company_id' options="{'no_create': True}" groups="base.group_multi_company" />
<field name="currency_id" invisible="1"/>