From 0bf118d0931b9779e13ec46d98fe63c1a61d1a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20L=C3=B3pez?= Date: Thu, 16 May 2024 15:46:19 -0400 Subject: [PATCH] [REF] l10n_do_accounting: use v16 _compute_name() code --- l10n_do_accounting/__manifest__.py | 2 +- l10n_do_accounting/models/monkey_patch.py | 98 +++++------------------ 2 files changed, 21 insertions(+), 79 deletions(-) diff --git a/l10n_do_accounting/__manifest__.py b/l10n_do_accounting/__manifest__.py index f5fba8073..ace62c09c 100644 --- a/l10n_do_accounting/__manifest__.py +++ b/l10n_do_accounting/__manifest__.py @@ -8,7 +8,7 @@ "category": "Localization", "license": "LGPL-3", "website": "https://github.com/odoo-dominicana", - "version": "16.0.1.5.4", + "version": "16.0.1.5.5", # any module necessary for this one to work correctly "depends": ["l10n_latam_invoice_document", "l10n_do"], # always loaded diff --git a/l10n_do_accounting/models/monkey_patch.py b/l10n_do_accounting/models/monkey_patch.py index 6038d33b1..47eaa8e73 100644 --- a/l10n_do_accounting/models/monkey_patch.py +++ b/l10n_do_accounting/models/monkey_patch.py @@ -8,89 +8,31 @@ class AccountMove(models.Model): @api.depends("posted_before", "state", "journal_id", "date") def _compute_name(self): - def journal_key(move): - return (move.journal_id, move.journal_id.refund_sequence and move.move_type) - - def date_key(move): - return (move.date.year, move.date.month) - - grouped = defaultdict( # key: journal_id, move_type - lambda: defaultdict( # key: first adjacent (date.year, date.month) - lambda: { - "records": self.env["account.move"], - "format": False, - "format_values": False, - "reset": False, - } - ) - ) self = self.sorted(lambda m: (m.date, m.ref or "", m.id)) - highest_name = self[0]._get_last_sequence(lock=False) if self else False - # Group the moves by journal and month for move in self: - if ( - not highest_name - and move == self[0] - and not move.posted_before - and move.date - ): - # In the form view, we need to compute a default sequence so that the user can edit - # it. We only check the first move as an approximation (enough for new in form view) - pass - elif (move.name and move.name != "/") or move.state != "posted": - try: - if not move.posted_before: - move._constrains_date_sequence() - # Has already a name or is not posted, we don't add to a batch - continue - except ValidationError: - # Has never been posted and the name doesn't match the date: recompute it - pass - group = grouped[journal_key(move)][date_key(move)] - if not group["records"]: - # Compute all the values needed to sequence this whole group - move._set_next_sequence() - ( - group["format"], - group["format_values"], - ) = move._get_sequence_format_param(move.name) - group["reset"] = move._deduce_sequence_number_reset(move.name) - group["records"] += move - - # Fusion the groups depending on the sequence reset and the format used because `seq` is - # the same counter for multiple groups that might be spread in multiple months. - final_batches = [] - for journal_group in grouped.values(): - journal_group_changed = True - for date_group in journal_group.values(): - if ( - journal_group_changed - or final_batches[-1]["format"] != date_group["format"] - or dict(final_batches[-1]["format_values"], seq=0) - != dict(date_group["format_values"], seq=0) - ): - final_batches += [date_group] - journal_group_changed = False - elif date_group["reset"] == "never": - final_batches[-1]["records"] += date_group["records"] - elif ( - date_group["reset"] == "year" - and final_batches[-1]["records"][0].date.year - == date_group["records"][0].date.year - ): - final_batches[-1]["records"] += date_group["records"] + if move.state == "cancel": + continue + + move_has_name = move.name and move.name != "/" + if move_has_name or move.state != "posted": + if not move.posted_before and not move._sequence_matches_date(): + if move._get_last_sequence(lock=False): + move.name = False + continue else: - final_batches += [date_group] - - # Give the name based on previously computed values - for batch in final_batches: - for move in batch["records"]: - move.name = batch["format"].format(**batch["format_values"]) - batch["format_values"]["seq"] += 1 - batch["records"]._compute_split_sequence() + if ( + move_has_name + and move.posted_before + or not move_has_name + and move._get_last_sequence(lock=False) + ): + continue + if move.date and (not move_has_name or not move._sequence_matches_date()): + move._set_next_sequence() - self.filtered(lambda m: not m.name).name = "/" + self.filtered(lambda m: not m.name and not move.quick_edit_mode).name = "/" + self._inverse_name() for move in self.filtered( lambda x: x.country_code == "DO"