[FIX] website_sale: force recompute fiscal position

Fiscal position was setted by onchange before commit #55535a6
Now, we need to call the onchange_shipping_id to set the fiscal position.
In case where the owner of the sale order is the public user, instead to
use the fiscal position from public user, we try to guess it with the
geolocation.
This commit is contained in:
Jeremy Kersten
2016-08-04 16:04:57 +02:00
parent 027003df3d
commit f3e577da2f
+16
View File
@@ -10,6 +10,7 @@ import odoo.addons.decimal_precision as dp
_logger = logging.getLogger(__name__)
class SaleOrder(models.Model):
_inherit = "sale.order"
@@ -303,6 +304,20 @@ class Website(models.Model):
'partner_shipping_id': addr['delivery'],
'user_id': salesperson_id or self.salesperson_id.id,
})
# set fiscal position
if request.website.partner_id.id != partner.id:
sale_order.onchange_partner_shipping_id()
else: # For public user, fiscal position based on geolocation
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()._get_fpos_by_region(country_id)
sale_order.fiscal_position_id = fp_id
else:
# if no geolocation, use the public user fp
sale_order.onchange_partner_shipping_id()
request.session['sale_order_id'] = sale_order.id
if request.website.partner_id.id != partner.id:
@@ -323,6 +338,7 @@ class Website(models.Model):
# change the partner, and trigger the onchange
sale_order.write({'partner_id': partner.id})
sale_order.onchange_partner_id()
sale_order.onchange_partner_shipping_id() # fiscal position
# check the pricelist : update it if the pricelist is not the 'forced' one
values = {}