def get_product_brand_slider(self, **post): value = {'header': False, 'brands': False} if post.get('label'): value['header'] = post.get('label') if post.get('brand-count'): brand_ids = request.env['product.brand'].search([('visible_slider', '=', True)]) if brand_ids: keep = QueryURL('/shop', brand_id=[]) value.update({'brands': brand_ids, 'keep': keep}) return request.render("alan_customize.brand_slider_content", value)
def product_brands(self, **post): b_obj = request.env['product.brand'] domain = [] if post.get('search'): domain += [('name', 'ilike', post.get('search'))] brand_rec = b_obj.search(domain) keep = QueryURL('/page/product_brands', brand_id=[]) values = {'brand_rec': brand_rec, 'keep': keep} if post.get('search'): values.update({'search': post.get('search')}) return request.render('website_sale_product_brand.product_brands', values)
def product_brands(self, **post): values = {} domain = [('active', '=', True), ('visible_slider', '=', True)] if post.get('search'): domain += [('name', 'ilike', post.get('search'))] brand_ids = request.env['product.brand'].search(domain) keep = QueryURL('/shop/brands', brand_id=[]) if brand_ids: values.update({'brands': brand_ids, 'keep': keep}) if post.get('search'): values.update({'search': post.get('search')}) return request.render('atharva_theme_general.product_brands', values)
def product_brands(self, **post): cr, context, pool = (request.cr, request.context, request.registry) b_obj = request.env['product.brand'] domain = [] if post.get('search'): domain += [('name', 'ilike', post.get('search'))] brand_ids = b_obj.search(domain) keep = QueryURL('/page/product_brands', brand_id=[]) values = {'brand_rec': brand_ids, 'keep': keep} if post.get('search'): values.update({'search': post.get('search')}) return request.render('alan_customize.product_brands', values)
def product_brands(self, **post): b_obj = request.env["product.brand"] domain = [] if post.get("search"): domain += [("name", "ilike", post.get("search"))] brand_rec = b_obj.sudo().search(domain) keep = QueryURL("/page/product_brands", brand_id=[]) values = {"brand_rec": brand_rec, "keep": keep} if post.get("search"): values.update({"search": post.get("search")}) return request.render("website_sale_product_brand.product_brands", values)
def product(self, product, package=None, category='', search='', **kwargs): _logger.info( "-------------------------------%r--------------------------------------", product) product_context = dict(request.env.context, active_id=product.id, partner=request.env.user.partner_id) ProductCategory = request.env['product.public.category'] if category: category = ProductCategory.browse(int(category)).exists() attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attrib_set = {v[1] for v in attrib_values} keep = QueryURL('/shop/test', package=package, category=category and category.id, search=search, attrib=attrib_list) categs = ProductCategory.search([('parent_id', '=', False)]) pricelist = request.website.get_current_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) if not product_context.get('pricelist'): product_context['pricelist'] = pricelist.id product = product.with_context(product_context) values = { 'search': search, 'category': category, 'pricelist': pricelist, 'attrib_values': attrib_values, 'compute_currency': compute_currency, 'attrib_set': attrib_set, 'keep': keep, 'categories': categs, 'main_object': product, 'product': product, 'get_attribute_value_ids': self.get_attribute_value_ids, } _logger.info("======================================================") return request.render("website_pathology.test_page", values)
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 shop(self, page=0, category=None, search='', ppg=False, **post): """Let the view know we only want wishlisted products.""" result = super(Wishlist, self).shop(page, category, search, ppg, **post) result.qcontext.update({ "wishlist_only": bool(post.get("wishlist_only")), "keep": QueryURL( "/shop", attrib=post.get("attrib", list()), category=category and int(category), search=search, wishlist_only=post.get("wishlist_only"), ), }) return result
def product_brands(self, **post): cr, context, pool = (request.cr, request.context, request.registry) b_obj = pool['product.brand'] domain = [] if post.get('search'): domain += [('name', 'ilike', post.get('search'))] brand_ids = b_obj.search(cr, SUPERUSER_ID, domain) brand_rec = b_obj.browse(cr, SUPERUSER_ID, brand_ids, context=context) keep = QueryURL('/page/product_brands', brand_id=[]) values = {'brand_rec': brand_rec, 'keep': keep} if post.get('search'): values.update({'search': post.get('search')}) return request.website.render( 'website_sale_product_brand.product_brands', values)
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 get_collection(self, url_handler, page=0, category=None, search='', ppg=False, **post): def _get_search_domain(search): domain = request.website.sudo().sale_product_domain() domain += [("id", "in", wk_collection.sudo().template_ids.ids)] 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'].sudo().browse( product_obj.ids) uid, env, context = request.uid, request.env, dict(request.env.context) url = "/collections/" + str(url_handler) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG wk_collection = request.env['website.collectional.page'].sudo().search( [("url_handler", '=', url_handler)]) 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(url, category=category and int(category), search=search, attrib=attrib_list) product_count = request.env["product.template"].sudo().search_count([ ('sale_ok', '=', True), ("id", "in", wk_collection.sudo().template_ids.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'].sudo().search( [('sale_ok', '=', True), ("id", "=", wk_collection.sudo().template_ids.ids)], limit=ppg, offset=pager['offset'], order='website_published desc, website_sequence desc') products = env['product.template'].sudo().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 = { 'collectional_obj': wk_collection, 'rows': PPR, 'bins': TableCompute().process( products if not search else _get_search_domain(search), ppg), 'products': products if not search else _get_search_domain(search), 'hide_pager': len(_get_search_domain(search)), 'pager': pager, "keep": keep, 'compute_currency': compute_currency, "pricelist": pricelist, } return request.render( "website_collectional_page.wk_collection_product_view_website_sale", values)
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 load_next_products(self, category='', loaded_products=0, search='', ppg=0, **post): if ppg: request.cr.execute( 'select min(list_price),max(list_price) from product_template where sale_ok=True and active=True and is_published=True' ) 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 custom_min_val = custom_max_val = 0 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)}) tag_list = request.httprequest.args.getlist('tags[]') tag_values = [[str(x) for x in v.split("-")] for v in tag_list if v] tag_ids = {v[0] for v in tag_values} tag_set = {v[1] for v in tag_values} brand_list = request.httprequest.args.getlist('brands[]') brand_values = [[str(x) for x in v.split("-")] for v in brand_list if v] brand_ids = {v[0] for v in brand_values} brand_set = {v[1] for v in brand_values} 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 post.get('brand'): 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)] 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')))] 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)] 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) products = Product.search(domain, limit=int(ppg), offset=int(loaded_products), order=self._get_search_order(post)) ProductAttribute = request.env['product.attribute'] tags = request.env['product.tag'].search([]) brands = request.env['product.brand'].search([]) 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, pricelist_context, pricelist = self._get_compute_currency_and_context( ) values = { 'compute_currency': compute_currency, 'pricelist': pricelist, 'add_more': True if request.website.shop_product_loader == 'infinite_loader' else False, 'products': products, 'keep': keep, 'tags': tags, 'brands': brands, 'list_view_active': (int(post.get('list_view_active')) if post.get('list_view_active') else False) } return request.render('alan_customize.newly_loaded_products', values) else: return None
def shop(self, page=0, category=None, search='', seller=None, **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry domain = request.website.sale_product_domain() 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) ] if category: domain += [('public_categ_ids', 'child_of', int(category))] if seller: domain += [('section_id', '=', int(seller))] 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, seller=seller and int(seller), attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse( context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(domain) if search: post["search"] = search if category: category = pool['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) product_ids = product_obj.search( domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') products = product_obj.browse(product_ids) style_obj = pool['product.style'] style_ids = style_obj.search([]) styles = style_obj.browse(style_ids) category_obj = pool['product.public.category'] category_ids = category_obj.search([('parent_id', '=', False)]) categs = category_obj.browse(category_ids) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search([]) attributes = attributes_obj.browse(attributes_ids) from_currency = pool.get('product.price.type')._get_field_currency( 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( from_currency, to_currency, price) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().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.website.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): website = request.website quantities_per_page = None 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) res.qcontext.update({ 'ppg': ppg, 'quantities_per_page': quantities_per_page }) if post.get('brand') or post.get('product_collection'): 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) if post.get('brand'): 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)] 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)] 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: 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, pricelist_context, pricelist = self._get_compute_currency_and_context( ) res.qcontext.update({ 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_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, 'product_collection': post.get('product_collection'), }) return res
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')
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 load_next_products(self, category='', loaded_products=0, search='', ppg=0, **post): if 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) brand_ids = [] if post.get('brand[]'): brand_list = request.httprequest.args.getlist('brand[]') brand_values = [[str(x) for x in v.rsplit("-", 1)] for v in brand_list if v] brand_ids = list(set([int(v[1]) for v in brand_values])) if len(brand_ids) > 0: domain += [('product_brand_id', 'in', brand_ids)] tag_ids = [] if post.get('tags[]'): tag_list = request.httprequest.args.getlist('tags[]') tag_values = [[str(x) for x in v.rsplit("-", 1)] for v in tag_list if v] tag_ids = list(set([int(v[1]) for v in tag_values])) if len(tag_ids) > 0: domain += [('tag_ids', 'in', tag_ids)] 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) 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_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) url = "/shop" if category: category = request.env['product.public.category'].browse( int(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=int(ppg), offset=int(loaded_products), 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) ]) brands = request.env['product.brand'].search([ ('active', '=', True), ('visible_slider', '=', True), ('product_ids', 'in', search_product.ids) ]) tags = request.env['product.tag'].search([ ('active', '=', True), ('product_ids', 'in', search_product.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) brands = request.env['product.brand'].search([ ('active', '=', True), ('visible_slider', '=', True) ]) tags = request.env['product.tag'].search([('active', '=', True) ]) 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 = { 'add_more': True if request.website.shop_product_loader == 'infinite_loader' else False, 'products': products, #'pager': pager, 'pricelist': pricelist, 'keep': keep, 'brands': brands, 'brand_set': brand_ids, 'tags': tags, 'tag_set': tag_ids, 'layout_mode': layout_mode, } return request.render( 'atharva_theme_general.newly_loaded_products', values) else: return None
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, **post): add_qty = int(post.get('add_qty', 1)) quantities_per_page = None quantities_per_page = request.env['product.qty_per_page'].search( [], order='sequence') 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 = quantities_per_page[0].name if quantities_per_page else 20 if not ppg: if quantities_per_page: ppg = quantities_per_page[0].name else: 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) brand_ids = [] if post.get('brand'): brand_list = request.httprequest.args.getlist('brand') brand_values = [[str(x) for x in v.rsplit("-", 1)] for v in brand_list if v] brand_ids = list(set([int(v[1]) for v in brand_values])) if len(brand_ids) > 0: domain += [('product_brand_id', 'in', brand_ids)] tag_ids = [] if post.get('tags'): tag_list = request.httprequest.args.getlist('tags') tag_values = [[str(x) for x in v.rsplit("-", 1)] for v in tag_list if v] tag_ids = list(set([int(v[1]) for v in tag_values])) if len(tag_ids) > 0: domain += [('tag_ids', 'in', tag_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)] 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 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=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)]) brands = request.env['product.brand'].search([ ('active', '=', True), ('visible_slider', '=', True), ('product_ids', 'in', search_product.ids) ]) tags = request.env['product.tag'].search([('active', '=', True), ('product_ids', 'in', search_product.ids)]) else: attributes = ProductAttribute.browse(attributes_ids) brands = request.env['product.brand'].search([ ('active', '=', True), ('visible_slider', '=', True) ]) tags = request.env['product.tag'].search([('active', '=', True)]) 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, 'brands': brands, 'brand_set': brand_ids, 'tags': tags, 'tag_set': tag_ids, 'categories': categs, 'attributes': attributes, 'keep': keep, 'search_categories_ids': search_categories.ids, 'layout_mode': layout_mode, 'quantities_per_page': quantities_per_page, 'add_more': True if request.website.shop_product_loader == 'infinite_loader' else False, } if category: values['main_object'] = category return request.render("website_sale.products", values)
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): 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 = 1000000000000000 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 Product = request.env['product.template'].with_context(bin_size=True) search_product = Product.search(domain, order=self._get_search_order(post)) 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) offset = pager['offset'] products = search_product[offset:offset + 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' 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, } 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 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 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): res = super(WebsiteSale, self).shop(page=page, category=category, search=search, ppg=ppg, **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 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} ProductAttribute = request.env['product.attribute'] filtered_attributes_ids = ProductAttribute.search([ ('id', 'in', list(attributes_ids)) ]) 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 = 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 Product = request.env['product.template'] Category = request.env['product.public.category'] if search: categories = Product.search(domain).mapped('public_categ_ids') categs = request.env['product.public.category'].filtered( lambda c: not c.parent_id) else: categs = Category.search([('parent_id', '=', False)] + request.website.website_domain()) 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)) if products: attributes = ProductAttribute.search([ '|', ('attribute_line_ids.product_tmpl_id', 'in', products.ids), ('attribute_line_desc_ids.product_tmpl_id', 'in', products.ids) ]) else: attributes = ProductAttribute.browse(attributes_ids) attributes = ProductAttribute.search([('id', 'in', attributes.ids), ('use_in_filter', '=', True), ('display_type', 'not in', ['text', 'textarea'])]) attr_value_dict, valid_attr_list = {}, [] if attributes: for each_attr in attributes: for each_val in each_attr.value_ids: attr_value_dict[each_val.id] = 0 temp_prod_list = Product.search(domain, limit=False, order=self._get_search_order(post)) if temp_prod_list: attrs_desc_line_rec = request.env[ 'product.attribute_desc.lines'].search([ ('product_tmpl_id', 'in', temp_prod_list.ids) ]) if attrs_desc_line_rec: for each_attrs_desc_line_rec in attrs_desc_line_rec: for each_vals_desc_line in each_attrs_desc_line_rec.value_ids: if each_vals_desc_line.id in attr_value_dict: attr_value_dict[each_vals_desc_line.id] += 1 attrs_line_rec = request.env[ 'product.template.attribute.line'].search([ ('product_tmpl_id', 'in', temp_prod_list.ids) ]) if attrs_line_rec: for each_attrs_line_rec in attrs_line_rec: for each_vals_line in each_attrs_line_rec.value_ids: if each_vals_line.id in attr_value_dict: attr_value_dict[each_vals_line.id] += 1 for each_attr in attributes: value_ids_count = 0 for each_val in each_attr.value_ids: if each_val.id in attr_value_dict and attr_value_dict[ each_val.id] > 0: value_ids_count += 1 if value_ids_count > 0: valid_attr_list.append(each_attr.id) attributes = ProductAttribute.search([('id', 'in', valid_attr_list)], order='sort_order, name') 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({ 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'filtered_attributes': filtered_attributes_ids, 'pager': pager, 'products': products, 'search_count': product_count, # common for all searchbox 'bins': TableCompute().process(products, ppg, ppr), 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'attr_value_prod_counts': attr_value_dict, }) return res
def repo(self, repo=None, search='', limit='100', refresh='', **post): Branch = request.env['runbot.branch'] Build = request.env['runbot.build'] Repo = request.env['runbot.repo'] count = lambda dom: Build.search_count(dom) repos = Repo.search([]) if not repo and repos: repo = repos[0] context = { 'repos': repos, 'repo': repo, 'host_stats': [], 'pending_total': count([('state', '=', 'pending')]), 'limit': limit, 'search': search, 'refresh': refresh, } build_ids = [] if repo: filters = { key: post.get(key, '1') for key in ['pending', 'testing', 'running', 'done'] } domain = [('repo_id', '=', repo.id)] domain += [('state', '!=', key) for key, value in filters.iteritems() if value == '0'] if search: domain += [ '|', '|', ('dest', 'ilike', search), ('subject', 'ilike', search), ('branch_id.branch_name', 'ilike', search) ] builds = Build.search(domain, limit=int(limit)) branch_ids, build_by_branch_ids = [], {} if builds: branch_query = """ SELECT br.id FROM runbot_branch br INNER JOIN runbot_build bu ON br.id=bu.branch_id WHERE bu.id IN %s ORDER BY bu.sequence DESC """ sticky_dom = [('repo_id', '=', repo.id), ('sticky', '=', True)] sticky_branch_ids = [] if search else Branch.search( sticky_dom).ids request.env.cr.execute(branch_query, (tuple(builds.ids), )) branch_ids = uniq_list( sticky_branch_ids + [br[0] for br in request.env.cr.fetchall()]) build_query = """ SELECT branch_id, max(case when br_bu.row = 1 then br_bu.build_id end), max(case when br_bu.row = 2 then br_bu.build_id end), max(case when br_bu.row = 3 then br_bu.build_id end), max(case when br_bu.row = 4 then br_bu.build_id end) FROM ( SELECT br.id AS branch_id, bu.id AS build_id, row_number() OVER (PARTITION BY branch_id) AS row FROM runbot_branch br INNER JOIN runbot_build bu ON br.id=bu.branch_id WHERE br.id in %s GROUP BY br.id, bu.id ORDER BY br.id, bu.id DESC ) AS br_bu WHERE row <= 4 GROUP BY br_bu.branch_id; """ request.env.cr.execute(build_query, (tuple(branch_ids), )) build_by_branch_ids = { rec[0]: [r for r in rec[1:] if r is not None] for rec in request.env.cr.fetchall() } branches = Branch.browse(branch_ids) build_ids = flatten(build_by_branch_ids.values()) build_dict = {build.id: build for build in Build.browse(build_ids)} def branch_info(branch): return { 'branch': branch, 'builds': [ self.build_info(build_dict[build_id]) for build_id in build_by_branch_ids[branch.id] ] } context.update({ 'branches': [branch_info(b) for b in branches], 'testing': count([('repo_id', '=', repo.id), ('state', '=', 'testing')]), 'running': count([('repo_id', '=', repo.id), ('state', '=', 'running')]), 'pending': count([('repo_id', '=', repo.id), ('state', '=', 'pending')]), 'qu': QueryURL('/runbot/repo/' + slug(repo), search=search, limit=limit, refresh=refresh, **filters), 'filters': filters, }) # consider host gone if no build in last 100 build_threshold = max(build_ids or [0]) - 100 for result in Build.read_group([('id', '>', build_threshold)], ['host'], ['host']): if result['host']: context['host_stats'].append({ 'host': result['host'], 'testing': count([('state', '=', 'testing'), ('host', '=', result['host'])]), 'running': count([('state', '=', 'running'), ('host', '=', result['host'])]), }) return request.render("runbot.repo", context)
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 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