2013-10-08 08:39:56 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import openerp
|
2014-05-14 22:43:38 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2013-10-08 08:39:56 +00:00
|
|
|
from openerp.addons.web import http
|
2014-06-30 16:29:20 +00:00
|
|
|
from openerp.addons.website.models.website import unslug
|
2013-10-08 08:39:56 +00:00
|
|
|
from openerp.tools.translate import _
|
|
|
|
from openerp.addons.web.http import request
|
2014-01-29 12:13:16 +00:00
|
|
|
import werkzeug.urls
|
2013-10-08 08:39:56 +00:00
|
|
|
|
|
|
|
class WebsiteCustomer(http.Controller):
|
|
|
|
_references_per_page = 20
|
|
|
|
|
2014-01-20 15:37:33 +00:00
|
|
|
@http.route([
|
2014-03-14 16:23:46 +00:00
|
|
|
'/customers',
|
|
|
|
'/customers/page/<int:page>',
|
2014-01-07 13:59:33 +00:00
|
|
|
'/customers/country/<int:country_id>',
|
|
|
|
'/customers/country/<country_name>-<int:country_id>',
|
2014-03-14 16:23:46 +00:00
|
|
|
'/customers/country/<int:country_id>/page/<int:page>',
|
|
|
|
'/customers/country/<country_name>-<int:country_id>/page/<int:page>',
|
2014-01-20 15:37:33 +00:00
|
|
|
], type='http', auth="public", website=True, multilang=True)
|
2014-05-12 17:51:21 +00:00
|
|
|
def customers(self, country_id=0, page=0, country_name='', **post):
|
2013-10-08 08:39:56 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-01-30 19:37:06 +00:00
|
|
|
country_obj = request.registry['res.country']
|
2013-10-08 08:39:56 +00:00
|
|
|
partner_obj = request.registry['res.partner']
|
|
|
|
partner_name = post.get('search', '')
|
|
|
|
|
2014-05-12 17:51:21 +00:00
|
|
|
domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)]
|
2013-10-08 08:39:56 +00:00
|
|
|
if partner_name:
|
2013-10-08 15:21:33 +00:00
|
|
|
domain += [
|
2013-10-08 08:39:56 +00:00
|
|
|
'|',
|
2014-01-29 16:35:57 +00:00
|
|
|
('name', 'ilike', post.get("search")),
|
|
|
|
('website_description', 'ilike', post.get("search"))
|
2013-10-08 08:39:56 +00:00
|
|
|
]
|
2014-01-29 15:08:38 +00:00
|
|
|
|
2014-01-30 16:11:32 +00:00
|
|
|
# group by country, based on customers found with the search(domain)
|
2013-10-08 08:39:56 +00:00
|
|
|
countries = partner_obj.read_group(
|
2014-01-30 16:11:32 +00:00
|
|
|
cr, openerp.SUPERUSER_ID, domain, ["id", "country_id"],
|
2013-10-08 08:39:56 +00:00
|
|
|
groupby="country_id", orderby="country_id", context=request.context)
|
|
|
|
country_count = partner_obj.search(
|
2014-01-30 16:11:32 +00:00
|
|
|
cr, openerp.SUPERUSER_ID, domain, count=True, context=request.context)
|
2013-10-08 08:39:56 +00:00
|
|
|
|
2014-01-30 16:36:39 +00:00
|
|
|
if country_id:
|
|
|
|
domain += [('country_id', '=', country_id)]
|
2014-01-30 19:37:06 +00:00
|
|
|
if not any(x['country_id'][0] == country_id for x in countries):
|
|
|
|
country = country_obj.browse(cr, uid, country_id, context)
|
|
|
|
countries.append({
|
|
|
|
'country_id_count': 0,
|
|
|
|
'country_id': (country_id, country.name)
|
|
|
|
})
|
|
|
|
countries.sort(key=lambda d: d['country_id'][1])
|
2014-01-30 16:36:39 +00:00
|
|
|
|
2014-01-30 20:57:13 +00:00
|
|
|
countries.insert(0, {
|
|
|
|
'country_id_count': country_count,
|
|
|
|
'country_id': (0, _("All Countries"))
|
|
|
|
})
|
|
|
|
|
2013-10-08 08:39:56 +00:00
|
|
|
# search customers to display
|
2014-05-12 17:51:21 +00:00
|
|
|
partner_count = partner_obj.search_count(cr, openerp.SUPERUSER_ID, domain, context=request.context)
|
2013-10-08 08:39:56 +00:00
|
|
|
|
|
|
|
# pager
|
|
|
|
pager = request.website.pager(
|
2014-05-12 17:51:21 +00:00
|
|
|
url="/customers", total=partner_count, page=page, step=self._references_per_page,
|
2013-10-08 08:39:56 +00:00
|
|
|
scope=7, url_args=post
|
|
|
|
)
|
|
|
|
|
2014-05-12 17:51:21 +00:00
|
|
|
partner_ids = partner_obj.search(request.cr, openerp.SUPERUSER_ID, domain,
|
|
|
|
offset=pager['offset'], limit=self._references_per_page,
|
|
|
|
context=request.context)
|
|
|
|
google_map_partner_ids = ','.join(map(str, partner_ids))
|
|
|
|
partners = partner_obj.browse(request.cr, openerp.SUPERUSER_ID, partner_ids, request.context)
|
|
|
|
|
2013-10-08 08:39:56 +00:00
|
|
|
values = {
|
|
|
|
'countries': countries,
|
2013-11-13 18:38:25 +00:00
|
|
|
'current_country_id': country_id or 0,
|
2014-05-12 17:51:21 +00:00
|
|
|
'partners': partners,
|
2013-10-08 08:39:56 +00:00
|
|
|
'google_map_partner_ids': google_map_partner_ids,
|
|
|
|
'pager': pager,
|
|
|
|
'post': post,
|
2014-01-29 12:13:16 +00:00
|
|
|
'search_path': "?%s" % werkzeug.url_encode(post),
|
2013-10-08 08:39:56 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_customer.index", values)
|
|
|
|
|
2014-05-14 22:43:38 +00:00
|
|
|
# Do not use semantic controller due to SUPERUSER_ID
|
|
|
|
@http.route(['/customers/<partner_id>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def partners_detail(self, partner_id, **post):
|
2014-06-30 16:29:20 +00:00
|
|
|
_, partner_id = unslug(partner_id)
|
|
|
|
if partner_id:
|
2014-05-14 22:43:38 +00:00
|
|
|
partner = request.registry['res.partner'].browse(request.cr, SUPERUSER_ID, partner_id, context=request.context)
|
|
|
|
if partner.exists() and partner.website_published:
|
|
|
|
values = {}
|
|
|
|
values['main_object'] = values['partner'] = partner
|
|
|
|
return request.website.render("website_customer.details", values)
|
|
|
|
return self.customers(**post)
|