diff options
| author | Jeremy Kersten <jke@odoo.com> | 2015-01-07 18:11:24 +0100 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2015-01-07 18:11:24 +0100 |
| commit | e5ac65de59f45f2d15ae6f6b840b02cac78afd03 (patch) | |
| tree | 142ddfd2d934061621029d3d675c5937c3a0f28a /addons/website_customer/controllers/main.py | |
| parent | d88c34d11e87857a799ecbb0062fe9309858413d (diff) | |
[IMP] website_customer: add tags on partners. That allows to sort/filter the customers on website. Old categories [res.partner.category] (named Tags in UI) was confusing with tags and have been renamed into Categories.
Diffstat (limited to 'addons/website_customer/controllers/main.py')
| -rw-r--r-- | addons/website_customer/controllers/main.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/addons/website_customer/controllers/main.py b/addons/website_customer/controllers/main.py index 793d6067fb7..2b874f722e3 100644 --- a/addons/website_customer/controllers/main.py +++ b/addons/website_customer/controllers/main.py @@ -7,6 +7,7 @@ from openerp.tools.translate import _ from openerp.addons.web.http import request import werkzeug.urls + class WebsiteCustomer(http.Controller): _references_per_page = 20 @@ -17,10 +18,17 @@ class WebsiteCustomer(http.Controller): '/customers/country/<country_name>-<int:country_id>', '/customers/country/<int:country_id>/page/<int:page>', '/customers/country/<country_name>-<int:country_id>/page/<int:page>', + '/customers/tag/<tag_id>', + '/customers/tag/<tag_id>/page/<int:page>', + '/customers/tag/<tag_id>/country/<int:country_id>', + '/customers/tag/<tag_id>/country/<country_name>-<int:country_id>', + '/customers/tag/<tag_id>/country/<int:country_id>/page/<int:page>', + '/customers/tag/<tag_id>/country/<country_name>-<int:country_id>/page/<int:page>', ], type='http', auth="public", website=True) - def customers(self, country_id=0, page=0, country_name='', **post): + def customers(self, country_id=0, page=0, country_name='', tag_id=0, **post): cr, uid, context = request.cr, request.uid, request.context country_obj = request.registry['res.country'] + tag_obj = request.registry['res.partner.tag'] partner_obj = request.registry['res.partner'] partner_name = post.get('search', '') @@ -32,6 +40,13 @@ class WebsiteCustomer(http.Controller): ('website_description', 'ilike', post.get("search")) ] + if tag_id: + try: + tag_id = int(tag_id.split("-")[-1]) + except: + tag_id = 0 + domain += [('tag_ids', 'in', tag_id)] + # group by country, based on customers found with the search(domain) countries = partner_obj.read_group( cr, openerp.SUPERUSER_ID, domain, ["id", "country_id"], @@ -49,6 +64,7 @@ class WebsiteCustomer(http.Controller): 'country_id': (country_id, country['name']) }) countries.sort(key=lambda d: d['country_id'][1]) + curr_country = country_obj.browse(cr, uid, country_id, context) countries.insert(0, { 'country_id_count': country_count, @@ -73,14 +89,22 @@ class WebsiteCustomer(http.Controller): google_map_partner_ids = ','.join(map(str, partner_ids)) partners = partner_obj.browse(request.cr, openerp.SUPERUSER_ID, partner_ids, request.context) + tag_obj = request.registry['res.partner.tag'] + tag_ids = tag_obj.get_tags_for_partners(cr, uid, partner_ids, context=context) + tags = tag_obj.browse(cr, uid, tag_ids, context=context) + tag = tag_id and tag_obj.browse(cr, uid, tag_id, context=context) or False + values = { 'countries': countries, 'current_country_id': country_id or 0, + 'current_country': country_id and curr_country or False, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'post': post, 'search_path': "?%s" % werkzeug.url_encode(post), + 'tag': tag, + 'tags': tags, } return request.website.render("website_customer.index", values) |
