From f3e577da2f479d5d0b768bd6f217d5891c659915 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Thu, 4 Aug 2016 15:24:45 +0200 Subject: [PATCH] [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. --- addons/website_sale/models/sale_order.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index f04882bb902..37835fd8a11 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -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 = {}