[IMP] account: get_fiscal_position returns a recordset
This commit is contained in:
@@ -147,12 +147,17 @@ class AccountFiscalPosition(models.Model):
|
||||
if not fpos:
|
||||
# Fallback on catchall (no country, no group)
|
||||
fpos = self.search(base_domain + null_country_dom, limit=1)
|
||||
return fpos or False
|
||||
return fpos
|
||||
|
||||
@api.model
|
||||
def get_fiscal_position(self, partner_id, delivery_id=None):
|
||||
"""
|
||||
:return: fiscal position found (recordset)
|
||||
:rtype: :class:`account.fiscal.position`
|
||||
"""
|
||||
if not partner_id:
|
||||
return False
|
||||
return self.env['account.fiscal.position']
|
||||
|
||||
# This can be easily overridden to apply more complex fiscal rules
|
||||
PartnerObj = self.env['res.partner']
|
||||
partner = PartnerObj.browse(partner_id)
|
||||
@@ -165,7 +170,7 @@ class AccountFiscalPosition(models.Model):
|
||||
|
||||
# partner manually set fiscal position always win
|
||||
if delivery.property_account_position_id or partner.property_account_position_id:
|
||||
return delivery.property_account_position_id.id or partner.property_account_position_id.id
|
||||
return delivery.property_account_position_id or partner.property_account_position_id
|
||||
|
||||
# First search only matching VAT positions
|
||||
vat_required = bool(partner.vat)
|
||||
@@ -175,7 +180,7 @@ class AccountFiscalPosition(models.Model):
|
||||
if not fp and vat_required:
|
||||
fp = self._get_fpos_by_region(delivery.country_id.id, delivery.state_id.id, delivery.zip, False)
|
||||
|
||||
return fp.id if fp else False
|
||||
return fp or self.env['account.fiscal.position']
|
||||
|
||||
|
||||
class AccountFiscalPositionTax(models.Model):
|
||||
|
||||
@@ -21,7 +21,7 @@ class AccountFiscalPosition(models.Model):
|
||||
partner_id).l10n_ar_afip_responsibility_type_id.id),
|
||||
('company_id', '=', company.id),
|
||||
]
|
||||
return self.search(domain, limit=1).id
|
||||
return self.search(domain, limit=1)
|
||||
return super().get_fiscal_position(partner_id, delivery_id=delivery_id)
|
||||
|
||||
@api.onchange('l10n_ar_afip_responsibility_type_ids', 'country_group_id', 'country_id', 'zip_from', 'zip_to')
|
||||
|
||||
@@ -283,8 +283,7 @@ class Website(models.Model):
|
||||
country_code = request.session['geoip'].get('country_code')
|
||||
if country_code:
|
||||
country_id = request.env['res.country'].search([('code', '=', country_code)], limit=1).id
|
||||
fp_id = request.env['account.fiscal.position'].sudo().with_company(request.website.company_id.id)._get_fpos_by_region(country_id)
|
||||
sale_order.fiscal_position_id = fp_id
|
||||
sale_order.fiscal_position_id = request.env['account.fiscal.position'].sudo().with_company(request.website.company_id.id)._get_fpos_by_region(country_id)
|
||||
else:
|
||||
# if no geolocation, use the public user fp
|
||||
sale_order.onchange_partner_shipping_id()
|
||||
|
||||
Reference in New Issue
Block a user