mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 17:02:07 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
from odoo.tests import common
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo import Command
|
||||
|
||||
|
||||
class TestFiscalPosition(common.TransactionCase):
|
||||
|
|
@ -43,25 +44,23 @@ class TestFiscalPosition(common.TransactionCase):
|
|||
country_id=fr.id))
|
||||
cls.alberto = cls.res_partner.create(dict(
|
||||
name="Alberto",
|
||||
vat="BE0477472701",
|
||||
vat="ZUÑ920208KL4",
|
||||
country_id=mx.id))
|
||||
cls.be_nat = cls.fp.create(dict(
|
||||
name="BE-NAT",
|
||||
auto_apply=True,
|
||||
country_id=be.id,
|
||||
vat_required=False,
|
||||
sequence=10))
|
||||
cls.fr_b2c = cls.fp.create(dict(
|
||||
name="EU-VAT-FR-B2C",
|
||||
auto_apply=True,
|
||||
country_id=fr.id,
|
||||
vat_required=False,
|
||||
sequence=40))
|
||||
cls.fr_b2b = cls.fp.create(dict(
|
||||
name="EU-VAT-FR-B2B",
|
||||
auto_apply=True,
|
||||
country_id=fr.id,
|
||||
vat_required=True,
|
||||
sequence=40))
|
||||
cls.fr_b2c = cls.fp.create(dict(
|
||||
name="EU-VAT-FR-B2C",
|
||||
auto_apply=True,
|
||||
country_id=fr.id,
|
||||
sequence=50))
|
||||
|
||||
def test_10_fp_country(self):
|
||||
|
|
@ -71,90 +70,43 @@ class TestFiscalPosition(common.TransactionCase):
|
|||
expected_pos.id,
|
||||
message)
|
||||
|
||||
george, jc, ben, alberto = self.george, self.jc, self.ben, self.alberto
|
||||
|
||||
# B2B has precedence over B2C for same country even when sequence gives lower precedence
|
||||
self.assertGreater(self.fr_b2b.sequence, self.fr_b2c.sequence)
|
||||
assert_fp(george, self.fr_b2b, "FR-B2B should have precedence over FR-B2C")
|
||||
self.fr_b2b.auto_apply = False
|
||||
assert_fp(george, self.fr_b2c, "FR-B2C should match now")
|
||||
self.fr_b2b.auto_apply = True
|
||||
|
||||
# Create positions matching on Country Group and on NO country at all
|
||||
self.eu_intra_b2b = self.fp.create(dict(
|
||||
name="EU-INTRA B2B",
|
||||
auto_apply=True,
|
||||
country_group_id=self.eu.id,
|
||||
vat_required=True,
|
||||
sequence=20))
|
||||
self.world = self.fp.create(dict(
|
||||
name="WORLD-EXTRA",
|
||||
auto_apply=True,
|
||||
vat_required=False,
|
||||
sequence=30))
|
||||
|
||||
# Country match has higher precedence than group match or sequence
|
||||
self.assertGreater(self.fr_b2b.sequence, self.eu_intra_b2b.sequence)
|
||||
assert_fp(george, self.fr_b2b, "FR-B2B should have precedence over EU-INTRA B2B")
|
||||
|
||||
# B2B has precedence regardless of country or group match
|
||||
self.assertGreater(self.eu_intra_b2b.sequence, self.be_nat.sequence)
|
||||
assert_fp(jc, self.eu_intra_b2b, "EU-INTRA B2B should match before BE-NAT")
|
||||
|
||||
# Lower sequence = higher precedence if country/group and VAT matches
|
||||
self.assertFalse(ben.vat) # No VAT set
|
||||
assert_fp(ben, self.be_nat, "BE-NAT should match before EU-INTRA due to lower sequence")
|
||||
|
||||
# Remove BE from EU group, now BE-NAT should be the fallback match before the wildcard WORLD
|
||||
self.be.write({'country_group_ids': [(3, self.eu.id)]})
|
||||
self.assertTrue(jc.vat) # VAT set
|
||||
assert_fp(jc, self.be_nat, "BE-NAT should match as fallback even w/o VAT match")
|
||||
|
||||
# No country = wildcard match only if nothing else matches
|
||||
self.assertTrue(alberto.vat) # with VAT
|
||||
assert_fp(alberto, self.world, "WORLD-EXTRA should match anything else (1)")
|
||||
alberto.vat = False # or without
|
||||
assert_fp(alberto, self.world, "WORLD-EXTRA should match anything else (2)")
|
||||
self.assertFalse(self.ben.vat) # No VAT set
|
||||
assert_fp(self.ben, self.be_nat, "BE-NAT should match before EU-INTRA due to lower sequence")
|
||||
|
||||
# Zip range
|
||||
self.fr_b2b_zip100 = self.fr_b2b.copy(dict(zip_from=0, zip_to=5000, sequence=60))
|
||||
george.zip = 6000
|
||||
assert_fp(george, self.fr_b2b, "FR-B2B with wrong zip range should not match")
|
||||
george.zip = 3000
|
||||
assert_fp(george, self.fr_b2b_zip100, "FR-B2B with zip range should have precedence")
|
||||
fr_b2b_zip100 = self.fr_b2b.copy(dict(zip_from=0, zip_to=5000, sequence=1))
|
||||
self.george.zip = 6000
|
||||
assert_fp(self.george, self.fr_b2b, "FR-B2B with wrong zip range should not match")
|
||||
self.george.zip = 1234
|
||||
assert_fp(self.george, fr_b2b_zip100, "FR-B2B with ok zip range should match")
|
||||
self.george.zip = None
|
||||
|
||||
# States
|
||||
self.fr_b2b_state = self.fr_b2b.copy(dict(state_ids=[(4, self.state_fr.id)], sequence=70))
|
||||
george.state_id = self.state_fr
|
||||
assert_fp(george, self.fr_b2b_zip100, "FR-B2B with zip should have precedence over states")
|
||||
george.zip = False
|
||||
assert_fp(george, self.fr_b2b_state, "FR-B2B with states should have precedence")
|
||||
fr_b2b_state = self.fr_b2b.copy(dict(state_ids=[(4, self.state_fr.id)], sequence=1))
|
||||
assert_fp(self.george, self.fr_b2b, "FR-B2B with states should not match")
|
||||
self.george.state_id = self.state_fr
|
||||
assert_fp(self.george, fr_b2b_state, "FR-B2B with states should match")
|
||||
|
||||
# Dedicated position has max precedence
|
||||
george.property_account_position_id = self.be_nat
|
||||
assert_fp(george, self.be_nat, "Forced position has max precedence")
|
||||
self.george.property_account_position_id = self.be_nat
|
||||
assert_fp(self.george, self.be_nat, "Forced position has max precedence")
|
||||
|
||||
|
||||
def test_20_fp_one_tax_2m(self):
|
||||
self.env.company.country_id = self.env.ref('base.us')
|
||||
self.env['account.tax.group'].create(
|
||||
{'name': 'Test Tax Group', 'company_id': self.env.company.id}
|
||||
)
|
||||
|
||||
self.src_tax = self.env['account.tax'].create({'name': "SRC", 'amount': 0.0})
|
||||
self.dst1_tax = self.env['account.tax'].create({'name': "DST1", 'amount': 0.0})
|
||||
self.dst2_tax = self.env['account.tax'].create({'name': "DST2", 'amount': 0.0})
|
||||
|
||||
self.fp2m = self.fp.create({
|
||||
'name': "FP-TAX2TAXES",
|
||||
'tax_ids': [
|
||||
(0,0,{
|
||||
'tax_src_id': self.src_tax.id,
|
||||
'tax_dest_id': self.dst1_tax.id
|
||||
}),
|
||||
(0,0,{
|
||||
'tax_src_id': self.src_tax.id,
|
||||
'tax_dest_id': self.dst2_tax.id
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
self.dst1_tax = self.env['account.tax'].create({'name': "DST1", 'amount': 0.0, 'fiscal_position_ids': [Command.set(self.fp2m.ids)], 'original_tax_ids': [Command.set(self.src_tax.ids)], 'sequence': 10})
|
||||
self.dst2_tax = self.env['account.tax'].create({'name': "DST2", 'amount': 0.0, 'fiscal_position_ids': [Command.set(self.fp2m.ids)], 'original_tax_ids': [Command.set(self.src_tax.ids)], 'sequence': 5})
|
||||
mapped_taxes = self.fp2m.map_tax(self.src_tax)
|
||||
|
||||
self.assertEqual(mapped_taxes, self.dst1_tax | self.dst2_tax)
|
||||
|
|
@ -175,24 +127,22 @@ class TestFiscalPosition(common.TransactionCase):
|
|||
'vat_required': True,
|
||||
'sequence': 10,
|
||||
})
|
||||
fp_eu_priv = self.env['account.fiscal.position'].create({
|
||||
'name': 'EU privé',
|
||||
'auto_apply': True,
|
||||
'country_group_id': self.eu.id,
|
||||
'vat_required': False,
|
||||
'sequence': 20,
|
||||
})
|
||||
fp_eu_intra = self.env['account.fiscal.position'].create({
|
||||
'name': 'Régime Intra-Communautaire',
|
||||
'auto_apply': True,
|
||||
'country_group_id': self.eu.id,
|
||||
'vat_required': True,
|
||||
'sequence': 20,
|
||||
})
|
||||
fp_eu_priv = self.env['account.fiscal.position'].create({
|
||||
'name': 'EU privé',
|
||||
'auto_apply': True,
|
||||
'country_group_id': self.eu.id,
|
||||
'sequence': 30,
|
||||
})
|
||||
fp_eu_extra = self.env['account.fiscal.position'].create({
|
||||
'name': 'Régime Extra-Communautaire',
|
||||
'auto_apply': True,
|
||||
'vat_required': False,
|
||||
'sequence': 40,
|
||||
})
|
||||
|
||||
|
|
@ -270,6 +220,77 @@ class TestFiscalPosition(common.TransactionCase):
|
|||
fp_eu_extra
|
||||
)
|
||||
|
||||
def test_domestic_fp_map_self(self):
|
||||
self.env.company.country_id = self.us
|
||||
self.env['account.tax.group'].create(
|
||||
{'name': 'Test Tax Group', 'company_id': self.env.company.id}
|
||||
)
|
||||
fp = self.env['account.fiscal.position'].create({
|
||||
'name': 'FP Self',
|
||||
})
|
||||
tax = self.env['account.tax'].create({
|
||||
'name': 'Source Dest Tax',
|
||||
'amount': 10,
|
||||
'fiscal_position_ids': [Command.link(fp.id)],
|
||||
})
|
||||
self.assertEqual(fp.map_tax(tax), tax)
|
||||
|
||||
def test_domestic_fp(self):
|
||||
"""
|
||||
check if the domestic fiscal position is well computed in different scenarios.
|
||||
"""
|
||||
country_group, a_country_group = self.env['res.country.group'].create([{
|
||||
'name': "One country group",
|
||||
}, {
|
||||
'name': "Alphabetically first country_group",
|
||||
}])
|
||||
my_country = self.env['res.country'].create({
|
||||
'name': "Neverland",
|
||||
'code': 'PP',
|
||||
'country_group_ids': [Command.set(country_group.ids + a_country_group.ids)],
|
||||
})
|
||||
self.env.company.country_id = my_country
|
||||
|
||||
# AT case - no sequence, one country_id
|
||||
fp_1, fp_2, fp_3 = self.env['account.fiscal.position'].create([{
|
||||
'name': 'FP First',
|
||||
'country_group_id': country_group.id,
|
||||
}, {
|
||||
'name': 'FP Second',
|
||||
'country_id': my_country.id,
|
||||
}, {
|
||||
'name': 'FP 3',
|
||||
'country_group_id': country_group.id,
|
||||
}])
|
||||
self.assertEqual(self.env.company.domestic_fiscal_position_id, fp_2)
|
||||
|
||||
# SA case - same sequence, one country_id
|
||||
(fp_1 + fp_2 + fp_3).write({'sequence': 10})
|
||||
fp_1.write({
|
||||
'country_id': my_country.id,
|
||||
'country_group_id': False,
|
||||
})
|
||||
fp_2.write({'country_id': False})
|
||||
self.assertEqual(self.env.company.domestic_fiscal_position_id, fp_1)
|
||||
|
||||
# NL case - different sequence, both country_group_id and country_id on a fp
|
||||
(fp_1 + fp_2).write({'country_group_id': country_group.id})
|
||||
fp_1.write({'country_id': False})
|
||||
fp_2.write({'country_id': my_country.id})
|
||||
fp_3.write({'country_group_id': a_country_group.id})
|
||||
self.assertEqual(self.env.company.domestic_fiscal_position_id, fp_2)
|
||||
|
||||
# Check that sequence is applied after the country
|
||||
fp_2.write({'sequence': 20})
|
||||
fp_3.write({'sequence': 15})
|
||||
self.assertEqual(self.env.company.domestic_fiscal_position_id, fp_1)
|
||||
|
||||
# CH/LI case - one fp with country_group_id only, nothing for others
|
||||
fp_1.write({'sequence': 30})
|
||||
fp_2.write({'country_id': False})
|
||||
fp_3.write({'country_group_id': False})
|
||||
self.assertEqual(self.env.company.domestic_fiscal_position_id, fp_2)
|
||||
|
||||
def test_fiscal_position_constraint(self):
|
||||
"""
|
||||
Test fiscal position constraint by updating the record
|
||||
|
|
@ -304,3 +325,21 @@ class TestFiscalPosition(common.TransactionCase):
|
|||
'zip_from': '123',
|
||||
'zip_to': '456',
|
||||
}])
|
||||
|
||||
def test_fiscal_position_different_vat_country(self):
|
||||
""" If the country is European, we need to be able to put the VAT of another country through the prefix"""
|
||||
fiscal_position = self.fp.create({
|
||||
'name': 'Special Delivery Case',
|
||||
'country_id': self.env.ref('base.fr').id,
|
||||
'foreign_vat': 'BE0477472701',
|
||||
})
|
||||
self.assertEqual(fiscal_position.foreign_vat, 'BE0477472701')
|
||||
|
||||
def test_get_first_fiscal_position(self):
|
||||
fiscal_positions = self.fp.create([{
|
||||
'name': f'fiscal_position_{sequence}',
|
||||
'auto_apply': True,
|
||||
'country_id': self.jc.country_id.id,
|
||||
'sequence': sequence
|
||||
} for sequence in range(1, 3)])
|
||||
self.assertEqual(self.fp._get_fiscal_position(self.jc), fiscal_positions[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue