diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 87a6aac943a..49fce7c7d3d 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -156,8 +156,8 @@ class website(orm.Model): string='Price list available for this Ecommerce/Website'), } - @tools.ormcache('uid', 'country_code', 'show_visible', 'website_pl', 'current_pl', 'all_pl') - def _get_pl(self, cr, uid, country_code, show_visible, website_pl, current_pl, all_pl): + @tools.ormcache('uid', 'country_code', 'show_visible', 'website_pl', 'current_pl', 'all_pl', 'partner_pl', 'order_pl') + def _get_pl_partner_order(self, cr, uid, country_code, show_visible, website_pl, current_pl, all_pl, partner_pl=False, order_pl=False): """ Return the list of pricelists that can be used on website for the current user. :param str country_code: code iso or False, If set, we search only price list available for this country @@ -166,6 +166,8 @@ class website(orm.Model): :param int current_pl: The current pricelist used on the website (If not selectable but the current pricelist we had this pricelist anyway) :param list all_pl: List of all pricelist available for this website + :param int partner_pl: the partner pricelist + :param int order_pl: the current cart pricelist :returns: list of pricelist ids """ @@ -175,12 +177,12 @@ class website(orm.Model): groups = self.pool['res.country.group'].search(cr, uid, [('country_ids.code', '=', country_code)]) for cgroup in self.pool['res.country.group'].browse(cr, uid, groups): for pll in cgroup.website_pricelist_ids: - if not show_visible or pll.selectable or pll.pricelist_id.id == current_pl: + if not show_visible or pll.selectable or pll.pricelist_id.id in (current_pl, order_pl): pcs.append(pll.pricelist_id) if not pcs: # no pricelist for this country, or no GeoIP pcs = [pll.pricelist_id for pll in all_pl - if not show_visible or pll.selectable or pll.pricelist_id.id == current_pl] + if not show_visible or pll.selectable or pll.pricelist_id.id in (current_pl, order_pl)] partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid).partner_id if not pcs or partner.property_product_pricelist.id != website_pl: @@ -189,6 +191,10 @@ class website(orm.Model): pcs = sorted(set(pcs), key=lambda pl: pl.name) return [pl.id for pl in pcs] + @tools.ormcache('uid', 'country_code', 'show_visible', 'website_pl', 'current_pl', 'all_pl') + def _get_pl(self, cr, uid, country_code, show_visible, website_pl, current_pl, all_pl): + return self._get_pl_partner_order(cr, uid, country_code, show_visible, website_pl, current_pl, all_pl) + def get_pricelist_available(self, cr, uid, show_visible=False, context=None): """ Return the list of pricelists that can be used on website for the current user. Country restrictions will be detected with GeoIP (if installed). @@ -206,10 +212,15 @@ class website(orm.Model): website_id = self.search(cr, uid, [], context=context) website = self.browse(cr, uid, website_id, context=context) isocountry = request.session.geoip and request.session.geoip.get('country_code') or False - pl_ids = self._get_pl(cr, uid, isocountry, show_visible, - website.user_id.sudo().partner_id.property_product_pricelist.id, - request.session.get('website_sale_current_pl'), - website.website_pricelist_ids) + partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id + order_pl = partner.last_website_so_id and partner.last_website_so_id.state == 'draft' and partner.last_website_so_id.pricelist_id + partner_pl = partner.property_product_pricelist + pl_ids = self._get_pl_partner_order(cr, uid, isocountry, show_visible, + website.user_id.sudo().partner_id.property_product_pricelist.id, + request.session.get('website_sale_current_pl'), + website.website_pricelist_ids, + partner_pl=partner_pl and partner_pl.id or None, + order_pl=order_pl and order_pl.id or None) return self.pool['product.pricelist'].browse(cr, uid, pl_ids, context=context) def is_pricelist_available(self, cr, uid, pl_id, context=None): @@ -427,6 +438,7 @@ class website_pricelist(osv.Model): # we change the config of website price list to force to recompute. website = self.pool['website'] website._get_pl.clear_cache(website) + website._get_pl_partner_order.clear_cache(website) def create(self, cr, uid, data, context=None): res = super(website_pricelist, self).create(cr, uid, data, context=context)