[FIX] account.fiscal.position: Fix get_fiscal_position for auto apply:
First match a fiscal position for the given country, then for a country group containing the country. If none found, search a fiscal position without country nor country group
This commit is contained in:
parent
d8e67d647f
commit
c4ae1ef66d
|
@ -47,6 +47,16 @@ class account_fiscal_position(osv.osv):
|
||||||
'active': True,
|
'active': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _check_country(self, cr, uid, ids, context=None):
|
||||||
|
obj = self.browse(cr, uid, ids[0], context=context)
|
||||||
|
if obj.country_id and obj.country_group_id:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
_constraints = [
|
||||||
|
(_check_country, 'You can not select a country and a group of countries', ['country_id', 'country_group_id']),
|
||||||
|
]
|
||||||
|
|
||||||
@api.v7
|
@api.v7
|
||||||
def map_tax(self, cr, uid, fposition_id, taxes, context=None):
|
def map_tax(self, cr, uid, fposition_id, taxes, context=None):
|
||||||
if not taxes:
|
if not taxes:
|
||||||
|
@ -115,10 +125,17 @@ class account_fiscal_position(osv.osv):
|
||||||
domain = [
|
domain = [
|
||||||
('auto_apply', '=', True),
|
('auto_apply', '=', True),
|
||||||
'|', ('vat_required', '=', False), ('vat_required', '=', partner.vat_subjected),
|
'|', ('vat_required', '=', False), ('vat_required', '=', partner.vat_subjected),
|
||||||
'|', ('country_id', '=', None), ('country_id', '=', delivery.country_id.id),
|
|
||||||
'|', ('country_group_id', '=', None), ('country_group_id.country_ids', '=', delivery.country_id.id)
|
|
||||||
]
|
]
|
||||||
fiscal_position_ids = self.search(cr, uid, domain, context=context)
|
|
||||||
|
fiscal_position_ids = self.search(cr, uid, domain + [('country_id', '=', delivery.country_id.id)], context=context, limit=1)
|
||||||
|
if fiscal_position_ids:
|
||||||
|
return fiscal_position_ids[0]
|
||||||
|
|
||||||
|
fiscal_position_ids = self.search(cr, uid, domain + [('country_group_id.country_ids', '=', delivery.country_id.id)], context=context, limit=1)
|
||||||
|
if fiscal_position_ids:
|
||||||
|
return fiscal_position_ids[0]
|
||||||
|
|
||||||
|
fiscal_position_ids = self.search(cr, uid, domain + [('country_id', '=', None), ('country_group_id', '=', None)], context=context, limit=1)
|
||||||
if fiscal_position_ids:
|
if fiscal_position_ids:
|
||||||
return fiscal_position_ids[0]
|
return fiscal_position_ids[0]
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
<field name="auto_apply"/>
|
<field name="auto_apply"/>
|
||||||
<field name="sequence"/>
|
<field name="sequence"/>
|
||||||
<field name="vat_required" attrs="{'readonly': [('auto_apply', '=', False)]}"/>
|
<field name="vat_required" attrs="{'readonly': [('auto_apply', '=', False)]}"/>
|
||||||
<field name="country_id" attrs="{'readonly': ['|', ('country_group_id','!=',False), ('auto_apply', '=', False)]}" />
|
<field name="country_id"/>
|
||||||
<field name="country_group_id" attrs="{'readonly': ['|', ('country_id','!=',False), ('auto_apply', '=', False)]}"/>
|
<field name="country_group_id"/>
|
||||||
</group>
|
</group>
|
||||||
<separator string="Taxes Mapping"/>
|
<separator string="Taxes Mapping"/>
|
||||||
<field name="tax_ids" widget="one2many_list">
|
<field name="tax_ids" widget="one2many_list">
|
||||||
|
|
Loading…
Reference in New Issue