[FIX] account: choosing the right fiscal position
for a partner who has vat number, fiscal positions with vat_required are prefered. opw:630849
This commit is contained in:
parent
a70ea6d03b
commit
940a0e45d4
|
@ -123,10 +123,12 @@ class account_fiscal_position(osv.osv):
|
||||||
else:
|
else:
|
||||||
delivery = partner
|
delivery = partner
|
||||||
|
|
||||||
domain = [
|
domains = [[('auto_apply', '=', True), ('vat_required', '=', partner.vat_subjected)]]
|
||||||
('auto_apply', '=', True),
|
if partner.vat_subjected:
|
||||||
'|', ('vat_required', '=', False), ('vat_required', '=', partner.vat_subjected),
|
# Possibly allow fallback to non-VAT positions, if no VAT-required position matches
|
||||||
]
|
domains += [[('auto_apply', '=', True), ('vat_required', '=', False)]]
|
||||||
|
|
||||||
|
for domain in domains:
|
||||||
if delivery.country_id.id:
|
if delivery.country_id.id:
|
||||||
fiscal_position_ids = self.search(cr, uid, domain + [('country_id', '=', delivery.country_id.id)], context=context, limit=1)
|
fiscal_position_ids = self.search(cr, uid, domain + [('country_id', '=', delivery.country_id.id)], context=context, limit=1)
|
||||||
if fiscal_position_ids:
|
if fiscal_position_ids:
|
||||||
|
|
|
@ -2,3 +2,4 @@ from . import test_tax
|
||||||
from . import test_search
|
from . import test_search
|
||||||
from . import test_reconciliation
|
from . import test_reconciliation
|
||||||
from . import test_account_move_closed_period
|
from . import test_account_move_closed_period
|
||||||
|
from . import test_fiscal_position
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
from openerp.tests.common import TransactionCase
|
||||||
|
|
||||||
|
class TestFiscalPosition(TransactionCase):
|
||||||
|
"""Tests for fiscal positions in auto apply (account.fiscal.position).
|
||||||
|
If a partner has a vat number, the fiscal positions with "vat_required=True"
|
||||||
|
are prefered.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestFiscalPosition, self).setUp()
|
||||||
|
self.fiscal_position_model = self.registry('account.fiscal.position')
|
||||||
|
self.res_partner_model = self.registry('res.partner')
|
||||||
|
self.res_country_model = self.registry('res.country')
|
||||||
|
|
||||||
|
def test_fiscal_position(self):
|
||||||
|
cr, uid = self.cr, self.uid
|
||||||
|
company_id = 1
|
||||||
|
country_id = self.res_country_model.search(cr, uid, [('name', '=', 'France')])[0]
|
||||||
|
partner_id = self.res_partner_model.create(cr, uid, dict(
|
||||||
|
name="George",
|
||||||
|
vat_subjected=True,
|
||||||
|
notify_email="always",
|
||||||
|
country_id=country_id))
|
||||||
|
fp_b2c_id = self.fiscal_position_model.create(cr, uid, dict(name="EU-VAT-FR-B2C",
|
||||||
|
auto_apply=True,
|
||||||
|
country_id=country_id,
|
||||||
|
vat_required=False,
|
||||||
|
sequence=1))
|
||||||
|
fp_b2b_id = self.fiscal_position_model.create(cr, uid, dict(name="EU-VAT-FR-B2B",
|
||||||
|
auto_apply=True,
|
||||||
|
country_id=country_id,
|
||||||
|
vat_required=True,
|
||||||
|
sequence=2))
|
||||||
|
res = self.fiscal_position_model.get_fiscal_position(cr, uid, company_id, partner_id)
|
||||||
|
self.assertEquals(fp_b2b_id, res,
|
||||||
|
"Fiscal position detection should pick B2B position as 1rst match")
|
||||||
|
|
||||||
|
self.fiscal_position_model.write(cr, uid, [fp_b2b_id], {'auto_apply': False})
|
||||||
|
res = self.fiscal_position_model.get_fiscal_position(cr, uid, company_id, partner_id)
|
||||||
|
self.assertEquals(fp_b2c_id, res,
|
||||||
|
"Fiscal position detection should pick B2C position as 1rst match")
|
|
@ -151,7 +151,8 @@ class l10n_eu_service(models.TransientModel):
|
||||||
'ref_tax_code_id': tx_code.id,
|
'ref_tax_code_id': tx_code.id,
|
||||||
'ref_base_sign': -1,
|
'ref_base_sign': -1,
|
||||||
'ref_tax_sign': -1,
|
'ref_tax_sign': -1,
|
||||||
'description': "EU-VAT-%s-S" % country.code
|
'description': "EU-VAT-%s-S" % country.code,
|
||||||
|
'sequence': 1000,
|
||||||
}
|
}
|
||||||
tax = account_tax.create(data_tax)
|
tax = account_tax.create(data_tax)
|
||||||
if self.fiscal_position_id:
|
if self.fiscal_position_id:
|
||||||
|
|
Loading…
Reference in New Issue