[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
This commit is contained in:
Martin Trigaux
2017-05-08 16:56:36 +02:00
parent 47dab7d3b4
commit 7afe6d28b6
2 changed files with 11 additions and 3 deletions
@@ -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")
+4 -3
View File
@@ -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"/>