|
| 1 | +# Copyright 2026 Tecnativa - Carlos Dauden |
| 2 | +# Copyright 2026 Tecnativa - Sergio Teruel |
| 3 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
| 4 | + |
| 5 | +from odoo import models |
| 6 | +from odoo.tools import ormcache_context |
| 7 | + |
| 8 | + |
| 9 | +class ResPartner(models.Model): |
| 10 | + _inherit = "res.partner" |
| 11 | + |
| 12 | + @ormcache_context("self.vat, self.country_id", keys=("is_canary_tax_agency",)) |
| 13 | + def _parse_aeat_vat_info(self): |
| 14 | + # NOTE: |
| 15 | + # The Canary Islands Tax Agency (ATC) SII-IGIC implementation does NOT support |
| 16 | + # IDType "02" (EU VAT number / NIF-IVA) used by the Spanish AEAT SII (VAT). |
| 17 | + # |
| 18 | + # Although the data structure is similar, ATC does not validate intra-community |
| 19 | + # operators nor VIES registrations, since IGIC is not VAT. |
| 20 | + # |
| 21 | + # As a result, foreign VAT numbers must be reported using IDType "04" |
| 22 | + # ("Official identification document") instead of "02". |
| 23 | + # |
| 24 | + # Using IDType "02" causes ATC to reject the record with error code 1103 |
| 25 | + # ("Valor del campo IDType incorrecto"). |
| 26 | + # |
| 27 | + # This conversion is intentional and required for SII submissions to ATC. |
| 28 | + country_code, identifier_type, identifier = super()._parse_aeat_vat_info() |
| 29 | + is_canary_tax_agency = self.env.context.get("is_canary_tax_agency") |
| 30 | + if is_canary_tax_agency and identifier_type == "02": |
| 31 | + identifier_type = "04" |
| 32 | + return country_code, identifier_type, identifier |
0 commit comments