def specials_product(self, ppg=False, **kw): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG Product = request.env['product.template'] Products = Product.search([('is_special', '=', True), ('website_published', '=', True)]) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: from_currency.compute( price, to_currency) values = { 'products': Products, 'bins': TableCompute().process(Products, ppg), 'compute_currency': compute_currency, 'pricelist': pricelist, } print '=------values0000------', values a = request.env.ref('custom_theme.featured_product').render(values) print '-a----------', a return a
def shop(self, page=0, category=None, search='', ppg=False, **post): res = super(WebsiteSaleReplace, self).shop(page, category, search, ppg, **post) if request.env.user.has_group('website.group_website_publisher'): # Editors will see all products, without replacements return res products = res.qcontext.get('products', {}) customer_products = self._get_customer_products(products) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG res.qcontext['products'] = customer_products res.qcontext['bins'] = TableCompute().process(customer_products, ppg) return res
def wk_website_product_brands(self,page=0, search='', **post): cr, context, pool = (request.cr, request.context, request.registry) domain = [] values={} if search: domain += ['|', '|', '|','|', ('name', 'ilike', search), ('description', 'ilike', search), ('products.name', 'ilike', search), ('products.description_sale', 'ilike', search), ('products.description', 'ilike', search), ] post['search'] =search url='/product/brands' keep = QueryURL('/product/brands', brand_id=[]) count = request.env['wk.product.brand'].search_count( domain) pager = request.website.pager(url=url, total=count, page=page, step=PPG, scope=7, url_args=post) brands = request.env['wk.product.brand'].search( domain,limit=PPG, offset=pager['offset']) values.update({ 'brand_rec': brands, 'bins': TableCompute().process(brands), 'rows': PPR, 'keep': keep, 'search': search, 'pager': pager, 'search_count': count}) return request.render('website_product_sorting_and_shopping.wk_website_shop_by_product_brands', values)
def shop(self, page=0, category=None, search='', ppg=False, **post): res = super(WebsiteSaleCategories, self).shop(page, category, search, ppg, **post) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_values = res.qcontext['attrib_values'] tag_set = res.qcontext['tag_set'] brand_set = res.qcontext['brand_set'] #???? price_min = res.qcontext['price_min'] price_max = res.qcontext['price_max'] domain = self._get_search_domain_ext(search, category, attrib_values, list(tag_set), list(brand_set), price_min, price_max) Product = request.env['product.template'] # FILTER PRODUCT WITH PUBLISHED PUBLIC CATEGORIES domain.append(('InPublishedCategory', '=', True)) url = "/shop" if category: category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) res.qcontext.update({ 'products': products, 'bins': TableCompute().process(products, ppg), 'search_count': product_count, 'pager': pager }) return res
def index(self, **kw): # prefetch all menus (it will prefetch website.page too) top_menu = request.website.menu_id homepage = request.website.homepage_id if homepage and (homepage.sudo().is_visible or request.env.user.has_group('base.group_user') ) and homepage.url != '/': return request.env['ir.http'].reroute(homepage.url) website_page = request.env['ir.http']._serve_page() if website_page: # return website_page url = "/" category = request.env['product.public.category'] pager = request.website.pager(url=url, total=12, page=0, step=12, scope=7, url_args={}) product_main = request.env['product.template'].sudo().search( [('is_published', '=', True), ('public_categ_ids.name', 'like', 'Feature product')], order="create_date desc", limit=12) if product_main: products = product_main else: products = request.env['product.template'].sudo().search( [('is_published', '=', True)], order="create_date desc", limit=12) keep = QueryURL('/shop', category=category and int(category), search='', attrib=[], order={}) values = { 'pager': pager, 'products': products, 'bins': TableCompute().process(products, 12, 6), 'ppg': 12, 'ppr': 6, 'keep': keep, } return request.render("home_product.home_products", values) else: first_menu = top_menu and top_menu.child_id and top_menu.child_id.filtered( lambda menu: menu.is_visible) if first_menu and first_menu[0].url not in ('/', '', '#') and \ (not (first_menu[0].url.startswith(('/?', '/#', ' ')))): return request.redirect(first_menu[0].url) raise request.not_found()
def load_mp_all_seller(self, page=0, search='', ppg=False, **post): if not ppg: ppg = request.env['website'].get_current_website().shop_ppg PPR = request.env['website'].get_current_website().shop_ppr if ppg: try: ppg = int(ppg) except ValueError: ppg = SPG post["ppg"] = ppg else: ppg = SPG domain = self._get_seller_search_domain(search) keep = QueryURL('/sellers/list', search=search) url = "/sellers/list" if search: post["search"] = search seller_obj = request.env['res.partner'] seller_count = seller_obj.sudo().search_count(domain) total_active_seller = seller_obj.sudo().search_count( self._get_seller_search_domain("")) pager = request.website.pager(url=url, total=seller_count, page=page, step=ppg, scope=7, url_args=post) seller_objs = seller_obj.sudo().search( domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) values = { 'search': search, 'pager': pager, 'seller_objs': seller_objs, 'search_count': seller_count, # common for all searchbox 'bins': TableCompute().process(seller_objs, ppg, PPR), 'ppg': ppg, 'ppr': PPR, 'rows': SPR, 'keep': keep, 'total_active_seller': total_active_seller, } return request.render("odoo_marketplace.sellers_list", values)
def search_product(self, **kw): domain = request.website.sale_product_domain() if kw.get('name'): domain += [('website_published', '=', True), '|', '|', '|', ('name', 'ilike', kw.get('name')), ('description', 'ilike', kw.get('name')), ('description_sale', 'ilike', kw.get('name')), ('product_variant_ids.default_code', 'ilike', kw.get('name'))] if kw.get('categories'): category_id = request.env['product.public.category'].sudo().search( [('name', '=', kw.get('categories'))], limit=1) if category_id: domain += [('public_categ_ids', 'child_of', int(category_id.id))] partner = request.env.user.partner_id values = {} category = request.env['product.public.category'].sudo().search([]) values.update({ 'category': category, }) product_template = request.env['product.template'].sudo() products = product_template.search(domain) if products: values.update({ 'bins': TableCompute().process(products, 10), 'search_products': products, 'rows': 4, 'partner_key': partner.res_affiliate_key, 'base_url': request.env['ir.config_parameter'].sudo().get_param( 'web.base.url') }) _logger.info("=======values====%r", values) return http.request.render('affiliate_management.product_link', values)
def Brand(self, brand=None, page=0, category=None, search='', ppg=False, **post): add_qty = int(post.get('add_qty', 1)) Category = request.env['product.public.category'] if category: category = Category.search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() else: category = Category if ppg: try: ppg = int(ppg) post['ppg'] = ppg except ValueError: ppg = False if not ppg: ppg = request.env['website'].get_current_website().shop_ppg or 20 ppr = request.env['website'].get_current_website().shop_ppr or 4 attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = WebsiteSale._get_search_domain(self, search, category, attrib_values) # Set the brand product if brand: domain += [('product_brand_ept_id.id', '=', brand.id)] else: domain += [('product_brand_ept_id', '!=', False)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context, pricelist = WebsiteSale._get_pricelist_context(self) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/brand" if brand: url = "/brand/%s" % slug(brand) if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list Product = request.env['product.template'].with_context(bin_size=True) search_product = Product.search(domain) website_domain = request.website.website_domain() categs_domain = [('parent_id', '=', False)] + website_domain if search: search_categories = Category.search( [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self categs_domain.append(('id', 'in', search_categories.ids)) else: search_categories = Category categs = Category.search(categs_domain) if category: url = "/shop/category/%s" % slug(category) product_count = len(search_product) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=WebsiteSale._get_search_order( self, post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([('product_tmpl_ids', 'in', search_product.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) layout_mode = request.session.get('website_sale_shop_layout_mode') if not layout_mode: if request.website.viewref( 'website_sale.products_list_view').active: layout_mode = 'list' else: layout_mode = 'grid' values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'ppg': ppg, 'ppr': ppr, 'categories': categs, 'attributes': attributes, 'keep': keep, 'search_categories_ids': search_categories.ids, 'layout_mode': layout_mode, 'brand': brand, 'is_brand_page': True } if category: values['main_object'] = category return request.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): """ Override shop function """ allowed_categories = allowed_products = '' partner = request.env.user.partner_id filter_type = partner.filter_type if filter_type == 'product_wise': allowed_products = partner.allowed_products if filter_type == 'category_wise': allowed_categories = partner.allowed_categories Category_available = [] Category = request.env['product.public.category'] for ids in allowed_categories: if not ids.parent_id.id in allowed_categories.ids: Category_available.append(ids.id) if filter_type == 'product_wise': categories = Category.search([('product_tmpl_ids', 'in', allowed_products.ids)]) for ids in categories: if not ids.parent_id.id in categories.ids: Category_available.append(ids.id) categ = Category.search([('id', 'in', Category_available)]) # supering shop*** if not allowed_products and not allowed_categories: return super(ProductVisibility, self).shop(page, category, search, ppg, **post) add_qty = int(post.get('add_qty', 1)) if category: category = Category.search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() else: category = Category if ppg: try: ppg = int(ppg) post['ppg'] = ppg except ValueError: ppg = False if not ppg: ppg = request.env['website'].get_current_website().shop_ppg or 20 ppr = request.env['website'].get_current_website().shop_ppr or 4 attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) Product = request.env['product.template'].with_context(bin_size=True) if allowed_products: domain_pro = self.search_domain(search, category, allowed_products, attrib_values) print(domain_pro) Product = Product.search(domain_pro) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context, pricelist = self._get_pricelist_context() request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list if not category: domain = self.search_domain(search, allowed_categories, allowed_products, attrib_values) search_product = Product.search(domain) website_domain = request.website.website_domain() categs_domain = [('parent_id', '=', False), ('product_tmpl_ids', 'in', search_product.ids)] + website_domain if search: search_categories = Category.search( [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self categs_domain.append(('id', 'in', search_categories.ids)) else: search_categories = allowed_categories if category: url = "/shop/category/%s" % slug(category) product_count = len(search_product) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) if allowed_products: products = Product.search(domain_pro, order=self._get_search_order(post)) else: products = Product.search(domain, order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([('product_tmpl_ids', 'in', search_product.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) layout_mode = request.session.get('website_sale_shop_layout_mode') if not layout_mode: if request.website.viewref('website_sale.products_list_view').active: layout_mode = 'list' else: layout_mode = 'grid' values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'ppg': ppg, 'ppr': ppr, 'categories': categ, 'attributes': attributes, 'keep': keep, 'search_categories_ids': categ.ids, 'layout_mode': layout_mode, } if category: values['main_object'] = category return request.render("website_sale.products", values)
def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post): # odoo11 # for displaying after whishlist or add to cart button n product_detail page if request.uid == 4: return request.render('web.login') if request.env.get('product.attribute.category') != None: compare_tmpl_obj = request.env.ref( 'website_sale_comparison.product_add_to_compare') if compare_tmpl_obj and compare_tmpl_obj.priority != 20: compare_tmpl_obj.sudo().write({'priority': 20}) if brand: req_ctx = request.context.copy() req_ctx.setdefault('brand_id', int(brand)) request.context = req_ctx result = super(KingfisherTheme, self).shop( page=page, category=category, brand=brand, search=search, **post) sort_order = "" cat_id = [] # For paging page_no = request.env['product.per.page.no'].sudo().search( [('set_default_check', '=', True)]) if page_no: ppg = page_no.name else: ppg = main_shop.PPG # product template object product_obj = request.env['product.template'] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [list(map(int, v.split("-"))) for v in attrib_list if v] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) domain = request.website.sale_product_domain() domain += self._get_search_domain(search, category, attrib_values) url = "/shop" keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) if post: request.session.update(post) if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list prevurl = request.httprequest.referrer if prevurl: if not re.search('/shop', prevurl, re.IGNORECASE): request.session['tag'] = "" request.session['sort_id'] = "" request.session['sortid'] = "" request.session['pricerange'] = "" request.session['min1'] = "" request.session['max1'] = "" request.session['curr_category'] = "" session = request.session cate_for_price = None # for category filter if category: cate_for_price = int(category) category = request.env['product.public.category'].sudo().browse( int(category)) url = "/shop/category/%s" % slug(category) if category != None: for ids in category: cat_id.append(ids.id) domain += ['|', ('public_categ_ids.id', 'in', cat_id), ('public_categ_ids.parent_id', 'in', cat_id)] # for tag filter if session.get('tag'): session_tag = session.get('tag')[0] tag = session_tag if tag: tag = request.env['biztech.product.tags'].sudo().browse( int(tag)) domain += [('biztech_tag_ids', '=', int(tag))] request.session["tag"] = [tag.id, tag.name] # For Product Sorting if session.get('sort_id'): session_sort = session.get('sort_id') sort = session_sort sort_field = request.env['biztech.product.sortby'].sudo().browse( int(sort)) request.session['product_sort_name'] = sort_field.name order_field = sort_field.sort_on.name order_type = sort_field.sort_type sort_order = '%s %s' % (order_field, order_type) if post.get("sort_id"): request.session["sortid"] = [ sort, sort_order, sort_field.name, order_type] # For Price slider is_price_slider = request.env.ref( 'kingfisher.kingfisher_slider_layout') if is_price_slider: is_discount_hide = True if request.website.get_current_pricelist( ).discount_policy == 'with_discount' else False product_slider_ids = [] asc_product_slider_obj = product_obj.search( domain, limit=1, order='list_price') desc_product_slider_obj = product_obj.search( domain, limit=1, order='list_price desc') if asc_product_slider_obj: # product_slider_ids.append(asc_product_slider_obj.website_price) product_slider_ids.append( asc_product_slider_obj.website_price if is_discount_hide else asc_product_slider_obj.list_price) if desc_product_slider_obj: # product_slider_ids.append(desc_product_slider_obj.website_price) product_slider_ids.append( desc_product_slider_obj.website_price if is_discount_hide else desc_product_slider_obj.list_price) if product_slider_ids: if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"): range1 = min(product_slider_ids) range2 = max(product_slider_ids) result.qcontext['range1'] = math.floor(range1) result.qcontext['range2'] = math.ceil(range2) if request.session.get('pricerange'): if cate_for_price and request.session.get('curr_category') and request.session.get('curr_category') != int(cate_for_price): request.session["min1"] = math.floor(range1) request.session["max1"] = math.ceil(range2) if session.get("min1") and session["min1"]: post["min1"] = session["min1"] if session.get("max1") and session["max1"]: post["max1"] = session["max1"] if range1: post["range1"] = range1 if range2: post["range2"] = range2 if range1 == range2: post['range1'] = 0.0 if request.session.get('min1') or request.session.get('max1'): if request.session.get('min1'): if request.session['min1'] != None: # domain += [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1'))] # ========== for hide list-website price diffrence ==================== if is_discount_hide: price_product_list = [] product_withprice = product_obj.search(domain) for prod_id in product_withprice: if prod_id.website_price >= float(request.session['min1']) and prod_id.website_price <= float(request.session['max1']): price_product_list.append(prod_id.id) if price_product_list: domain += [('id', 'in', price_product_list)] else: domain += [('id', 'in', [])] else: domain += [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1'))] # ============================== request.session["pricerange"] = str( request.session['min1'])+"-To-"+str(request.session['max1']) if session.get('min1') and session['min1']: result.qcontext['min1'] = session["min1"] result.qcontext['max1'] = session["max1"] if cate_for_price: request.session['curr_category'] = int(cate_for_price) if request.session.get('default_paging_no'): ppg = int(request.session.get('default_paging_no')) product_count = product_obj.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = product_obj.search( domain, limit=ppg, offset=pager['offset'], order=sort_order) result.qcontext.update({'product_count': product_count, 'products': products, 'category': category, 'pager': pager, 'keep': keep, 'search': search, 'bins': TableCompute().process(products, ppg)}) result.qcontext['brand'] = brand result.qcontext['domain'] = domain result.qcontext['brand_obj'] = request.env[ 'product.brands'].sudo().search([('id', '=', brand)]) return result
def shop(self, page=0, category=None, search='', ppg=False, **post): res = super(emiproThemeBaseExtended, self).shop(page=page, category=category, search=search, ppg=ppg, **post) cust_min_val = request.httprequest.values.get('min_val', False) cust_max_val = request.httprequest.values.get('max_val', False) attrib_list = request.httprequest.args.getlist('attrib') if cust_max_val and cust_min_val: try: tmp_cust_min_val = float(cust_min_val) tmp_cust_max_val = float(cust_max_val) if tmp_cust_min_val > tmp_cust_max_val: return request.redirect('/shop') except Exception as e: return request.redirect('/shop') if not post.get('filter_id', False): return res # If the filter found replace domain with the filter domain and render the shop with default functionality slider_filter = request.env['slider.filter'].sudo().search([('id', '=', int(post.get('filter_id')))]) if not slider_filter: return request.redirect("/shop") domain = safe_eval(slider_filter.filter_id.domain) if category: category = request.env['product.public.category'].search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context() request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list Product = request.env['product.template'] Category = request.env['product.public.category'] search_categories = False if search: categories = Product.search(domain).mapped('public_categ_ids') search_categories = Category.search( [('id', 'parent_of', categories.ids)] + request.website.website_domain()) categs = search_categories.filtered(lambda c: not c.parent_id) else: categs = Category.search([('parent_id', '=', False)] + request.website.website_domain()) parent_category_ids = [] if category: url = "/shop/category/%s" % slug(category) parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit selected_products = Product.search(domain, limit=False) attributes = ProductAttribute.search([('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'rows': PPR, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'search_categories_ids': search_categories and search_categories.ids, } if category: values['main_object'] = category return request.render("website_sale.products", values)
def SetTables(self, page=0, category=None, search='', wk_price=None, ppg=False, **post): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG if category: category = request.env['product.public.category'].search( [('id', '=', int(category))], limit=1) if not category: raise NotFound() attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop/dining/set/tables', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) #Price Attribute ===================================================== attrib_prices = request.httprequest.args.getlist('attrib_price') price_set = [] brand = (post.get('brand') and post.get('brand')) or False for attrib_price in attrib_prices: attrib_price_index = attrib_price.split('-')[0] if brand: if (brand != attrib_price_index): price_set += [int(attrib_price_index)] else: price_set += [int(attrib_price_index)] price_set = list(set(price_set)) price_rec = request.env['wk.product.price'].search([]) wk_price = request.env['wk.product.price'].browse(list(set(price_set))) #Leg Style Attribute ===================================================== att_leg_style = request.httprequest.args.getlist('att_leg_style') set_leg_style = [int(x.encode('UTF8')) for x in att_leg_style] leg_style = request.env['leg.style'].search([]) #Leg Style Attribute ===================================================== att_table_style = request.httprequest.args.getlist('att_table_style') set_table_style = [int(x.encode('UTF8')) for x in att_table_style] table_style = request.env['table.style'].search([]) url = "/shop/dining/set/tables" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list categs = request.env['product.public.category'].search([('parent_id', '=', False)]) Product = request.env['product.template'] domain += [('wk_type', '=', 'dts')] parent_category_ids = [] if category: url = "/shop/dining/set/tables/category/%s" % slug(category) parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit selected_products = Product.search(domain, limit=False) attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: from_currency.compute( price, to_currency) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'rows': PPR, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'wk_price': wk_price, 'price_rec': price_rec, 'price_set': price_set, 'set_leg_style': set_leg_style, 'leg_style': leg_style, 'set_table_style': set_table_style, 'table_style': table_style, } if category: values['main_object'] = category return request.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG # For Attributes attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [ list(map(int, v.split("-"))) for v in attrib_list if v ] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) # For Tags tag_list = request.httprequest.args.getlist('tags') tag_values = [list(map(str, v.split("-"))) for v in tag_list if v] tag_set = set([int(v[1]) for v in tag_values]) # For Brands brand_list = request.httprequest.args.getlist('brands') brand_values = [list(map(str, v.split("-"))) for v in brand_list if v] brand_set = set([int(v[1]) for v in brand_values]) Product = request.env['product.template'] # Price Filter Condition categ_products = None if category: categ_products = Product.search([('website_published', '=', True), ('public_categ_ids', 'child_of', int(category))]) if categ_products: products_price = [ product.website_price for product in categ_products ] products_price.sort() price_min_range = products_price and products_price[0] price_max_range = products_price and products_price[-1] if request.httprequest.args.getlist('price_min') \ and request.httprequest.args.getlist('price_min')[0] != '': price_min = float( request.httprequest.args.getlist('price_min')[0]) else: price_min = float(price_min_range) if request.httprequest.args.getlist('price_max') \ and request.httprequest.args.getlist('price_max')[0] != '': price_max = float( request.httprequest.args.getlist('price_max')[0]) else: price_max = float(price_max_range) else: price_max = price_min = price_min_range = price_max_range = 0.0 else: price_max = price_min = price_min_range = price_max_range = 0.0 domain = self._get_search_domain_ext(search, category, attrib_values, list(tag_set), list(brand_set)) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order'), brands=brand_list, tags=tag_list) url = "/shop" if category: category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list if tag_list: post['tags'] = tag_list if brand_list: post['brands'] = brand_list product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] ProductBrand = request.env['product.brand'] ProductTag = request.env['product.tags'] if products: attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', products.ids) ]) prod_brands = [] prod_tags = [] for product in products: if product.brand_id: prod_brands.append(product.brand_id.id) if product.tag_ids: for tag_id in product.tag_ids.ids: prod_tags.append(tag_id) brands = ProductBrand.browse(list(set(prod_brands))) tags = ProductTag.browse(list(set(prod_tags))) else: attributes = ProductAttribute.browse(attributes_ids) brands = ProductBrand.browse(brand_set) tags = ProductTag.browse(tag_set) limits = request.env['product.view.limit'].search([]) res = super(WebsiteSaleExt, self).shop(page=page, category=category, search=search, ppg=ppg, **post) res.qcontext.update({ 'pager': pager, 'products': products, 'tags': tags, 'brands': brands, 'bins': TableCompute().process(products, ppg), 'attributes': attributes, 'search_count': product_count, 'attrib_values': attrib_values, 'tag_values': tag_values, 'brand_values': brand_values, 'brand_set': brand_set, 'attrib_set': attrib_set, 'tag_set': tag_set, 'limits': limits, 'PPG': PPG, 'keep': keep, 'categ_products': categ_products, }) return res
def shop(self, page=0, category=None, search='', ppg=False, **post): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context( ) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if category: category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list categs = request.env['product.public.category'].search([ ('parent_id', '=', False), ('pathology', '=', False) ]) Product = request.env['product.template'] parent_category_ids = [] if category: parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit selected_products = Product.search(domain, limit=False) attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'rows': PPR, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, } if category: values['main_object'] = category return request.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): res = super(WebsiteSaleCustom, self).shop( page=page, category=category, search=search, ppg=ppg, **post) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [ [int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order'), version=post.get('version'), author=post.get('author')) if post.get('version'): domain += [('product_variant_ids.attribute_value_ids.id', '=', post.get('version'))] if post.get('author'): domain += [('product_variant_ids.app_author_ids.id', '=', post.get('author'))] url = "/shop" if category: category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) attribute_id = request.env.ref( 'apps_product_creator.attribute_odoo_version') category_all = request.env['product.public.category'].search([]) versions = request.env['product.attribute.value'].search([ ('attribute_id', '=', attribute_id.id)]) authors = request.env['odoo.author'].search([]) Product = request.env['product.template'] product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit selected_products = Product.search(domain, limit=False) attributes = ProductAttribute.search( [('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) res.qcontext.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'category_all': category_all, 'versions': versions, 'authors': authors, 'version': post.get('version'), 'author': post.get('author'), 'attributes': attributes, 'keep': keep, }) return res
def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post): add_more = False max_val = 0 min_val = 0 custom_min_val = custom_max_val = 0 website = request.website quantities_per_page = None if website.shop_product_loader == 'infinite_loader': add_more = True quantities_per_page = request.env['product.qty_per_page'].search( [], order='sequence') if ppg: try: ppg = int(ppg) except ValueError: ppg = quantities_per_page[ 0].name if quantities_per_page else PPG res = super(WebsiteSale, self).shop(page, category, search, ppg, **post) if 'ppg' in post: post["ppg"] = ppg else: ppg = quantities_per_page[0].name if quantities_per_page else PPG res = super(WebsiteSale, self).shop(page, category, search, ppg, **post) product_ids = request.env['product.template'].search( ['&', ('sale_ok', '=', True), ('active', '=', True)]) if product_ids and product_ids.ids: request.cr.execute( 'select min(list_price),max(list_price) from product_template where id in %s', (tuple(product_ids.ids), )) min_max_vals = request.cr.fetchall() min_val = min_max_vals[0][0] or 0 if int(min_val) == 0: min_val = 1 max_val = min_max_vals[0][1] or 1 if post.get('min_val') and post.get('max_val'): custom_min_val = float(post.get('min_val')) custom_max_val = float(post.get('max_val')) post.update({ 'attrib_price': '%s-%s' % (custom_min_val, custom_max_val) }) else: post.update({'attrib_price': '%s-%s' % (min_val, max_val)}) res.qcontext.update({ 'ppg': ppg, 'quantities_per_page': quantities_per_page, 'add_more': add_more, 'min_val': min_val, 'max_val': max_val, 'custom_min_val': custom_min_val, 'custom_max_val': custom_max_val, 'floor': math.floor, 'ceil': math.ceil }) if brand: brand = request.env['product.brand'].search( [('id', '=', int(brand))] + request.website.website_domain(), limit=1) if not brand: raise werkzeug.exceptions.NotFound() res.qcontext.update({'brand': brand}) brand_list = request.httprequest.args.getlist('brands') brand_values = [[str(x) for x in v.split("-")] for v in brand_list if v] brand_set = set([int(v[1]) for v in brand_values]) tag_list = request.httprequest.args.getlist('tags') tag_values = [[str(x) for x in v.split("-")] for v in tag_list if v] tag_set = set([int(v[1]) for v in tag_values]) # if brand or post.get('brand') or post.get('product_collection') or # (post.get('min_val') and post.get('max_val')): attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain_ext(search, category, attrib_values, list(tag_set), list(brand_set)) if brand: domain += [('product_brand_id', '=', brand.id)] if post.get('brand'): product_designer_obj = request.env['product.brand'] brand_ids = product_designer_obj.search( [('id', '=', int(post.get('brand')))] + request.website.website_domain()) if brand_ids: domain += [('product_brand_id', 'in', brand_ids.ids)] if post.get('product_collection'): prod_collection_rec = request.env['multitab.configure'].search([ ('id', '=', int(post.get('product_collection'))) ]) if prod_collection_rec: prod_id_list = list({ each_p.product_id.id for each_p in prod_collection_rec.product_ids }) domain += [('id', 'in', prod_id_list)] if post.get('min_val') and post.get('max_val'): domain += [('list_price', '>=', float(post.get('min_val'))), ('list_price', '<=', float(post.get('max_val')))] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order'), brands=brand_list, tags=tag_list) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if category: category = request.env['product.public.category'].search( [('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() else: url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list if tag_list: post['tags'] = tag_list if brand_list: post['brands'] = brand_list if brand: brand = request.env['product.brand'].browse(int(brand)) if not brand or not brand.can_access_from_current_website(): raise werkzeug.exceptions.NotFound() else: url = "/shop/brand/%s" % slug(brand) Product = request.env['product.template'] ProductPublicCategory = request.env['product.public.category'] selected_products = Product.search(domain, limit=False) search_categories = False if search: categories = selected_products.mapped('public_categ_ids') search_categories = ProductPublicCategory.search( [('id', 'parent_of', categories.ids)] + request.website.website_domain()) categs = search_categories.filtered(lambda c: not c.parent_id) else: categs = ProductPublicCategory.search( [('parent_id', '=', False)] + request.website.website_domain()) parent_category_ids = [] if category: parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] tags = request.env['product.tag'].search([]) brands = request.env['product.brand'].search([]) if selected_products: attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context( ) res.qcontext.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'brands': brands, 'brand_values': brand_values, 'brand_set': brand_set, 'tags': tags, 'tag_values': tag_values, 'tag_set': tag_set, 'pager': pager, 'products': products, 'search_count': product_count, 'bins': TableCompute().process(products, ppg), 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'search_categories_ids': search_categories and search_categories.ids, 'product_collection': post.get('product_collection'), }) return res
def seller(self, seller_id=None, page=0, category=None, search='', ppg=False, **post): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) domain = [('sale_ok', '=', True), ('wk_mp_membership', '=', True), ("website_published", "=", True)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse(pricelist_context['pricelist']) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if category: category = request.env['product.public.category'].browse(int(category)) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list categs = request.env['product.public.category'].search([('parent_id', '=', False)]) Product = request.env['product.template'] parent_category_ids = [] if category: parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset']) ProductAttribute = request.env['product.attribute'] if products: attributes = ProductAttribute.search([('attribute_line_ids.product_tmpl_id', 'in', products.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: from_currency.compute(price, to_currency) monthly_products = products.filtered(lambda x: x.duration_type == 'month' and x.plan_duration == 1) yearly_products = products.filtered(lambda x: x.duration_type == 'year' and x.plan_duration == 1) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(monthly_products, ppg), 'yearly_bins': TableCompute().process(yearly_products, ppg), 'rows': PPR, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, } if category: values['main_object'] = category return request.render("marketplace_membership.wk_mp_membership_plan", values)
def logistics_shop(self, page=0, category=None, search='', ppg=False, **post): add_qty = int(post.get('add_qty', 1)) if category: category = request.env['product.public.category'].search( [('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/logistics_shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context, pricelist = self._get_pricelist_context() request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/logistics_shop" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list Product = request.env['product.template'].with_context(bin_size=True) Category = request.env['product.public.category'] search_categories = False search_product = Product.search(domain) if search: categories = search_product.mapped('public_categ_ids') search_categories = Category.search( [('id', 'parent_of', categories.ids)] + request.website.website_domain()) categs = search_categories.filtered(lambda c: not c.parent_id) else: categs = Category.search([('parent_id', '=', False)] + request.website.website_domain()) parent_category_ids = [] if category: url = "/logistics_shop/category/%s" % slug(category) parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = len(search_product) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([ ('attribute_line_ids.value_ids', '!=', False), ('attribute_line_ids.product_tmpl_id', 'in', search_product.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) compute_currency = self._get_compute_currency(pricelist, products[:1]) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'rows': PPR, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'search_categories_ids': search_categories and search_categories.ids, } if category: values['main_object'] = category return request.render("website_logistics_shop.logistics_products", values)
def auctions_shop(self, page=0, category=None, search='', ppg=False, **post): add_qty = int(post.get('add_qty', 1)) Category = request.env['product.public.category'] if category: category = Category.search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website(): raise NotFound() else: category = Category if ppg: try: ppg = int(ppg) post['ppg'] = ppg except ValueError: ppg = False if not ppg: ppg = request.env['website'].get_current_website().shop_ppg or 20 ppr = request.env['website'].get_current_website().shop_ppr or 4 attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) auction_domain = get_auctions_domain(search, category) keep = QueryURL('/auctions', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context, pricelist = self._get_pricelist_context() request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/auctions" is_search = False if search: is_search = True post["search"] = search if attrib_list: post['attrib'] = attrib_list Product = request.env['product.template'].with_context(bin_size=True) Auction = request.env['auction'].with_context(bin_size=True) domain.append(['is_published', '=', True]) search_product = Product.search(domain, order=self._get_search_order(post)) auctions = Auction.search(auction_domain) website_domain = request.website.website_domain() categs_domain = [('parent_id', '=', False)] + website_domain if search: search_categories = Category.search( [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self categs_domain.append(('id', 'in', search_categories.ids)) else: search_categories = Category categs = Category.search(categs_domain) if category: url = "/auctions/category/%s" % slug(category) product_count = len(search_product) auctions_count = len(auctions) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) pager_auctions = request.website.pager(url=url, total=auctions_count, page=page, step=ppg, scope=7, url_args=post) offset = pager['offset'] offset_auctions = pager_auctions['offset'] products = search_product[offset:offset + ppg] auctions = auctions[offset_auctions:offset_auctions + ppg] ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([('product_tmpl_ids', 'in', search_product.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) layout_mode = request.session.get('website_sale_shop_layout_mode') if not layout_mode: if request.website.viewref( 'website_sale.products_list_view').active: layout_mode = 'list' else: layout_mode = 'grid' future_products = [] in_process_products = [] past_products = [] now = datetime.today() for product in products: try: start = datetime.strptime(str(product.auction_id.start_date), '%Y-%m-%d %H:%M:%S') end = datetime.strptime(str(product.auction_id.end_date), '%Y-%m-%d %H:%M:%S') if now < start: future_products.append(product) elif now < end: in_process_products.append(product) else: past_products.append(product) except: pass future_auctions = [] in_process_auctions = [] past_auctions = [] for auction in auctions: start = datetime.strptime(str(auction.start_date), '%Y-%m-%d %H:%M:%S') end = datetime.strptime(str(auction.end_date), '%Y-%m-%d %H:%M:%S') if now < start: future_auctions.append(auction) elif now < end: in_process_auctions.append(auction) else: past_auctions.append(auction) requested_url = request.httprequest.url if 'search' in requested_url: is_search = True if 'search' not in pager['page_next']['url']: for page in pager['pages']: page['url'] += '&search=' pager['page_next']['url'] += '&search=' pager['page_previous']['url'] += '&search=' values = { 'search': search, 'is_search': is_search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pager_auctions': pager_auctions, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'past_products': past_products, 'in_process_products': in_process_products, 'future_products': future_products, 'auctions': auctions, 'future_auctions': future_auctions, 'in_process_auctions': in_process_auctions, 'past_auctions': past_auctions, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'ppg': ppg, 'ppr': ppr, 'categories': categs, 'attributes': attributes, 'keep': keep, 'search_categories_ids': search_categories.ids, 'layout_mode': layout_mode, '_': _, } if category: values['main_object'] = category return request.render("auction_website.auctions", values)
def shop(self, page=0, category=None, search='', brand='', ppg=False, **post): """ Filter products by brand. """ response = super(WebsiteProductBrand, self).shop(page=page, category=category, search=search, ppg=ppg, **post) # execute below block if url contains brand parameter brand_obj = request.env['product.brand'] product_temp_obj = request.env['product.template'] brands_list = request.httprequest.args.getlist('brand') ppg, post = self.get_product_per_page(ppg, **post) domain, url = self.get_product_domain(search, category, post, response) if brands_list: brand = self.get_product_brands(brands_list) if brand: attrib_list = request.httprequest.args.getlist('attrib') try: brand_values = [ int(x) for x in request.httprequest.args.getlist('brand') ] except Exception as e: brand_values = [] product_brands = brand_obj.sudo().browse(brand_values).exists() post["brand"] = brands_list domain += [('product_brand_id', 'in', product_brands.ids)] product_count = product_temp_obj.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = product_temp_obj.search( domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) keep = QueryURL('/shop', category=category and int(category), search=search, brand=brands_list, attrib=attrib_list, order=post.get('order')) all_published_products = request.env[ 'product.template'].search([('website_published', '=', True)]) published_product_brands = self.get_product_brands( all_published_products.mapped('product_brand_id').ids) values = { 'products': products, 'bins': TableCompute().process(products, ppg), 'pager': pager, 'search_count': product_count, 'search': search, 'product_brands': published_product_brands, 'product_brand_set': set(brand_values), 'request_brands': brand, 'keep': keep, } response.qcontext.update(values) return response try: brand_list = [ int(x) for x in request.httprequest.args.getlist('brand') ] except Exception as e: brand_list = [] product_count = product_temp_obj.search_count(domain) pager1 = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = product_temp_obj.search(domain, limit=ppg, offset=pager1['offset'], order=self._get_search_order(post)) if products: product_brands = self.get_product_brands( products.mapped('product_brand_id').ids) else: product_brands = self.get_product_brands(brand_list) values = { 'product_brands': product_brands, 'product_brand_set': set(brand_list), 'search_count': len(products), } response.qcontext.update(values) return response
def shop(self, page=0, category=None, search='', ppg=False, **post): if ppg: try: ppg = int(ppg) post['ppg'] = ppg except ValueError: ppg = False if not ppg: ppg = request.env['website'].get_current_website().shop_ppg or 20 res = super(WebsiteSaleExt, self).shop(page=page, category=category, search=search, ppg=ppg, **post) # For Attributes attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} # For Brands brand_list = request.httprequest.args.getlist('brand-id') brand_values = [list(map(str, v.split("-"))) for v in brand_list if v] brand_set = set([int(v[1]) for v in brand_values]) Product = request.env['product.template'] domain = self._get_search_domain_ext(search, category, attrib_values, list(brand_set)) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order'), brands=brand_list) url = "/shop" if category: url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list if brand_list: post['brands'] = brand_list if search: post["search"] = search product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] ProductBrand = request.env['product.brand'] if products: selected_products = Product.search(domain, limit=False) attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids) ]) prod_brands = [] for product in selected_products: if product.product_brand_id: prod_brands.append(product.product_brand_id.id) brands = ProductBrand.browse(list(set(prod_brands))) else: attributes = ProductAttribute.browse(attributes_ids) brands = ProductBrand.browse(brand_set) res.qcontext.update({ 'pager': pager, 'products': products, 'brands': brands, 'bins': TableCompute().process(products, ppg), 'attributes': attributes, 'search_count': product_count, 'attrib_values': attrib_values, 'brand_values': brand_values, 'brand_set': brand_set, 'attrib_set': attrib_set, 'ppg': ppg, 'keep': keep, 'search': search, }) return res
def shop(self, page=0, category=None, search='', ppg=False, **post): res = super(WebsiteSale, self).shop(page, category, search, ppg, **post) if post.get('brand'): if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) domain = self._get_search_domain(search, category, attrib_values) product_designer_obj = request.env['product.brand'] brand_ids = product_designer_obj.search([('id', '=', int(post.get('brand')))]) if brand_ids: domain += [('product_brand_id', 'in', brand_ids.ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if category: category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list categs = request.env['product.public.category'].search([ ('parent_id', '=', False) ]) Product = request.env['product.template'] parent_category_ids = [] if category: parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: attributes = ProductAttribute.search([ ('attribute_line_ids.product_tmpl_id', 'in', products.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: from_currency.compute( price, to_currency) res.qcontext.update({ 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg), 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, }) else: return res return res
def shop(self, page=0, category=None, search='', ppg=False, **post): if request.env['website'].sudo().get_current_website( ).theme_id.name == 'theme_crafito': result = super(CrafitoEcommerceShop, self).shop(page=page, category=category, search=search, ppg=ppg, **post) add_qty = int(post.get('add_qty', 1)) Category = request.env['product.public.category'] if category: category = Category.search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website( ): raise NotFound() else: category = Category if ppg: try: ppg = int(ppg) post['ppg'] = ppg except ValueError: ppg = False if not ppg: ppg = request.env['website'].get_current_website( ).shop_ppg or 20 ppr = request.env['website'].get_current_website().shop_ppr or 4 attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context, pricelist = self._get_pricelist_context() request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) url = "/shop" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list if post: request.session.update(post) sort_order = self._get_search_order(post) Product = request.env['product.template'].with_context( bin_size=True) session = request.session cate_for_price = None # For Product Sorting if session.get('sort_id'): session_sort = session.get('sort_id') sort = session_sort sort_field = request.env['biztech.product.sortby'].sudo( ).search([('id', '=', int(sort))]) request.session['product_sort_name'] = sort_field.name order_field = sort_field.sort_on.name order_type = sort_field.sort_type sort_order = 'is_published desc, %s %s, id desc' % ( order_field, order_type) if post.get("sort_id"): request.session["sortid"] = [ sort, sort_order, sort_field.name, order_type ] is_price_slider = request.website.viewref( 'theme_crafito.product_price_slider') # if is_price_slider and is_price_slider.active: if is_price_slider: # For Price slider is_discount_hide = True if request.website.get_current_pricelist( ).discount_policy == 'with_discount' else False product_slider_ids = [] asc_product_slider_ids = Product.search(domain, limit=1, order='list_price') desc_product_slider_ids = Product.search( domain, limit=1, order='list_price desc') if asc_product_slider_ids: # product_slider_ids.append(asc_product_slider_ids.website_price) product_slider_ids.append( asc_product_slider_ids.price if is_discount_hide else asc_product_slider_ids.list_price) if desc_product_slider_ids: # product_slider_ids.append(desc_product_slider_ids.website_price) product_slider_ids.append( desc_product_slider_ids.price if is_discount_hide else desc_product_slider_ids.list_price) if product_slider_ids: if post.get("range1") or post.get( "range2" ) or not post.get("range1") or not post.get("range2"): range1 = min(product_slider_ids) range2 = max(product_slider_ids) result.qcontext['range1'] = math.floor(range1) result.qcontext['range2'] = math.ceil(range2) if request.session.get('pricerange'): if cate_for_price and request.session.get( 'curr_category') and request.session.get( 'curr_category') != int(cate_for_price): request.session["min1"] = math.floor(range1) request.session["max1"] = math.ceil(range2) if session.get("min1") and session["min1"]: post["min1"] = session["min1"] if session.get("max1") and session["max1"]: post["max1"] = session["max1"] if range1: post["range1"] = range1 if range2: post["range2"] = range2 if range1 == range2: post['range1'] = 0.0 if request.session.get('min1') or request.session.get( 'max1'): if request.session.get('min1'): if request.session['min1'] != None: # ========== for hide list-website price diffrence ==================== if is_discount_hide: price_product_list = [] product_withprice = Product.search(domain) for prod_id in product_withprice: if prod_id.price >= float( request.session['min1'] ) and prod_id.price <= float( request.session['max1']): price_product_list.append( prod_id.id) if price_product_list: domain += [('id', 'in', price_product_list)] else: domain += [('id', 'in', [])] else: domain += [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1'))] request.session["pricerange"] = str( request.session['min1']) + "-To-" + str( request.session['max1']) if session.get('min1') and session['min1']: result.qcontext['min1'] = session["min1"] result.qcontext['max1'] = session["max1"] if cate_for_price: request.session['curr_category'] = int(cate_for_price) Product = request.env['product.template'].with_context( bin_size=True) search_product = Product.search(domain) website_domain = request.website.website_domain() categs_domain = [('parent_id', '=', False)] + website_domain if search: search_categories = Category.search( [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self categs_domain.append(('id', 'in', search_categories.ids)) else: search_categories = Category categs = Category.search(categs_domain) if category: url = "/shop/category/%s" % slug(category) product_count = len(search_product) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=sort_order) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([ ('product_tmpl_ids', 'in', search_product.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) layout_mode = request.session.get('website_sale_shop_layout_mode') if not layout_mode: if request.website.viewref( 'website_sale.products_list_view').active: layout_mode = 'list' else: layout_mode = 'grid' result.qcontext.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'ppg': ppg, 'ppr': ppr, 'categories': categs, 'attributes': attributes, 'keep': keep, 'search_categories_ids': search_categories.ids, 'layout_mode': layout_mode, }) return result else: return super(CrafitoEcommerceShop, self).shop(page=page, category=category, search=search, ppg=ppg, **post)
def shop(self, page=0, category=None, search='', brand=None, **post): values = {} domain = request.website.sale_product_domain() if search: domain += [ '|', '|', '|', ('name', 'ilike', search), ('description', 'ilike', search), ('description_sale', 'ilike', search), ('product_variant_ids.default_code', 'ilike', search) ] if category: domain += [('public_categ_ids', 'child_of', int(category))] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split('-')) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) product_obj = request.env['product.template'] # Brand's product search if brand: values.update({'brand': brand}) product_designer_obj = request.env['product.brand'] brand_ids = product_designer_obj.search([('id', '=', int(brand))]) domain += [('product_brand_id', 'in', brand_ids.ids)] url = '/shop' product_count = product_obj.search_count(domain) if search: post['search'] = search if category: category = request.env['product.public.category'].\ browse(int(category)) url = '/shop/category/%s' % slug(category) pager = request.website.\ pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post) products = product_obj.\ search(domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') style_obj = request.env['product.style'] styles = style_obj.search([]) category_obj = request.env['product.public.category'] categories = category_obj.search([]) categs = filter(lambda x: not x.parent_id, categories) if category: selected_id = int(category) children_ids = category_obj.\ search([('parent_id', '=', selected_id)]) values.update({'child_list': children_ids}) attributes_obj = request.env['product.attribute'] attributes = attributes_obj.search([]) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = self.currency_compute(from_currency, to_currency) values.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': TableCompute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]) }) return request.render('website_sale.products', values)
def shop(self, page=0, category=None, search='', ppg=False, **post): result = super(CrafitoEcommerceShop, self).shop(page=page, category=category, search=search, **post) # odoo11 # for displaying after whishlist or add to cart button n product_detail page if request.env.get('product.attribute.category') != None: compare_tmpl_obj = request.env.ref( 'website_sale_comparison.product_add_to_compare') if compare_tmpl_obj and compare_tmpl_obj.priority != 20: compare_tmpl_obj.sudo().write({'priority': 20}) sort_order = "" cat_id = [] ppg = 18 product_temp = [] newproduct = [] # product template object product_obj = request.env['product.template'] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [ list(map(int, v.split("-"))) for v in attrib_list if v ] attributes_ids = set([v[0] for v in attrib_values]) attrib_set = set([v[1] for v in attrib_values]) domain = request.website.sale_product_domain() domain += self._get_search_domain(search, category, attrib_values) url = "/shop" if post: request.session.update(post) prevurl = request.httprequest.referrer if prevurl: if not re.search('/shop', prevurl, re.IGNORECASE): request.session['sortid'] = "" request.session['sort_id'] = "" request.session['pricerange'] = "" request.session['min1'] = "" request.session['max1'] = "" request.session['curr_category'] = "" session = request.session cate_for_price = None # for category filter if category: cate_for_price = int(category) category = request.env['product.public.category'].browse( int(category)) url = "/shop/category/%s" % slug(category) if category != None: for ids in category: cat_id.append(ids.id) domain += [ '|', ('public_categ_ids.id', 'in', cat_id), ('public_categ_ids.parent_id', 'in', cat_id) ] # For Product Sorting if session.get('sort_id'): session_sort = session.get('sort_id') sort = session_sort sort_field = request.env['biztech.product.sortby'].sudo().search([ ('id', '=', int(sort)) ]) request.session['product_sort_name'] = sort_field.name order_field = sort_field.sort_on.name order_type = sort_field.sort_type sort_order = '%s %s' % (order_field, order_type) if post.get("sort_id"): request.session["sortid"] = [ sort, sort_order, sort_field.name, order_type ] is_price_slider = request.env.ref('theme_crafito.product_price_slider') if is_price_slider and is_price_slider.active: # For Price slider is_discount_hide = True if request.website.get_current_pricelist( ).discount_policy == 'with_discount' else False product_slider_ids = [] asc_product_slider_ids = product_obj.search(domain, limit=1, order='list_price') desc_product_slider_ids = product_obj.search( domain, limit=1, order='list_price desc') if asc_product_slider_ids: # product_slider_ids.append(asc_product_slider_ids.website_price) product_slider_ids.append( asc_product_slider_ids.website_price if is_discount_hide else asc_product_slider_ids.list_price) if desc_product_slider_ids: # product_slider_ids.append(desc_product_slider_ids.website_price) product_slider_ids.append( desc_product_slider_ids.website_price if is_discount_hide else desc_product_slider_ids.list_price) if product_slider_ids: if post.get("range1") or post.get("range2") or not post.get( "range1") or not post.get("range2"): range1 = min(product_slider_ids) range2 = max(product_slider_ids) result.qcontext['range1'] = math.floor(range1) result.qcontext['range2'] = math.ceil(range2) if request.session.get('pricerange'): if cate_for_price and request.session.get( 'curr_category') and request.session.get( 'curr_category') != int(cate_for_price): request.session["min1"] = math.floor(range1) request.session["max1"] = math.ceil(range2) if session.get("min1") and session["min1"]: post["min1"] = session["min1"] if session.get("max1") and session["max1"]: post["max1"] = session["max1"] if range1: post["range1"] = range1 if range2: post["range2"] = range2 if range1 == range2: post['range1'] = 0.0 if request.session.get('min1') or request.session.get('max1'): if request.session.get('min1'): if request.session['min1'] != None: # ========== for hide list-website price diffrence ==================== if is_discount_hide: price_product_list = [] product_withprice = product_obj.search(domain) for prod_id in product_withprice: if prod_id.website_price >= float( request.session['min1'] ) and prod_id.website_price <= float( request.session['max1']): price_product_list.append(prod_id.id) if price_product_list: domain += [('id', 'in', price_product_list) ] else: domain += [('id', 'in', [])] else: domain += [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1'))] # ============================== request.session["pricerange"] = str( request.session['min1']) + "-To-" + str( request.session['max1']) if session.get('min1') and session['min1']: result.qcontext['min1'] = session["min1"] result.qcontext['max1'] = session["max1"] if cate_for_price: request.session['curr_category'] = int(cate_for_price) product_count = product_obj.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = product_obj.search(domain, limit=ppg, offset=pager['offset'], order=sort_order) result.qcontext.update({ 'search_count': product_count, 'products': products, 'category': category, 'pager': pager, 'bins': TableCompute().process(products, ppg) }) return result
def seller(self, seller_id=None, seller_url_handler=None, page=0, category=None, search='', ppg=False, **post): seller = url = False uid, context, env = request.uid, dict(request.env.context), request.env if seller_url_handler: seller = request.env["res.partner"].sudo().search( [("url_handler", "=", str(seller_url_handler))], limit=1) url = "/seller/profile/" + str(seller.url_handler) elif seller_id: seller = env['res.partner'].sudo().browse(seller_id) wk_name = seller.sudo().name.strip().replace(" ", "-") url = '/seller/profile/' + wk_name + '-' + str(seller.id) if not seller: return False if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG if not context.get('pricelist'): pricelist = request.website.get_current_pricelist() context['pricelist'] = int(pricelist) else: pricelist = env['product.pricelist'].sudo().browse( context['pricelist']) # Calculate seller total sales count sales_count = 0 all_products = request.env['product.template'].sudo().search([ ("marketplace_seller_id", "=", seller.sudo().id) ]) for prod in all_products: sales_count += prod.sales_count attrib_list = request.httprequest.args.getlist('attrib') url_for_keep = url keep = QueryURL(url_for_keep, category=category and int(category), search=search, attrib=attrib_list) seller_product_ids = request.env["product.template"].search([ ("marketplace_seller_id", "=", seller.id) ]) product_count = request.env["product.template"].sudo().search_count([ ('sale_ok', '=', True), ('status', '=', "approved"), ("website_published", "=", True), ("id", "in", seller_product_ids.ids) ]) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = env['product.template'].sudo().search( [('sale_ok', '=', True), ('status', '=', "approved"), ("website_published", "=", True), ("marketplace_seller_id", "=", seller.id)], limit=ppg, offset=pager['offset'], order='website_published desc, website_sequence desc') from_currency = env['res.users'].sudo().browse( uid).company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: env['res.currency'].sudo()._compute( from_currency, to_currency, price) values = { 'seller': seller, 'search': search, 'rows': PPR, 'bins': TableCompute().process(products, ppg), 'pager': pager, 'products': products, "keep": keep, 'compute_currency': compute_currency, "pricelist": pricelist, "sales_count": sales_count, "product_count": int(product_count), } return request.render("odoo_marketplace.mp_seller_profile", values)
def shopBrand(self, page=0, category=None, search='', brand=None, **post): values = {} domain = request.website.sale_product_domain() if search: domain += ['|', '|', '|', ('name', 'ilike', search), ('description', 'ilike', search), ('description_sale', 'ilike', search), ('product_variant_ids.default_code', 'ilike', search)] if category: domain += [('public_categ_ids', 'child_of', int(category))] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split('-')) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() pricelist_context['pricelist'] = pricelist.id else: pricelist = request.env['product.pricelist'].browse( pricelist_context['pricelist']) product_obj = request.env['product.template'] # Brand's product search if brand: values.update({'brand': brand}) product_designer_obj = request.env['product.brand'] brand_ids = product_designer_obj.search([('id', '=', int(brand))]) domain += [('product_brand_id', 'in', brand_ids.ids)] url = '/shop' product_count = product_obj.search_count(domain) if search: post['search'] = search if category: category = request.env['product.public.category']. \ browse(int(category)) url = '/shop/category/%s' % slug(category) pager = request.website. \ pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post) products = product_obj. \ search(domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') style_obj = request.env['product.style'] styles = style_obj.search([]) category_obj = request.env['product.public.category'] categories = category_obj.search([]) categs = filter(lambda x: not x.parent_id, categories) if category: selected_id = int(category) children_ids = category_obj. \ search([('parent_id', '=', selected_id)]) values.update({'child_list': children_ids}) attributes_obj = request.env['product.attribute'] attributes = attributes_obj.search([]) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = self.currency_compute(from_currency, to_currency) values.update({'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': TableCompute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [ s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode ([('attrib', i) for i in attribs])}) # ---------------------- CSTM ------------------------ productMaxMinDates = {} productProduct = request.env['product.product'].search([('product_tmpl_id', 'in', products.ids)]) for val in productProduct: val.env.cr.execute( "SELECT min(use_date), max (use_date) FROM public.stock_production_lot where product_id = %s", (val.id,)) query_result = val.env.cr.dictfetchone() productMaxMinDates[val.id] = {"min": fields.Datetime.from_string(query_result['min']), "max": fields.Datetime.from_string(query_result['max'])} values['productExpiration'] = productMaxMinDates; values['isVisibleWebsiteExpirationDate'] = request.env['ir.config_parameter'].sudo().get_param( 'website_sales.default_website_expiration_date') porductRows = [] porductRows.append([]) i = 1 for val in products: porductRows[-1].append(val) if i % 4 == 0: porductRows.append([]) i += 1 values['porductRows'] = porductRows return request.render('website_sale.products', values)
def seller_shop(self, shop_url_handler, page=0, category=None, search='', ppg=False, **post): shop_obj = request.env["seller.shop"].sudo().search( [("url_handler", "=", str(shop_url_handler))], limit=1) if not shop_obj: return False def _get_search_domain(search): domain = request.website.sale_product_domain() domain += [("marketplace_seller_id", "=", shop_obj.sudo().seller_id.id)] if search: for srch in search.split(" "): domain += [ '|', '|', '|', ('name', 'ilike', srch), ('description', 'ilike', srch), ('description_sale', 'ilike', srch), ('product_variant_ids.default_code', 'ilike', srch) ] product_obj = request.env['product.template'].sudo().search(domain) return request.env['product.template'].browse(product_obj.ids) uid, context, env = request.uid, dict(request.env.context), request.env url = "/seller/shop/" + str(shop_obj.url_handler) if search: post["search"] = search if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG if not context.get('pricelist'): pricelist = request.website.get_current_pricelist() context['pricelist'] = int(pricelist) else: pricelist = env['product.pricelist'].sudo().browse( context['pricelist']) # Calculate seller total sales count sales_count = 0 all_products = request.env['product.template'].sudo().search([ ("marketplace_seller_id", "=", shop_obj.sudo().seller_id.id) ]) for prod in all_products: sales_count += prod.sales_count attrib_list = request.httprequest.args.getlist('attrib') url_for_keep = '/seller/shop/' + str(shop_obj.url_handler) keep = QueryURL(url_for_keep, category=category and int(category), search=search, attrib=attrib_list) product_count = request.env["product.template"].sudo().search_count([ ('sale_ok', '=', True), ('status', '=', "approved"), ("website_published", "=", True), ("id", "in", shop_obj.sudo().seller_product_ids.ids) ]) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = env['product.template'].sudo().search( [('sale_ok', '=', True), ('status', '=', "approved"), ("website_published", "=", True), ("marketplace_seller_id", "=", shop_obj.sudo().seller_id.id)], limit=ppg, offset=pager['offset'], order='website_published desc, website_sequence desc') from_currency = env['res.users'].sudo().browse( uid).company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: env['res.currency'].sudo()._compute( from_currency, to_currency, price) shop_banner_url = request.website.image_url(shop_obj, 'shop_banner') values = { 'shop_obj': shop_obj, 'search': search, 'rows': PPR, 'bins': TableCompute().process( products if not search else _get_search_domain(search), ppg), 'pager': pager, 'products': products if not search else _get_search_domain(search), "keep": keep, 'compute_currency': compute_currency, "pricelist": pricelist, 'hide_pager': len(_get_search_domain(search)), 'shop_banner_url': shop_banner_url, "sales_count": sales_count, "product_count": int(product_count), } return request.render("odoo_marketplace.mp_seller_shop", values)
def shop(self, page=0, category=None, search='', ppg=False, brands=None, **post): if request.env['website'].sudo().get_current_website( ).theme_id.name == 'theme_scita': add_qty = int(post.get('add_qty', 1)) Category = request.env['product.public.category'] if category: category = Category.search([('id', '=', int(category))], limit=1) if not category or not category.can_access_from_current_website( ): raise NotFound() else: category = Category if brands: req_ctx = request.context.copy() req_ctx.setdefault('brand_id', int(brands)) request.context = req_ctx result = super(ScitaShop, self).shop(page=page, category=category, search=search, ppg=ppg, **post) page_no = request.env['product.per.page.no'].sudo().search([ ('set_default_check', '=', True) ]) if page_no: ppg = int(page_no.name) else: ppg = result.qcontext['ppg'] ppr = request.env['website'].get_current_website().shop_ppr or 4 attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values} attrib_set = {v[1] for v in attrib_values} domain = self._get_search_domain(search, category, attrib_values) url = "/shop" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list if post: request.session.update(post) Product = request.env['product.template'].with_context( bin_size=True) session = request.session cate_for_price = None search_product = Product.search(domain) website_domain = request.website.website_domain() pricelist_context, pricelist = self._get_pricelist_context() categs_domain = [('parent_id', '=', False)] + website_domain if search: search_categories = Category.search( [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self categs_domain.append(('id', 'in', search_categories.ids)) else: search_categories = Category categs = Category.search(categs_domain) if category: url = "/shop/category/%s" % slug(category) cate_for_price = int(category) prevurl = request.httprequest.referrer if prevurl: if not re.search('/shop', prevurl, re.IGNORECASE): request.session['pricerange'] = "" request.session['min1'] = "" request.session['max1'] = "" request.session['curr_category'] = "" brand_list = request.httprequest.args.getlist('brand') brand_set = set([int(v) for v in brand_list]) if brand_list: brandlistdomain = list(map(int, brand_list)) domain += [('product_brand_id', 'in', brandlistdomain)] bran = [] brand_obj = request.env['product.brands'].sudo().search([ ('id', 'in', brandlistdomain) ]) if brand_obj: for vals in brand_obj: if vals.name not in bran: bran.append((vals.name, vals.id)) if bran: request.session["brand_name"] = bran if not brand_list: request.session["brand_name"] = '' product_count = len(search_product) is_price_slider = request.website.viewref( 'theme_scita.scita_price_slider_layout').active if is_price_slider: # For Price slider is_discount_hide = True if request.website.get_current_pricelist( ).discount_policy == 'with_discount' or request.website.get_current_pricelist( ).discount_policy == 'without_discount' else False product_slider_ids = [] if is_discount_hide: price_list = Product.search(domain).mapped('price') if price_list: product_slider_ids.append(min(price_list)) product_slider_ids.append(max(price_list)) else: asc_product_slider_ids = Product.search(domain, limit=1, order='list_price') desc_product_slider_ids = Product.search( domain, limit=1, order='list_price desc') if asc_product_slider_ids: product_slider_ids.append( asc_product_slider_ids.price if is_discount_hide else asc_product_slider_ids.list_price) if desc_product_slider_ids: product_slider_ids.append( desc_product_slider_ids.price if is_discount_hide else desc_product_slider_ids.list_price) if product_slider_ids: if post.get("range1") or post.get( "range2" ) or not post.get("range1") or not post.get("range2"): range1 = min(product_slider_ids) range2 = max(product_slider_ids) result.qcontext['range1'] = math.floor(range1) result.qcontext['range2'] = math.ceil(range2) if request.session.get('pricerange'): if cate_for_price and request.session.get( 'curr_category') and request.session.get( 'curr_category') != float(cate_for_price): request.session["min1"] = math.floor(range1) request.session["max1"] = math.ceil(range2) if session.get("min1") and session["min1"]: post["min1"] = session["min1"] if session.get("max1") and session["max1"]: post["max1"] = session["max1"] if range1: post["range1"] = range1 if range2: post["range2"] = range2 if range1 == range2: post['range1'] = 0.0 if request.session.get('min1') or request.session.get( 'max1'): if is_discount_hide: price_product_list = [] product_withprice = Product.search(domain) for prod_id in product_withprice: if prod_id.price >= float( request.session['min1'] ) and prod_id.price <= float( request.session['max1']): price_product_list.append(prod_id.id) if price_product_list: domain += [('id', 'in', price_product_list)] else: domain += [('id', 'in', [])] else: domain += [('list_price', '>=', float(request.session.get('min1'))), ('list_price', '<=', float(request.session.get('max1')))] request.session["pricerange"] = str( request.session['min1']) + "-To-" + str( request.session['max1']) if session.get('min1') and session['min1']: result.qcontext['min1'] = session["min1"] result.qcontext['max1'] = session["max1"] if cate_for_price: request.session['curr_category'] = float(cate_for_price) if request.session.get('default_paging_no'): ppg = int(request.session.get('default_paging_no')) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) product_count = Product.search_count(domain) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] if products: # get all products without limit attributes = ProductAttribute.search([ ('product_tmpl_ids', 'in', search_product.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) layout_mode = request.session.get('website_sale_shop_layout_mode') if not layout_mode: if request.website.viewref( 'website_sale.products_list_view').active: layout_mode = 'list' else: layout_mode = 'grid' result.qcontext.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'add_qty': add_qty, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'ppg': ppg, 'ppr': ppr, 'categories': categs, 'attributes': attributes, 'keep': keep, 'search_categories_ids': search_categories.ids, 'layout_mode': layout_mode, 'brand_set': brand_set, }) return result else: return super(ScitaShop, self).shop(page=page, category=category, search=search, ppg=ppg, **post)
def seller_shop_recently_product(self, shop_id, page=0, category=None, search='', ppg=False, **post): uid, context, env = request.uid, dict(request.env.context), request.env url = "/seller/shop/" + str(shop_id) shop_obj = env["seller.shop"].sudo().browse(shop_id) recently_product = request.website.mp_recently_product page = 0 category = None search = '' ppg = False if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG if not context.get('pricelist'): pricelist = request.website.get_current_pricelist() context['pricelist'] = int(pricelist) else: pricelist = env['product.pricelist'].sudo().browse( context['pricelist']) attrib_list = request.httprequest.args.getlist('attrib') keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) recently_product_obj = request.env['product.template'].search( [('sale_ok', '=', True), ('status', '=', "approved"), ("website_published", "=", True), ("marketplace_seller_id", "=", shop_obj.seller_id.id)], order= 'create_date desc, website_published desc, website_sequence desc', limit=recently_product) product_count = len(recently_product_obj.ids) pager = request.website.pager(url=url, total=product_count, page=page, step=20, scope=7, url_args=post) product_ids = request.env['product.template'].search( [("id", "in", recently_product_obj.ids)], limit=ppg, offset=pager['offset'], order='website_published desc, website_sequence desc') products = env['product.template'].browse(product_ids.ids) from_currency = env['res.users'].sudo().browse( uid).company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: env['res.currency'].sudo()._compute( from_currency, to_currency, price) values = { 'rows': PPR, 'bins': TableCompute().process(products, ppg), 'pager': pager, 'products': products, "keep": keep, 'compute_currency': compute_currency, "pricelist": pricelist, 'shop_obj': shop_obj, } return request.env.ref( 'odoo_marketplace.shop_recently_product').render(values, engine='ir.qweb')