[IMP] account: remove required attribute on stored and related field

The field journal_id and date are both required on account.move and are stored
related on account.move.line.
Setting the required on the account.move.line allows to make it required in the
views or for the ORM but in practice it will be same as it's required on the
parent.

Making it required is a performance killer as it forces to specify a value for
the create which will retrigger an update on the parent move.
This means that adding a line with a date value on an account.move with already
10 lines will trigger 11 updates (date of the new line -> date of the move ->
date on the 10 existing lines), even if the value has not changed.
This commit is contained in:
Martin Trigaux
2016-09-02 12:03:40 +02:00
parent 14f07cb96f
commit 7ad9487a83
+2 -2
View File
@@ -395,12 +395,12 @@ class AccountMoveLine(models.Model):
matched_credit_ids = fields.One2many('account.partial.reconcile', 'debit_move_id', String='Matched Credits',
help='Credit journal items that are matched with this journal item.')
journal_id = fields.Many2one('account.journal', related='move_id.journal_id', string='Journal',
default=_get_journal, required=True, index=True, store=True, copy=False)
default=_get_journal, index=True, store=True, copy=False) # related is required
blocked = fields.Boolean(string='No Follow-up', default=False,
help="You can check this box to mark this journal item as a litigation with the associated partner")
date_maturity = fields.Date(string='Due date', index=True, required=True,
help="This field is used for payable and receivable journal entries. You can put the limit date for the payment of this line.")
date = fields.Date(related='move_id.date', string='Date', required=True, index=True, default=fields.Date.context_today, store=True, copy=False)
date = fields.Date(related='move_id.date', string='Date', index=True, store=True, copy=False) # related is required
analytic_line_ids = fields.One2many('account.analytic.line', 'move_id', string='Analytic lines', oldname="analytic_lines")
tax_ids = fields.Many2many('account.tax', string='Taxes')
tax_line_id = fields.Many2one('account.tax', string='Originator tax', ondelete='restrict')