Odoo Help


How to add an extra step in the webshop flow?

on 6/22/15, 10:50 AM 2,876 views

Hi guys,

I want to change the default behaviour from the webshop but I'm not entirely sure how to do this.
When the user clicks on 'shop' I want it to redirect to another page, where the user has to choose a value from the dropdown. After the users chooses an item from the dropdown and clicks on the submit button he should be send to the shop and should only see products that meet this criteria.

I've first made a controller that redirects:

 #Make a redirect first.
    @http.route(['/shop'], type='http', auth="public", website=True)
    def redirect(self, **post):
	return request.redirect("/shop/categoryselection")

Then I made a new controller for the new view like this:

 #Page that shows dropdown for all kind of finishing types
    @http.route(['/shop/categoryselection'], type='http', auth="public", website=True)
    def categoryselection(self, **post):
	cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
        order = request.website.sale_get_order()
	finishing_ids = pool['sale.order.finishing'].search(cr, uid, [('website_publish', '=', True)], context=context)
        afwerkingen = pool['sale.order.finishing'].browse(cr, uid, finishing_ids, context=context)
        values = dict(order=order, afwerkingen=afwerkingen)

        if post:
	    _logger.warning("in if post:")
            if post.get('afwerking'):
		_logger.warning("in if post.get")
                order.write({'afwerkingpicker': int(post.get('afwerking'))})
            return request.redirect("/shop")
        return request.website.render("website_sale.products", values)

The new page has the following XML to render it:

 <template id="categoryselection">
            <t t-call="website.layout">
              <div id="wrap">
                <div class="container oe_website_sale">
                  <h1 class="mb32">Kies een categorie</h1>
                  <div class="row">
                    <form method="post" class="">
                        <div class="row bg-info" style="padding:15px;margin-top:30px;border-radius:15px;">
                          <div class="form-inline form-group">
                            <label for="afwerking" class="h4">Type afwerking</label>
			    <br />
                            <select id="afwerking" name="afwerking" class="form-control">
                              <t t-foreach="afwerkingen" t-as="afwerking">
                                <option t-att-value='afwerking.id'>
                                  <span t-field="afwerking.name" />
			<input type="submit" class='btn btn-primary pull-right' value='Bevestigen'/>

 However this request.website.render gives me the following error:

 QWebException: "'NoneType' object is not callable" while evaluating
"keep('/shop'+ ('/category/'+slug(category)) if category else '', search=0)"

I'm not quite sure how I should fix this and then my second question is also.. how can I only show the products that meet the selected value from the dropdown? The selection is filled with data from the model sale.order.finishing and on my product view I made a Many2many that links to sale.order.finishing so that the user can choose which product belongs to which finishing.
The product view:

 <!-- Inherit product view and add Many2many -->
        <record id="product.product_template_only_form_view_inherit" model="ir.ui.view">
            <field name="name">product.template.product.inherit</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_only_form_view"/>
            <field name="arch" type="xml">
              <xpath expr="//field[@name='description']" position="before">
                  <field name="afwerkingpickerProduct"/>

and the python code behind this view:

 #Add many2many (for finishing on product) to product.template
class aa_houbolak_finishing_in_product_model(models.Model):
    _inherit = 'product.template'
    afwerkingpickerProduct = fields.Many2many('sale.order.finishing','product_finishing_rel','src_id_finishing','dest_id_finishing',string='Afwerking(en):')




| 6 5 7
Lodz, Poland

On 6/28/15, 4:56 PM

Probably your problem is related to rendering this template (from website_sale/view/templates.xml):

<template id="search" name="Search hidden fields">
<form t-att-action="keep('/shop'+ ('/category/'+slug(category)) if category else '', search=0)" method="get" t-att-class="search_class">


My sugestion, try to override (inherit)  /shop controller like this:

from openerp.addons.website_sale.controllers.main import website_sale
class Extension(website_sale):

], type='http', auth="public", website=True)

def shop(self, page=0, category=None, search='', **post):
### do_before() !!!
_logger.info('My SHOP')
return super(Extension, self).shop(page=page, category=category, search=search, **post)

Hi Zbik! Its indeed related to it but I honestly have no clue how I can redirect it correctly.. It seems to be missing some values or something. That is really the part where I'm stuck. Any ideas?

on 6/29/15, 2:03 AM

Why do not you start with site /shop/categoryselection, without redirection from /shop? In the current situation, you have a redirect loop... /shop -> /shop/categoryselection -> /shop ->....

on 6/29/15, 3:17 AM

or you need to change /shop route ...

Ahmed M.Elmubarak
on 6/29/15, 4:59 AM

@zbik I do start with /shop/selection, I simply redirect when the user clicks on shop (so on the controller I do request.redirect from /shop to /shop/categoryselection) and when the user is done there is a submit button. After clicking on this button the user should see all products that match the filter but I'm not sure how.. By the way you can see the full code here: https://github.com/Yenthe666/Dev/tree/master/aa_houbolak

on 6/30/15, 2:07 AM

Answer updated

on 6/30/15, 12:04 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 6/22/15, 10:50 AM
Seen: 2876 times
Last updated: 6/30/15, 12:05 PM