Skip to content

Commit

Permalink
[FIX] account.fiscal.position: Fix get_fiscal_position for auto apply:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gorash authored and KangOl committed Oct 27, 2014
1 parent d8e67d6 commit c4ae1ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions addons/account/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class account_fiscal_position(osv.osv):
'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
def map_tax(self, cr, uid, fposition_id, taxes, context=None):
if not taxes:
Expand Down Expand Up @@ -115,10 +125,17 @@ def get_fiscal_position(self, cr, uid, company_id, partner_id, delivery_id=None,
domain = [
('auto_apply', '=', True),
'|', ('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:
return fiscal_position_ids[0]
return False
Expand Down
4 changes: 2 additions & 2 deletions addons/account/partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<field name="auto_apply"/>
<field name="sequence"/>
<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_group_id" attrs="{'readonly': ['|', ('country_id','!=',False), ('auto_apply', '=', False)]}"/>
<field name="country_id"/>
<field name="country_group_id"/>
</group>
<separator string="Taxes Mapping"/>
<field name="tax_ids" widget="one2many_list">
Expand Down

0 comments on commit c4ae1ef

Please sign in to comment.