def _get_pricelist_available(self, req, show_visible=False): """ Return the list of pricelists that can be used on website for the current user. Country restrictions will be detected with GeoIP (if installed). :param bool show_visible: if True, we don't display pricelist where selectable is False (Eg: Code promo) :returns: pricelist recordset """ website = ir_http.get_request_website() if not website: if self.env.context.get('website_id'): website = self.browse(self.env.context['website_id']) else: # In the weird case we are coming from the backend (https://github.com/flectra/flectra/issues/20245) website = len(self) == 1 and self or self.search([], limit=1) isocountry = req and req.session.geoip and req.session.geoip.get( 'country_code') or False partner = self.env.user.partner_id last_order_pl = partner.last_website_so_id.pricelist_id partner_pl = partner.property_product_pricelist pricelists = website._get_pl_partner_order( isocountry, show_visible, website.user_id.sudo().partner_id.property_product_pricelist.id, req and req.session.get('website_sale_current_pl') or None, website.pricelist_ids, partner_pl=partner_pl and partner_pl.id or None, order_pl=last_order_pl and last_order_pl.id or None) return self.env['product.pricelist'].browse(pricelists)
def _get_partner_pricelist_multi_filter_hook(self): res = super(ProductPricelist, self)._get_partner_pricelist_multi_filter_hook() website = ir_http.get_request_website() if website: res = res.filtered( lambda pl: pl._is_available_on_website(website.id)) return res
def _get_partner_pricelist_multi_search_domain_hook(self, company_id): domain = super( ProductPricelist, self)._get_partner_pricelist_multi_search_domain_hook(company_id) website = ir_http.get_request_website() if website: domain += self._get_website_pricelists_domain(website.id) return domain
def _get_partner_pricelist_multi(self, partner_ids, company_id=None): ''' If `property_product_pricelist` is read from website, we should use the website's company and not the user's one. Passing a `company_id` to super will avoid using the current user's company. ''' website = ir_http.get_request_website() if not company_id and website: company_id = website.company_id.id return super(ProductPricelist, self)._get_partner_pricelist_multi( partner_ids, company_id)
def _compute_cart_qty(self): website = ir_http.get_request_website() if not website: self.cart_qty = 0 return cart = website.sale_get_order() for product in self: product.cart_qty = sum( cart.order_line.filtered( lambda p: p.product_id.id == product.id).mapped( 'product_uom_qty')) if cart else 0
def _eval_context(self): res = super(IrRule, self)._eval_context() # We need is_frontend to avoid showing website's company items in backend # (that could be different than current company). We can't use # `get_current_website(falback=False)` as it could also return a website # in backend (if domain set & match).. is_frontend = ir_http.get_request_website() Website = self.env['website'] res['website'] = is_frontend and Website.get_current_website( ) or Website return res
def _compute_last_website_so_id(self): SaleOrder = self.env['sale.order'] for partner in self: is_public = any( u._is_public() for u in partner.with_context(active_test=False).user_ids) website = ir_http.get_request_website() if website and not is_public: partner.last_website_so_id = SaleOrder.search( [ ('partner_id', '=', partner.id), ('website_id', '=', website.id), ('state', '=', 'draft'), ], order='write_date desc', limit=1) else: partner.last_website_so_id = SaleOrder # Not in a website context or public User
def _post_processing_att(self, tagName, atts, options): if atts.get('data-no-post-process'): return atts atts = super(QWeb, self)._post_processing_att(tagName, atts, options) if tagName == 'img' and 'loading' not in atts: atts['loading'] = 'lazy' # default is auto if options.get('inherit_branding') or options.get('rendering_bundle') or \ options.get('edit_translations') or options.get('debug') or (request and request.session.debug): return atts website = ir_http.get_request_website() if not website and options.get('website_id'): website = self.env['website'].browse(options['website_id']) if not website: return atts name = self.URL_ATTRS.get(tagName) if request and name and name in atts: atts[name] = url_for(atts[name]) if not website.cdn_activated: return atts data_name = f'data-{name}' if name and (name in atts or data_name in atts): atts = OrderedDict(atts) if name in atts: atts[name] = website.get_cdn_url(atts[name]) if data_name in atts: atts[data_name] = website.get_cdn_url(atts[data_name]) if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: atts = OrderedDict(atts) atts['style'] = re_background_image.sub( lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts
def get_available(self): website = ir_http.get_request_website() if not website: return super().get_available() # Return the website-available ones in this case return request.website.language_ids.get_sorted()