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 request.context = dict( request.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 product(self, product, category='', search='', **kwargs): product_context = dict(request.env.context, active_id=product.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 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 _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 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 = [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 = [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 = [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 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 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 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 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 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 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 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, }) 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) except (UserError, AccessError, ValidationError) as exc: validation_errors.append(ustr(exc)) except Exception: _logger.error("Error caught during request creation", exc_info=True) validation_errors.append( _("Unknown server error. See server logs.")) else: return request.render( "crnd_wsd.wsd_requests_new_congratulation", {'req': req.sudo()}) values['validation_errors'] = validation_errors # TODO: update values with posted values to save data entered by # user return request.render("crnd_wsd.wsd_requests_new_request_data", values)
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 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)
def partners_detail(self, seller_id, page=0, ppg=False, **post): _, seller_id = unslug(seller_id) if seller_id: if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG partner = request.env['res.partner'].sudo().browse(seller_id) if partner.exists(): url = "/shop" keep = QueryURL('/shop') Product = request.env['product.template'].with_context( bin_size=True) product_count = Product.search_count([ ('seller_id', '=', partner.id), ('website_published', '=', True) ]) pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) products = Product.search([('seller_id', '=', partner.id), ('website_published', '=', True)], limit=ppg, offset=pager['offset']) total_page = (len(partner.website_message_ids) / 10) + 1 values = { 'main_object': partner, 'partner': partner, 'edit_page': False, 'products': products, 'pager': pager, 'keep': keep, 'bins': TableCompute().process(products, ppg), 'rows': PPR, 'total_page': math.floor(total_page) } return request.render("odoo_website_marketplace.seller_page", values) return request.not_found()
def requests(self, req_status='my', page=0, search="", **post): if req_status not in ('my', 'open', 'closed', 'all'): return request.not_found() Request = request.env['request.request'] url = '/requests/' + req_status keep = QueryURL( url, [], search=search, **post) domains = self._requests_get_request_domains(search, **post) req_count = { 'all': Request.search_count(domains['all']), 'open': Request.search_count(domains['open']), 'closed': Request.search_count(domains['closed']), 'my': Request.search_count(domains['my']), } # make pager pager = request.website.pager( url=url, total=req_count[req_status], page=page, step=ITEMS_PER_PAGE, url_args=dict( post, search=search), ) # search the count to display, according to the pager data reqs = request.env['request.request'].search( domains[req_status], limit=ITEMS_PER_PAGE, offset=pager['offset']) values = { 'search': search, 'reqs': reqs.sudo(), 'pager': pager, 'default_url': url, 'req_status': req_status, 'req_count': req_count, 'keep': keep, 'get_redirect': get_redirect, } values.update(self._requests_list_get_extra_context( req_status=req_status, search=search, **post )) return request.render( 'crnd_wsd.wsd_requests', values)
def shop(self, page=0, category=None, search='', ppg=False, **post): # When user does a search in /shop the search input maintains # the value, so if you click on other category any product is listed. # This is a minor change that remove search keyword argument from keep # method. res = super(WebsiteSale, self).shop(page=page, category=category, search=search, ppg=ppg, **post) attrib_list = request.httprequest.args.getlist('attrib') keep = QueryURL('/shop', category=category and int(category), attrib=attrib_list, order=post.get('order')) res.qcontext['keep'] = keep return res
def blogs(self, page=1, **post): cr, uid, context = request.cr, request.uid, request.context blog_obj = request.registry['blog.post'] total = blog_obj.search(cr, uid, [], count=True, context=context) pager = request.website.pager( url='/blog', total=total, page=page, step=self._blog_post_per_page, ) post_ids = blog_obj.search(cr, uid, [], offset=(page-1)*self._blog_post_per_page, limit=self._blog_post_per_page, context=context) posts = blog_obj.browse(cr, uid, post_ids, context=context) blog_url = QueryURL('', ['blog', 'tag']) return request.website.render("website_blog.latest_blogs", { 'posts': posts, 'pager': pager, 'blog_url': blog_url, })
def render_product_carousel(self, domain=False, limit=12, products_per_slide=4, **kwargs): # Snippet options only allow a maximium of 24 records limit = min(limit, 24) _pricelist_context, pricelist = self._get_pricelist_context() # Used this way to follow Odoo implementation request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id) records = request.env["product.template"].search(domain or [], limit=limit) records_grouped = [] record_list = [] for index, record in enumerate(records, 1): record_list.append(record) if index % products_per_slide == 0: records_grouped.append(record_list) record_list = [] if any(record_list): records_grouped.append(record_list) template = "website_snippet_carousel_product.s_product_carousel_items" return request.website.viewref(template).render({ "objects": records_grouped, "keep": QueryURL("/shop"), "pager": request.website.pager(url="/shop", total=limit, scope=7, url_args=kwargs), "products_per_slide": products_per_slide, "num_slides": len(records_grouped), "uniqueId": "pc-%d" % int(time.time() * 1000), })
def single_property(self, record_property, **kw): property_root_url = QueryURL('/property-listing') property_type_url = '' article_ld_json = True print(record_property.ld_json_structure_date()) json_object = '<script type="application/ld+json">' + json.dumps( record_property.ld_json_structure_date()) + '</script>' locations = request.env['khmerrealty.property.location'].search([ ('parent_id', '=', False) ]) if record_property.property_category == 'buy': property_type_url = '/property/buy' elif record_property.property_category == 'rent': property_type_url = '/property/rent' return request.render( 'khmerrealty.single_property', { 'property': record_property, 'main_object': record_property, 'banners': http.request.env['khmerrealty.advertising'].search( [('show_in', '=', 'single_property')], limit=3), 'related_property': http.request.env['khmerrealty.property'].search( [('id', '!=', record_property.id), ('property_type', 'in', [record_property.property_type.id])], limit=4, order='id desc'), 'property_root_url': property_root_url, 'property_type_url': property_type_url, 'locations': locations, 'article_ld_json': article_ld_json, 'article_ld_json_script': json_object, })
def checkout(self, page=0, search='', ppg=False, **post): order = request.website.sale_get_order() redirection = self.checkout_redirection(order) if redirection: return redirection if order.partner_id.id == request.website.user_id.sudo().partner_id.id: return request.redirect('/shop/address') for f in self._get_mandatory_billing_fields(): if not order.partner_id[f]: return request.redirect('/shop/address?partner_id=%d' % order.partner_id.id) values = self.checkout_values(**post) address_count = self.count_address(values, search=search) if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG if search: post["search"] = search keep = QueryURL('/shop/checkout', search=search) pager = request.website.pager(url='/shop/checkout', total=address_count, page=page, step=ppg, scope=7, url_args=post) #_logger.info("Search %s:%s:%s:%s:%s" % (values, ppg, pager['offset'], search, post)) values.update(self.checkout_pager_values(values, search=search, limit=ppg, offset=pager['offset'])) values.update({ 'pager': pager, 'keep': keep, 'count': None, 'search': search }) _logger.info("POST %s:%s" % (post, order.partner_shipping_id)) # Avoid useless rendering if called in ajax if post.get('xhr'): return 'ok' return request.render("website_sale.checkout", values)
def render_mega_menu_qweb(self, template, category_id, domain=None, limit=None, order='published_date desc'): render = "" try: category = request.env['product.public.category'].search([ ("id", '=', category_id) ]) param = { 'keep': QueryURL('/shop/category/'), 'slug': slug, 'category': category, } render = request.render(template, param) except Exception as e: _logger.info("\n.....Exception .%r,.............", str(e)) return render
def _prepare_product_values(self, product, category, search, **kwargs): 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) ProductCategory = request.env['product.public.category'] if category: category = ProductCategory.sudo().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.sudo().search([('parent_id', '=', False)]) pricelist = request.website.get_current_pricelist() if not product_context.get('pricelist'): product_context['pricelist'] = pricelist.id product = product.with_context(product_context) # Needed to trigger the recently viewed product rpc view_track = request.website.viewref("website_sale.product").track return { 'search': search, 'category': category, 'pricelist': pricelist, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'keep': keep, 'categories': categs, 'main_object': product, 'product': product, 'add_qty': add_qty, 'view_track': view_track, }
def product(self, product, search='', **kwargs): product_context = dict(request.env.context, active_id=product.id, partner=request.env.user.partner_id) 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('/purchase', search=search, attrib=attrib_list) values = { 'search': search, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'keep': keep, 'main_object': product, 'product': product, 'get_attribute_value_ids': self.get_attribute_value_ids, } return request.render("purchase_request_website.product", values)
def wk_website_product_category(self, page=0, search='', **post): cr, context, pool = (request.cr, request.context, request.registry) domain = [] values={} if search: domain += ['|', ('name', 'ilike', search), ('category_description', 'ilike', search),] post['search'] =search url='/product/categories' keep = QueryURL('/product/categories', category_id=[]) count = request.env['product.public.category'].search_count( domain) pager = request.website.pager(url=url, total=count, page=page, step=PPG, scope=7, url_args=post) categories = request.env['product.public.category'].search( domain, limit=PPG, offset=pager['offset']) values.update ({'cat_rec': categories, 'bins': TableCompute().process(categories), 'rows': PPR, 'keep': keep, 'search': search, 'pager':pager, 'search_count': count}) return request.render('website_product_sorting_and_shopping.wk_website_shop_by_product_categories', values)
def _prepare_product_values(self, product, category, search, **kwargs): 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) 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() def compute_currency(price): return product.currency_id._convert(price, pricelist.currency_id, product._get_current_company(pricelist=pricelist, website=request.website), fields.Date.today()) if not product_context.get('pricelist'): product_context['pricelist'] = pricelist.id product = product.with_context(product_context) return { 'search': search, 'category': category, 'pricelist': pricelist, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'keep': keep, 'categories': categs, 'main_object': product, 'product': product, 'add_qty': add_qty, }
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 press(self, page=1, sortby=None, **post): # for sorting the latest press on top press_sortings = { 'date': {'label': _('Created Date'), 'order': 'create_date desc'}, 'name': {'label': _('Press Title'), 'order': 'name'}, } if not sortby: sortby = 'date' sort_order = press_sortings[sortby]['order'] # for pagination PressData = request.env['website.press'] total_press_data = PressData.search([], count=True) press_data = PressData.search([], limit=2) if len(press_data) == 1: return werkzeug.utils.redirect('/press/%s' % slug(press_data[0]), code=302) # calling pagination method pager = request.website.pager( url='/press', total=total_press_data, page=page, step=self._press_per_page, ) # limiting press post for each page press_posts = PressData.search([], order=sort_order, offset=(page - 1) * self._press_per_page, limit=self._press_per_page) press_url = QueryURL('', ['press']) # transferring values to template for rendering values = { 'press_posts': press_posts, 'pager': pager, 'press_url': press_url, } return http.request.render('website_press.press', values)