From 73660ee2269dbf5ae64ab0540aa9add67c8e4282 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Fri, 31 Jul 2026 19:11:49 +0200 Subject: [PATCH] Revert "[FIX] l10n_es_edi_tbai_reagyp_recibidas: fix chaining within same invoice series" This reverts commit 8bf9779d98bf08c52b799c4e1a0a4d340bfa87d9. --- .../models/__init__.py | 2 - .../models/l10n_es_edi_tbai_document.py | 62 ------------------- .../models/res_company.py | 22 ------- 3 files changed, 86 deletions(-) delete mode 100644 l10n_es_edi_tbai_reagyp_recibidas/models/l10n_es_edi_tbai_document.py delete mode 100644 l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py diff --git a/l10n_es_edi_tbai_reagyp_recibidas/models/__init__.py b/l10n_es_edi_tbai_reagyp_recibidas/models/__init__.py index 265dbff..e89b491 100644 --- a/l10n_es_edi_tbai_reagyp_recibidas/models/__init__.py +++ b/l10n_es_edi_tbai_reagyp_recibidas/models/__init__.py @@ -1,3 +1 @@ from . import account_move # noqa: F401 -from . import res_company # noqa: F401 -from . import l10n_es_edi_tbai_document # noqa: F401 diff --git a/l10n_es_edi_tbai_reagyp_recibidas/models/l10n_es_edi_tbai_document.py b/l10n_es_edi_tbai_reagyp_recibidas/models/l10n_es_edi_tbai_document.py deleted file mode 100644 index 9f06ffa..0000000 --- a/l10n_es_edi_tbai_reagyp_recibidas/models/l10n_es_edi_tbai_document.py +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright 2026 - Today Criptomart -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import re - -from odoo import models - - -class L10nEsEdiTbaiDocument(models.Model): - _inherit = "l10n_es_edi_tbai.document" - - def _get_sale_values(self, values): - """Override to ensure chain links only within the same invoice series.""" - sale_values = super()._get_sale_values(values) - - # Replace chain_prev_document with one from the same series - chain_prev_document = sale_values.get("chain_prev_document") - if chain_prev_document: - current_series = self._get_series_prefix(self.name) - prev_series = self._get_series_prefix(chain_prev_document.name) - - # If series mismatch OR previous doc has no valid XML, find correct one - if ( - current_series != prev_series - or not chain_prev_document.xml_attachment_id - ): - same_series_doc = self._get_last_chained_document_by_series( - current_series - ) - sale_values["chain_prev_document"] = same_series_doc - - return sale_values - - @staticmethod - def _get_series_prefix(doc_name): - """Extract series prefix from document name (e.g., 'INV/2026/' from 'INV/2026/01248').""" - if not doc_name: - return "" - # Everything before the first digit - match = re.search(r"\d+", doc_name) - if match: - return doc_name[: match.start()].rstrip("/") - return doc_name - - def _get_last_chained_document_by_series(self, series_prefix): - """Find the last valid chained document matching a specific series prefix.""" - domain = [ - ("chain_index", "!=", 0), - ("company_id", "=", self.company_id.id), - ("is_cancel", "=", False), - ("state", "=", "accepted"), # Must be accepted in chain - ] - docs = self.search(domain, order="chain_index desc") - - # Return the first doc matching series that has valid XML - for doc in docs: - if ( - self._get_series_prefix(doc.name) == series_prefix - and doc.xml_attachment_id - ): - return doc - - return self.env["l10n_es_edi_tbai.document"] diff --git a/l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py b/l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py deleted file mode 100644 index 179e146..0000000 --- a/l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2026 - Today Criptomart -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models - - -class ResCompany(models.Model): - _inherit = "res.company" - - def _get_l10n_es_tbai_last_chained_document(self): - """ - Returns the last tbai document posted to this company's chain. - Each invoice series has its own independent chain in TicketBAI. - Filters out cancellation documents to skip cancelled invoices. - """ - domain = [ - ("chain_index", "!=", 0), - ("company_id", "=", self.id), - ("is_cancel", "=", False), - ] - return self.env["l10n_es_edi_tbai.document"].search( - domain, limit=1, order="chain_index desc" - )