# 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" )