summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliam <wan@odoo.com>2020-03-20 08:16:44 +0000
committerwilliam <wan@odoo.com>2020-03-20 20:10:00 +0000
commit92f9d9b21b7bdde796e6105ee53f83d71fde3044 (patch)
tree8a298dd09f4056cb9bc292b26ec48deecd867541
parent25aaf7afcff9b361d809c112bc8e93c91c357519 (diff)
[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>
-rw-r--r--addons/account/models/account_move.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index b1458bf43e6..2b7c8352f3e 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -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))))