From 49fe63a4d041f1fcbda045e553bc56c67391b8c6 Mon Sep 17 00:00:00 2001 From: "John (jol)" Date: Thu, 12 Aug 2021 13:11:54 +0000 Subject: [PATCH 1/2] [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 --- addons/account/models/partner.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 775ac97b105..56510f2d2c5 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -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 From 56387832ec5eabfe86bd936c9bd71b3fdc7cb666 Mon Sep 17 00:00:00 2001 From: "John Laterre (jol)" Date: Thu, 20 Jan 2022 10:34:27 +0000 Subject: [PATCH 2/2] [FIX] sale_stock: fix perf tests Since this commit: d26b468 the number of queries executed when creating a sale order is counted. Because of the current change in the code, the numbers are no longer accurate. Hence this correction. Related PR : #75033 Part-of: odoo/odoo#81832 --- addons/sale_stock/tests/test_create_perf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sale_stock/tests/test_create_perf.py b/addons/sale_stock/tests/test_create_perf.py index 38e4f1f247b..654b19ab203 100644 --- a/addons/sale_stock/tests/test_create_perf.py +++ b/addons/sale_stock/tests/test_create_perf.py @@ -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,