def product(self, product, category='', search='', **kwargs): ProductCategory = request.env['product.public.category'] if category: category = ProductCategory.browse(int(category)).exists() # For Attributes attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [ list(map(int, v.split("-"))) for v in attrib_list if v ] 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]) 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 = False 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 = False keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_list, brands=brand_list, tags=tag_list, price_min=price_min, price_max=price_max) res = super(WebsiteSaleExt, self).product(product=product, category=category, search=search, **kwargs) res.qcontext.update({ 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'tag_values': tag_values, 'tag_set': tag_set, 'brand_values': brand_values, 'brand_set': brand_set, 'keep': keep, 'price_min': price_min, 'price_max': price_max, }) return res
def custom_amp_view(self, product, category='', search='', **post): if request.website.is_amp_enable: ProductCategory = request.env['product.public.category'] if category: category = ProductCategory.browse(int(category)).exists() categs = ProductCategory.search([('parent_id', '=', False)]) 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/amp', category=category and category.id, search=search, attrib=attrib_list) values = { 'main_object': product, 'product': product, 'category': category, 'categories': categs, 'keep': keep, } return request.render("theme_scita.apm_product_view", values) else: raise NotFound()
def blogs(self, page=1, **post): Blog = request.env['blog.blog'] blogs = Blog.search([], limit=2) if len(blogs) == 1: return werkzeug.utils.redirect('/blog/%s' % slug(blogs[0]), code=302) BlogPost = request.env['blog.post'] total = BlogPost.search([], count=True) pager = request.website.pager( url='/blog', total=total, page=page, step=self._blog_post_per_page, ) posts = BlogPost.search([], offset=(page - 1) * self._blog_post_per_page, limit=self._blog_post_per_page) blog_url = QueryURL('', ['blog', 'tag']) return request.render("website_blog.latest_blogs", { 'posts': posts, 'pager': pager, 'blog_url': blog_url, })
def index(self, blog=None, tag=None, page=1, **opt): # Blog = request.env['blog.blog'] # blogs = Blog.search([], limit=3) BlogPost = request.env['blog.post'] # total = BlogPost.search([], count=True) # pager = request.website.pager( # url='/blog', # total=total, # page=page, # step=self._blog_post_per_page, # ) getIdNews = request.env['blog.tag'].search([( 'name','=', 'News' )],) posts = BlogPost.search([( 'tag_ids', '=',getIdNews.id )], offset=(page - 1) * self._blog_post_per_page, limit=self._blog_post_per_page) blog_url = QueryURL('', ['blog', 'tag']) return http.request.render('erpi_theme_company.catp_comp_home',{ 'posts': posts, # 'pager': pager, 'blog_url': blog_url, })
def _show_optional_products(self, **kwargs): ks_pid = kwargs.get("product_id") pricelist = request.website.get_current_pricelist() product = request.env['product.template'].browse(ks_pid) ProductCategory = request.env['product.public.category'] categs = ProductCategory.search([('parent_id', '=', False)]) add_qty = int(kwargs.get('add_qty', 1)) product_context = dict(request.env.context, quantity=add_qty, active_id=product.id, partner=request.env.user.partner_id) if not product_context.get('pricelist'): product_context['pricelist'] = pricelist.id product = product.with_context(product_context) keep = QueryURL('/shop', category=product.categ_id and product.categ_id.id, search=[], attrib=[]) values = { 'search': [], 'category': product.categ_id, 'pricelist': pricelist, 'attrib_values': [], # compute_currency deprecated, get from product 'compute_currency': request.website.get_current_pricelist().currency_id, 'attrib_set': (), 'keep': keep, 'image_url': "/web/image/product.template/"+str(product.id)+"/image", 'categories': product.categ_id, 'main_object': product, 'product': product, 'add_qty': add_qty, 'optional_product_ids': [p.with_context({'active_id': p.id}) for p in product.optional_product_ids], # get_attribute_exclusions deprecated, use product method # 'get_attribute_exclusions': self._get_attribute_exclusions, } return [request.env['ir.ui.view'].render_template("ks_theme_kinetik.product",values),len(values['optional_product_ids'])]
def request_new_select_type(self, type_id=None, category_id=None, **kwargs): keep = QueryURL('', [], type_id=type_id, category_id=category_id, **kwargs) req_type = self._id_to_record('request.type', type_id) req_category = self._id_to_record('request.category', category_id) if request.httprequest.method == 'POST' and req_type: return request.redirect(keep( '/requests/new/step/data', type_id=req_type.id, category_id=req_category.id, **kwargs)) public_types = self._request_new_get_public_types( type_id=type_id, category_id=req_category.id, **kwargs) if len(public_types) == 1 and not http.request.session.debug: return request.redirect(keep( '/requests/new/step/data', type_id=public_types.id, category_id=req_category.id, **kwargs)) values = { 'req_types': public_types, 'req_type_sel': req_type, 'req_category': req_category, 'keep': keep, 'get_redirect': get_redirect, } return request.render( "crnd_wsd.wsd_requests_new_select_type", values)
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,wk_brand=None, **post): response= super(WebsiteSale, self).shop(page, category, search,ppg,**post) if wk_brand: response.qcontext['wk_brand'] =wk_brand brand = request.httprequest.args.getlist('brand') if post and post.get('order'): products=response.qcontext['products'] products.sudo().update_wk_sales_data() if 'wk_sales_count' in post.get('order'): sales_products = products.sorted('wk_sales_count') p_data = sales_products.mapped(lambda p:(p.id,p.name,p.wk_sales_count)) sort_domain=[('fields_name','=','wk_sales_count'),('model_name','=','product.template')] sort=request.env['wk.sort.attribute'].search(sort_domain,limit=1) if sort.order!='desc': sales_products = sales_products[::-1] response.qcontext['products'] = sales_products order = self._get_search_order(post) response.qcontext['order'] =order keep = QueryURL('/shop', category=category and int(category), brand=brand, # wk_brand = wk_brand and wk_brand.id, search=search, attrib= request.httprequest.args.getlist('attrib'), attrib_brand=request.httprequest.args.getlist('attrib_brand'), order=post.get('order') ) response.qcontext['keep'] =keep return response
def request_new_select_category(self, category_id=None, **kwargs): keep = QueryURL('', [], category_id=category_id, **kwargs) req_category = self._id_to_record('request.category', category_id) if request.httprequest.method == 'POST' and req_category: return request.redirect( keep('/requests/new/step/type', category_id=req_category.id, **kwargs)) public_categories = self._request_new_get_public_categs( category_id=category_id, **kwargs).filtered(lambda r: self._request_new_get_public_types( category_id=r.id, **kwargs)) if len(public_categories) <= 1 and not http.request.debug: return request.redirect( keep('/requests/new/step/type', category_id=public_categories.id, **kwargs)) values = { 'req_categories': public_categories, 'req_category_sel': req_category, 'keep': keep, 'get_redirect': get_redirect, } return request.render("crnd_wsd.wsd_requests_new_select_category", values)
def index(self, **kw): request.env.cr.execute( "SELECT id FROM product_template where website_published = TRUE ORDER BY id desc" ) product_ids = request.env.cr.fetchall()[0:6] latest_ids = [] for product_id in product_ids: latest_ids.append(product_id[0]) latest_products = request.env['product.template'].browse(latest_ids) keep = QueryURL("/shop") 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) from_currency = request.env.user.company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: from_currency.compute( price, to_currency) return request.render( 'website.homepage', { 'latest_products': latest_products, 'keep': keep, 'compute_currency': compute_currency })
def _get_products_categories(self, parent_cat, current_cat, page, post): """ Retorna el listado de productos por subcategorias :param parent_cat: La categoria padre :param current_cat: La nueva subcategoria a mostrar :return: """ Category = request.env['product.public.category'] Product = request.env['product.template'].with_context(bin_size=True) category = Category.search([('id', '=', parent_cat)], order='sequence') child_id = category.child_id.ids # child_id.append(category.id) item_per_page = 15 offset = 0 url = "/shop" if category: url = "/shop/category/%s" % slug(category) if page == 0: page = 1 if page > 1: offset = item_per_page * page domain = [('public_categ_ids', 'in', child_id), ('website_id', '=', request.website.id), ('company_id', '=', request.website.company_id.id)] products = Product.search(domain, offset=offset, limit=item_per_page) products_count = Product.search_count(domain) pager = request.website.pager(url=url, total=products_count, page=page, step=item_per_page, scope=7, url_args=post) attrib_list = request.httprequest.args.getlist('attrib') keep = QueryURL('/shop', category=category and int(category), search='', attrib=attrib_list, order=post.get('order')) array = order_categories(child_id, current_cat) new_array = [] for index in array: current_category = category.child_id.filtered( lambda cat: cat.id == index) for item in products: if index in item.public_categ_ids.ids: item.color_category = current_category.color new_array.append(item) return {'products': new_array, 'keep': keep, 'pager': pager}
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 product(self, product, category='', search='', **kwargs): 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', 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) Attachment = request.env['ir.attachment'] product_id = product.id att = Attachment.search_read( domain=[('res_model', '=', product._name), ('res_id', '=', product_id), ('product_downloadable', '=', True)], fields=['name', 'write_date'], order='write_date desc', ) 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, 'digital_attachments': att, 'get_attribute_value_ids': self.get_attribute_value_ids, } return request.render("website_sale.product", values)
def shop(self, page=0, category=None, seedling_months=None, search="", ppg=False, **post): sm_mgr = request.env["seed.seedling.month"] if seedling_months == "now": # Get current month seedling_month_ids = sm_mgr.sudo().search([ ("sequence", "=", datetime.date.today().month) ]) else: # Split list of id for seedling months seedling_month_list = seedling_months_to_list(seedling_months) # Get existing seedling months seedling_month_ids = sm_mgr.sudo().browse(seedling_month_list) seedling_month_ids = seedling_month_ids.filtered( lambda r: r.exists()) seedling_months = seedling_months_to_str(seedling_month_ids) # Put seedling months in the context so that it is accessible by # other function of this controller. if seedling_month_ids: context = dict(request.env.context) context["seedling_month_ids"] = seedling_month_ids request.env.context = context # The parent does not take seedling_months as an argument. So we # give them in the post arg. This is needed for the pager to # work correctly. if seedling_months: post["seedling_months"] = str(seedling_months) response = super().shop(page, category, search, ppg, **post) # Build the new `keep` function to keep arguments in the URL attrib_list = request.httprequest.args.getlist("attrib") keep = QueryURL( "/shop", category=category and int(category), search=search, attrib=attrib_list, seedling_months=seedling_months and str(seedling_months), order=post.get("order"), ) # Add element to context response.qcontext["keep"] = keep response.qcontext["seedling_months"] = seedling_month_ids response.qcontext["all_seedling_months"] = sm_mgr.sudo().search([]) response.qcontext["sm_add2str"] = seedling_months_add_to_str response.qcontext["sm_del2str"] = seedling_months_del_to_str return response
def request_new_fill_data(self, type_id=None, category_id=None, req_text=None, **kwargs): req_type = self._id_to_record('request.type', type_id) if not req_type: return request.redirect( QueryURL('/requests/new/step/type', [])(type_id=type_id, category_id=category_id, **kwargs)) req_category = self._id_to_record('request.category', category_id) values = self._request_new_process_data(req_type, req_category, req_text=req_text, **kwargs) values.update({ 'get_redirect': get_redirect, }) values['validation_errors'] = {} if request.httprequest.method == 'POST': req_data = self._request_new_prepare_data(req_type, req_category, req_text, **kwargs) validation_errors = self._request_new_validate_data( req_type, req_category, req_text, req_data, **kwargs) if not validation_errors: try: req = request.env['request.request'].create(req_data) req._request_bind_attachments() except (UserError, AccessError, ValidationError) as exc: validation_errors.update( {'error': { 'error_text': ustr(exc) }}) except Exception: _logger.error("Error caught during request creation", exc_info=True) validation_errors.update({ 'error': { 'error_text': _("Unknown server error. See server logs.") } }) else: return request.render( "crnd_wsd.wsd_requests_new_congratulation", {'req': req.sudo()}) values['validation_errors'] = validation_errors values.update(req_data) return request.render("crnd_wsd.wsd_requests_new_request_data", values)
def render_product_category(self, template, **kwargs): categories = request.env["product.public.category"].search([ ("parent_id", "=", False), ("website_published", "=", True) ]) keep = QueryURL("/shop", category=0) return request.website.viewref(template).render({ "object": categories, "keep": keep })
def shop(self, page=0, category=None, search='', ppg=False,wk_price=None, **post): response= super(WebsiteSale, self).shop(page=page, category=category, search=search,wk_price=wk_price,ppg=ppg,**post) #Price Attribute ===================================================== brand =(post.get('brand') and post.get('brand')) or False attrib_prices = request.httprequest.args.getlist('attrib_price') price_set=[] 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)] response.qcontext['price_set']= list(set(price_set)) response.qcontext['price_rec']= request.env['wk.product.price'].search([]) response.qcontext['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') response.qcontext['set_leg_style'] = [int(x.encode('UTF8')) for x in att_leg_style] response.qcontext['leg_style'] = request.env['leg.style'].search([]) #Table Style Attribute ===================================================== att_table_style = request.httprequest.args.getlist('att_table_style') response.qcontext['set_table_style'] = [int(x.encode('UTF8')) for x in att_table_style] response.qcontext['table_style'] = request.env['table.style'].search([]) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG qcontext = dict(response.qcontext) attrib_list = request.httprequest.args.getlist('attrib') 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 search_count = len(qcontext.get('products')) print ">>>search_count",qcontext.get('search_count'), search_count pager = request.website.pager(url=url, total=qcontext.get('search_count'), page=page, step=ppg, scope=7, url_args=post) response.qcontext['pager'] = pager keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order'),attrib_price=attrib_prices) response.qcontext['keep'] = keep return response
def product(self, product, category='', search='', **kwargs): product_context = dict(request.env.context, active_id=product.id, partner=request.env.user.partner_id) ProductCategory = request.env['product.public.category'] Rating = request.env['rating.rating'] if category: category = ProductCategory.browse(int(category)).exists() 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]) keep = QueryURL('/shop', 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) # get the rating attached to a mail.message, and the rating stats of the product ratings = Rating.search([('message_id', 'in', product.website_message_ids.ids)]) rating_message_values = dict([(record.message_id.id, record.rating) for record in ratings]) rating_product = product.rating_get_stats([('website_published', '=', True)]) 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, 'rating_message_values': rating_message_values, 'rating_product': rating_product } return request.render("website_sale.product", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): # User values try: custom_min_price = float(post.get("min_price")) except (ValueError, TypeError): custom_min_price = None try: custom_max_price = float(post.get("max_price")) except (ValueError, TypeError): custom_max_price = None # Call Super with context if custom_max_price is not None and custom_min_price is not None: # Sanitize Values if custom_min_price > custom_max_price: custom_max_price, custom_min_price = custom_min_price, custom_max_price # FIXME: Using 'request.env.context' to avoid issues with other modules request.env.context = dict( request.env.context, price_vals=[custom_min_price, custom_max_price]) response = super().shop( page=page, category=category, search=search, ppg=ppg, **post ) # Search maximum price # Using pricelist in this way to follow Odoo implementation _pricelist_context, pricelist = self._get_pricelist_context() request.context = dict( request.context, pricelist=pricelist.id, partner=request.env.user.partner_id, price_vals=None) product_id = request.env['product.template'].with_context( prefetch_fields=False ).search( self._get_search_domain( search, category, response.qcontext.get('attrib_values')), order='list_price DESC', limit=1) max_price = product_id.list_price # Price Filter QWeb Values keep = QueryURL( '/shop', category=category and int(category), search=post.get('search'), attrib=post.get('atrib'), order=post.get('order'), min_price=custom_min_price, max_price=custom_max_price) response.qcontext.update({ "custom_min_price": custom_min_price, "custom_max_price": custom_max_price, "max_price": max_price, "keep": keep, }) return response
def product(self, product, category='', search='', **kwargs): product_context = dict(request.env.context, active_id=product.id, partner=request.env.user.gooderp_partner_id) ProductCategory = request.env['goods.class'] # Rating = request.env['rating.rating'] if category: category = ProductCategory.browse(int(category)).exists() 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]) keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_list) if not product_context.get('pricelist'): # product_context['pricelist'] = pricelist.id product = product.with_context(product_context) attribute_dict = {} for attribute in product.attribute_ids: for value in attribute.value_ids: if not attribute_dict.has_key(value.category_id.name): attribute_dict.update( {value.category_id.name: [value.value_id.name]}) else: if value.value_id.name in attribute_dict[ value.category_id.name]: continue else: attribute_dict[value.category_id.name].append( value.value_id.name) # 货币取当前登录用户公司对应的货币 for user in request.env['res.users'].browse(request.uid): currency = user.company_id.currency_id values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'keep': keep, 'main_object': product, 'product': product, 'get_attribute_value_ids': self.get_attribute_value_ids, 'currency': currency, 'attribute_dict': attribute_dict, } return request.render("good_shop.product", values)
def blog(self, blog=None, tag=None, page=1, **opt): Blog = request.env['blog.blog'] if blog and not blog.can_access_from_current_website(): raise werkzeug.exceptions.NotFound() blogs = Blog.search(request.website.website_domain(), order="create_date asc, id asc") if not blog and len(blogs) == 1: return werkzeug.utils.redirect('/blog/%s' % slug(blogs[0]), code=302) date_begin, date_end, state = opt.get('date_begin'), opt.get( 'date_end'), opt.get('state') values = self._prepare_blog_values(blogs=blogs, blog=blog, date_begin=date_begin, date_end=date_end, tags=tag, state=state, page=page) # in case of a redirection need by `_prepare_blog_values` we follow it if isinstance(values, werkzeug.wrappers.Response): return values if blog: values['main_object'] = blog values['edit_in_backend'] = True values['blog_url'] = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end) else: values['blog_url'] = QueryURL('/blog', ['tag'], date_begin=date_begin, date_end=date_end) return request.render("website_blog.blog_post_short", values)
def custom_get_brand_slider(self, **post): keep = QueryURL('/theme_scita/custom_get_brand_slider', brand_id=[]) if post.get('slider-type'): slider_header = request.env['brand.snippet.config'].sudo().search([ ('id', '=', int(post.get('slider-type'))) ]) values = { 'slider_header': slider_header, 'website_brands': slider_header.collections_brands } return request.render("theme_scita.custom_scita_brand_slider_view", values)
def get_brands_data(self, product_count, product_label): keep = QueryURL('/shop/get_it_brand', brand_id=[]) value = {'website_brands': False, 'brand_header': False, 'keep': keep} if product_count: brand_data = request.env['product.brands'].sudo().search( [('active', '=', True)], limit=int(product_count)) if brand_data: value['website_brands'] = brand_data if product_label: value['brand_header'] = product_label return value
def purchase(self, page=0, 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 = self._get_search_domain(search, attrib_values) keep = QueryURL('/purchase', search=search, attrib=attrib_list, order=post.get('order')) request.context = dict(request.context, partner=request.env.user.partner_id) url = "/purchase" if search: post["search"] = search if attrib_list: post['attrib'] = attrib_list 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.sudo().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, '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), 'rows': PPR, 'attributes': attributes, 'keep': keep, } return request.render("purchase_request_website.products", values)
def blog(self, blog=None, tag=None, page=1, **opt): if not blog.can_access_from_current_website(): raise werkzeug.exceptions.NotFound() date_begin, date_end, state = opt.get('date_begin'), opt.get('date_end'), opt.get('state') values = self._prepare_blog_values(blogs=blog, date_begin=date_begin, date_end=date_end, tags=tag, state=state, page=page) values.update({ 'blog_url': QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end), 'blog': blog, }) return request.render("website_blog.blog_post_short", values)
def product(self, product, category='', search='', **kwargs): if product.is_gunwerks_template: 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', 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, } return request.render("theme_gunwerks.new_product_page", values) else: return super(GunwerksWebsiteSale, self).product(product=product, category=category, search=search, **kwargs)
def display_racefields(self, **post): racefields = request.env['gogp.racefields'].sudo().search([ ('is_published', '=', True) ]) keep = QueryURL('/racefields/participants', category=False, search='', order='id') return request.render('goGP.website_racefields_menu', { 'racefields': racefields, 'keep': keep })
def product(self, product, category='', search='', **kwargs): if not product.can_access_from_current_website(): raise NotFound() 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', 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._convert( price, to_currency, request.env.user.company_id, fields.Date.today( )) 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, } return request.render("website_sale.product", values)
def blogs(self, page=1, tag=None, **post): Blog = request.env['blog.blog'] blogs = Blog.search(request.website.website_domain(), order="create_date asc, id asc") if len(blogs) == 1: return werkzeug.utils.redirect('/blog/%s' % slug(blogs[0]), code=302) date_begin, date_end = post.get('date_begin'), post.get('date_end') values = self._prepare_blog_values(blogs=blogs, date_begin=date_begin, date_end=date_end, tags=tag, page=page) values.update({ 'blog_url': QueryURL('/blog', ['tag'], date_begin=date_begin, date_end=date_end), }) return request.render("website_blog.blog_post_short", values)
def get_brand_slider(self, **post): keep = QueryURL('/king_pro/get_brand_slider', brand_id=[]) value = {'website_brands': False, 'brand_header': False, 'keep': keep} if post.get('product_count'): brand_data = request.env['product.brands'].sudo().search( [], limit=int(post.get('product_count'))) if brand_data: value['website_brands'] = brand_data if post.get('product_label'): value['brand_header'] = post.get('product_label') return request.render("kingfisher.kingfisher_brand_slider_view", value)