[FIX] account: depends in compute name

opw-2220539

The depends of _compute_name and _compute highest_name could lead to a
double recompute.
To reproduce:
* create a draft invoice in a new journal; a name is set
* post a new invoice in the same journa; the name is the one of the
draft + 1
* post the draft invoice; the name is changed to the other posted + 1
but it shouldn't

closes #47944

closes odoo/odoo#48144

X-original-commit: 2d7b751477d9c723fcbbc868534f47565e0a1621
Signed-off-by: Josse Colpaert <jco@openerp.com>
This commit is contained in:
william
2020-03-20 20:10:00 +00:00
parent 25aaf7afcf
commit 92f9d9b21b
+8 -5
View File
@@ -287,7 +287,8 @@ class AccountMove(models.Model):
if self.invoice_date:
if not self.invoice_payment_term_id:
self.invoice_date_due = self.invoice_date
self.date = self.invoice_date
if self.date != self.invoice_date: # Don't flag date as dirty if not needed
self.date = self.invoice_date
self._onchange_currency()
@api.onchange('journal_id')
@@ -922,7 +923,7 @@ class AccountMove(models.Model):
# COMPUTE METHODS
# -------------------------------------------------------------------------
@api.depends('journal_id', 'date', 'state', 'highest_name')
@api.depends('posted_before', 'state', 'highest_name')
def _compute_name(self):
for record in self.sorted(lambda m: (m.date, m.ref or '', m.id)):
if not record.name or record.name == '/':
@@ -937,7 +938,7 @@ class AccountMove(models.Model):
record.name = '/'
record.name = record.name or '/'
@api.depends('journal_id', 'date', 'state')
@api.depends('journal_id', 'date')
def _compute_highest_name(self):
for record in self:
record.highest_name = record._get_last_sequence()
@@ -2138,8 +2139,10 @@ class AccountMove(models.Model):
# Create the analytic lines in batch is faster as it leads to less cache invalidation.
self.mapped('line_ids').create_analytic_lines()
self.state = 'posted'
self.posted_before = True
self.write({
'state': 'posted',
'posted_before': True,
})
for move in self:
if move.auto_post and move.date > fields.Date.today():
raise UserError(_("This move is configured to be auto-posted on {}".format(move.date.strftime(get_lang(self.env).date_format))))