'Return the current sale order after mofications specified by params.
:param bool force_create: Create sale order if not already existing
:param str code: Code to force a pricelist (promo code)
If empty, it\'s a special case to reset the pricelist with the first available else the default.
:param bool update_pricelist: Force to recompute all the lines from sale order to adapt the price with the current pricelist.
:param int force_pricelist: pricelist_id - if set,  we change the pricelist with this one
:returns: browse record for the current sale order'

@api.multi
def sale_get_order(self, force_create=False, code=None, update_pricelist=False, force_pricelist=False):

    self.ensure_one()
    partner = self.env.user.partner_id
    sale_order_id = request.session.get('sale_order_id')
    if (not sale_order_id):
        last_order = partner.last_website_so_id
        available_pricelists = self.get_pricelist_available()
        sale_order_id = ((last_order.state == 'draft') and (last_order.pricelist_id in available_pricelists) and last_order.id)
    pricelist_id = (request.session.get('website_sale_current_pl') or self.get_current_pricelist().id)
    if self.env['product.pricelist'].browse(force_pricelist).exists():
        pricelist_id = force_pricelist
        request.session['website_sale_current_pl'] = pricelist_id
        update_pricelist = True
    if (not self._context.get('pricelist')):
        self = self.with_context(pricelist=pricelist_id)
    sale_order = (self.env['sale.order'].sudo().browse(sale_order_id).exists() if sale_order_id else None)
    if ((not sale_order) and (force_create or code)):
        pricelist = self.env['product.pricelist'].browse(pricelist_id).sudo()
        so_data = self._prepare_sale_order_values(partner, pricelist)
        sale_order = self.env['sale.order'].sudo().create(so_data)
        if (request.website.partner_id.id != partner.id):
            sale_order.onchange_partner_shipping_id()
        else:
            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:
                sale_order.onchange_partner_shipping_id()
        request.session['sale_order_id'] = sale_order.id
        if (request.website.partner_id.id != partner.id):
            partner.write({'last_website_so_id': sale_order.id})
    if sale_order:
        if (not request.session.get('sale_order_id')):
            request.session['sale_order_id'] = sale_order.id
        pricelist_id = (pricelist_id or partner.property_product_pricelist.id)
        if ((sale_order.partner_id.id != partner.id) and (request.website.partner_id.id != partner.id)):
            flag_pricelist = False
            if (pricelist_id != sale_order.pricelist_id.id):
                flag_pricelist = True
            fiscal_position = sale_order.fiscal_position_id.id
            sale_order.write({'partner_id': partner.id})
            sale_order.onchange_partner_id()
            sale_order.onchange_partner_shipping_id()
            sale_order['payment_term_id'] = self.sale_get_payment_term(partner)
            values = {}
            if sale_order.pricelist_id:
                if (sale_order.pricelist_id.id != pricelist_id):
                    values['pricelist_id'] = pricelist_id
                    update_pricelist = True
            if sale_order.fiscal_position_id:
                sale_order._compute_tax_id()
            if values:
                sale_order.write(values)
            recent_fiscal_position = sale_order.fiscal_position_id.id
            if (flag_pricelist or (recent_fiscal_position != fiscal_position)):
                update_pricelist = True
        if (code and (code != sale_order.pricelist_id.code)):
            code_pricelist = self.env['product.pricelist'].sudo().search([('code', '=', code)], limit=1)
            if code_pricelist:
                pricelist_id = code_pricelist.id
                update_pricelist = True
        elif ((code is not None) and sale_order.pricelist_id.code):
            pricelist_id = partner.property_product_pricelist.id
            update_pricelist = True
        if update_pricelist:
            request.session['website_sale_current_pl'] = pricelist_id
            values = {'pricelist_id': pricelist_id}
            sale_order.write(values)
            for line in sale_order.order_line:
                if line.exists():
                    sale_order._cart_update(product_id=line.product_id.id, line_id=line.id, add_qty=0)
    else:
        request.session['sale_order_id'] = None
        return None
    return sale_order
