commit
5364e84c35
@ -23,7 +23,6 @@ class AccountMove(models.Model):
|
|||||||
entry_number = fields.Char(
|
entry_number = fields.Char(
|
||||||
index=True,
|
index=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
tracking=True,
|
|
||||||
store=True,
|
store=True,
|
||||||
compute="_compute_entry_number",
|
compute="_compute_entry_number",
|
||||||
help="Automatic numbering, based on journal configuration.",
|
help="Automatic numbering, based on journal configuration.",
|
||||||
@ -59,9 +58,16 @@ class AccountMove(models.Model):
|
|||||||
chosen = self.filtered_domain(
|
chosen = self.filtered_domain(
|
||||||
[("state", "=", "posted"), ("entry_number", "=", False)]
|
[("state", "=", "posted"), ("entry_number", "=", False)]
|
||||||
)
|
)
|
||||||
|
# Cache all the new numbers to avoid wasting recomputations, caused by
|
||||||
|
# searches done by _next() in the loop below
|
||||||
|
chosen_map = {}
|
||||||
for move in chosen.sorted(lambda one: (one.date, one.name, one.id)):
|
for move in chosen.sorted(lambda one: (one.date, one.name, one.id)):
|
||||||
move.entry_number = move.journal_id.entry_number_sequence_id._next(
|
chosen_map[move.id] = move.journal_id.entry_number_sequence_id._next(
|
||||||
move.date
|
move.date
|
||||||
)
|
)
|
||||||
|
# Write all the new numbers in the chosen moves
|
||||||
|
for move_id, new_number in chosen_map.items():
|
||||||
|
self.browse(move_id).entry_number = new_number
|
||||||
if chosen:
|
if chosen:
|
||||||
_logger.info("Added entry_number to %r", chosen)
|
_logger.info("Added entry_number to %d account moves", len(chosen))
|
||||||
|
_logger.debug("Added entry_number to %r", chosen)
|
||||||
|
@ -42,12 +42,15 @@ class RenumberCase(TestAccountReconciliationCommon):
|
|||||||
next_year_invoice = self._create_invoice(
|
next_year_invoice = self._create_invoice(
|
||||||
date_invoice="2023-12-31", auto_validate=True
|
date_invoice="2023-12-31", auto_validate=True
|
||||||
)
|
)
|
||||||
|
next_year_invoice.flush(["entry_number"], next_year_invoice)
|
||||||
new_invoice = self._create_invoice(
|
new_invoice = self._create_invoice(
|
||||||
date_invoice="2022-05-10", auto_validate=True
|
date_invoice="2022-05-10", auto_validate=True
|
||||||
)
|
)
|
||||||
|
new_invoice.flush(["entry_number"], new_invoice)
|
||||||
old_invoice = self._create_invoice(
|
old_invoice = self._create_invoice(
|
||||||
date_invoice="2022-04-30", auto_validate=True
|
date_invoice="2022-04-30", auto_validate=True
|
||||||
)
|
)
|
||||||
|
old_invoice.flush(["entry_number"], old_invoice)
|
||||||
self.assertLess(new_invoice.entry_number, old_invoice.entry_number)
|
self.assertLess(new_invoice.entry_number, old_invoice.entry_number)
|
||||||
# Fix entry number order with wizard; default values are OK
|
# Fix entry number order with wizard; default values are OK
|
||||||
wiz_f = Form(self.env["account.move.renumber.wizard"])
|
wiz_f = Form(self.env["account.move.renumber.wizard"])
|
||||||
|
Loading…
Reference in New Issue
Block a user