[FIX] l10n_es_edi_tbai_reagyp_recibidas: fix chaining within same invoice series
TicketBAI maintains independent chains per invoice series (INV, RINV, etc). When building the chain for a new invoice, ensure it links to the previous valid document from the same series, not just the last document regardless of series. Fixes error "time data '' does not match format '%d-%m-%Y'" when previous document's XML is missing or when wrong series document is used for chaining. - Override _get_sale_values to validate series match - Add _get_last_chained_document_by_series to filter by series+state+xml - Skip cancelled documents and documents without valid XML Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5a6d9c9894
commit
8bf9779d98
3 changed files with 86 additions and 0 deletions
22
l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py
Normal file
22
l10n_es_edi_tbai_reagyp_recibidas/models/res_company.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# 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"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue