[FIX] account: fix fiscal position with delivery address

The goal is to ensure that 2 conditions are met for a fiscal position to
be applied (within the EU):

- The customer must have a valid VAT number from another EU Member State
- The goods must leave the country of origin

Task: 2596204
X-original-commit: ca0fc6cda38fd1e4d3c8cd8953bea790a90001f5
Part-of: odoo/odoo#81832
This commit is contained in:
John (jol)
2022-01-24 16:05:55 +00:00
committed by John Laterre (jol)
parent 36258053c5
commit 49fe63a4d0
+9 -2
View File
@@ -215,8 +215,15 @@ class AccountFiscalPosition(models.Model):
if not partner:
return self.env['account.fiscal.position']
# if no delivery use invoicing
if not delivery:
company = self.env.company
intra_eu = vat_exclusion = False
if company.vat and partner.vat:
eu_country_codes = set(self.env.ref('base.europe').country_ids.mapped('code'))
intra_eu = company.vat[:2] in eu_country_codes and partner.vat[:2] in eu_country_codes
vat_exclusion = company.vat[:2] == partner.vat[:2]
# If company and partner have the same vat prefix (and are both within the EU), use invoicing
if not delivery or (intra_eu and vat_exclusion):
delivery = partner
# partner manually set fiscal position always win