Skip to content

Commit b30bea8

Browse files
committed
[FIX] l10n_es_aeat_sii_match: Look for vendor bill properly
On vendor bills, the invoice number may be repeated across different vendors, returning an incorrect matching. For minimizing this, we first look for invoices with the same date, and if more than one match, then we iterate for finding the one matching (maybe partially) the VAT. We are not including the VAT comparison on the initial search, because you may have other identifier set on the partner, and then not returning any result at all, so we reserve this check only in case of multiple match.
1 parent afe352f commit b30bea8

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

l10n_es_aeat_sii_match/models/aeat_sii_match_report.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import copy
66
import json
7+
from datetime import datetime
78

89
from dateutil.relativedelta import relativedelta
910
from zeep.helpers import serialize_object
@@ -12,6 +13,8 @@
1213
from odoo.exceptions import UserError
1314
from odoo.modules.registry import Registry
1415

16+
from odoo.addons.l10n_es_aeat.models.aeat_mixin import AEAT_DATE_FORMAT
17+
1518
SII_VERSION = "1.1"
1619

1720

@@ -162,13 +165,23 @@ def _get_aeat_odoo_invoices_by_num(self, left_invoices, matched_invoices):
162165
limit=1,
163166
)
164167
else:
168+
invoice_date = invoice["IDFactura"]["FechaExpedicionFacturaEmisor"]
169+
invoice_date = datetime.strptime(invoice_date, AEAT_DATE_FORMAT)
165170
odoo_invoice = self.env["account.move"].search(
166171
[
167172
("ref", "=", name),
173+
("invoice_date", "=", invoice_date),
168174
("move_type", "in", ["in_invoice", "in_refund"]),
169175
],
170-
limit=1,
171176
)
177+
if len(odoo_invoice) > 1:
178+
vat = invoice["IDFactura"]["IDEmisorFactura"].get("NIF", "NO_VALID")
179+
for rec in odoo_invoice:
180+
if vat in rec.partner_id.vat:
181+
odoo_invoice = rec
182+
break
183+
else:
184+
odoo_invoice = False # Don't match with any of them
172185
if odoo_invoice and odoo_invoice.id not in list(matched_invoices.keys()):
173186
matched_invoices[odoo_invoice.id] = invoice
174187
else:

0 commit comments

Comments
 (0)