[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 closes odoo/odoo#81832 Task: 2596204 Forward-port-of: odoo/odoo#75033 Signed-off-by: Quentin De Paoli <qdp@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestPERF(common.TransactionCase):
|
||||
@users('admin')
|
||||
@warmup
|
||||
def test_empty_sale_order_creation_perf(self):
|
||||
with self.assertQueryCount(admin=33):
|
||||
with self.assertQueryCount(admin=34):
|
||||
self.env['sale.order'].create({
|
||||
'partner_id': self.partners[0].id,
|
||||
'user_id': self.salesmans[0].id,
|
||||
@@ -87,7 +87,7 @@ class TestPERF(common.TransactionCase):
|
||||
@users('admin')
|
||||
@warmup
|
||||
def test_light_sales_orders_batch_creation_perf(self):
|
||||
with self.assertQueryCount(admin=68): # 67 locally, 68 in nightly runbot
|
||||
with self.assertQueryCount(admin=69): # 68 locally, 69 in nightly runbot
|
||||
self.env['sale.order'].create([{
|
||||
'partner_id': self.partners[0].id,
|
||||
'user_id': self.salesmans[0].id,
|
||||
|
||||
Reference in New Issue
Block a user