2018-01-16 06:58:15 +01:00
# -*- coding: utf-8 -*-
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
2018-01-16 06:58:15 +01:00
import werkzeug . urls
2018-01-16 11:34:37 +01:00
from flectra import http
from flectra . addons . http_routing . models . ir_http import unslug , slug
from flectra . addons . website . models . ir_http import sitemap_qs2dom
from flectra . tools . translate import _
from flectra . http import request
2018-01-16 06:58:15 +01:00
class WebsiteCustomer ( http . Controller ) :
_references_per_page = 20
def sitemap_industry ( env , rule , qs ) :
if not qs or qs . lower ( ) in ' /customers ' :
yield { ' loc ' : ' /customers ' }
Industry = env [ ' res.partner.industry ' ]
dom = sitemap_qs2dom ( qs , ' /customers/industry ' , Industry . _rec_name )
for industry in Industry . search ( dom ) :
loc = ' /customers/industry/ %s ' % slug ( industry )
if not qs or qs . lower ( ) in loc :
yield { ' loc ' : loc }
dom = [ ( ' website_published ' , ' = ' , True ) , ( ' assigned_partner_id ' , ' != ' , False ) ]
dom + = sitemap_qs2dom ( qs , ' /customers/country ' )
countries = env [ ' res.partner ' ] . sudo ( ) . read_group ( dom , [ ' id ' , ' country_id ' ] , groupby = ' country_id ' )
for country in countries :
loc = ' /customers/country/ %s ' % slug ( country [ ' country_id ' ] )
if not qs or qs . lower ( ) in loc :
yield { ' loc ' : loc }
@http.route ( [
' /customers ' ,
' /customers/page/<int:page> ' ,
' /customers/country/<model( " res.country " ):country> ' ,
' /customers/country/<model( " res.country " ):country>/page/<int:page> ' ,
' /customers/industry/<model( " res.partner.industry " ):industry> ' ,
' /customers/industry/<model( " res.partner.industry " ):industry>/page/<int:page> ' ,
' /customers/industry/<model( " res.partner.industry " ):industry>/country/<model( " res.country " ):country> ' ,
' /customers/industry/<model( " res.partner.industry " ):industry>/country/<model( " res.country " ):country>/page/<int:page> ' ,
] , type = ' http ' , auth = " public " , website = True , sitemap = sitemap_industry )
def customers ( self , country = None , industry = None , page = 0 , * * post ) :
Tag = request . env [ ' res.partner.tag ' ]
Partner = request . env [ ' res.partner ' ]
search_value = post . get ( ' search ' )
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
domain = [ ( ' website_published ' , ' = ' , True ) , ( ' website_ids ' , ' in ' , request . website . id ) , ( ' assigned_partner_id ' , ' != ' , False ) ]
2018-01-16 06:58:15 +01:00
if search_value :
domain + = [
' | ' , ' | ' ,
( ' name ' , ' ilike ' , search_value ) ,
( ' website_description ' , ' ilike ' , search_value ) ,
( ' industry_id.name ' , ' ilike ' , search_value ) ,
]
tag_id = post . get ( ' tag_id ' )
if tag_id :
tag_id = unslug ( tag_id ) [ 1 ] or 0
domain + = [ ( ' website_tag_ids ' , ' in ' , tag_id ) ]
# group by industry, based on customers found with the search(domain)
industries = Partner . sudo ( ) . read_group ( domain , [ " id " , " industry_id " ] , groupby = " industry_id " , orderby = " industry_id " )
partners_count = Partner . sudo ( ) . search_count ( domain )
if industry :
domain . append ( ( ' industry_id ' , ' = ' , industry . id ) )
if industry . id not in ( x [ ' industry_id ' ] [ 0 ] for x in industries if x [ ' industry_id ' ] ) :
if industry . exists ( ) :
industries . append ( {
' industry_id_count ' : 0 ,
' industry_id ' : ( industry . id , industry . name )
} )
industries . sort ( key = lambda d : ( d . get ( ' industry_id ' ) or ( 0 , ' ' ) ) [ 1 ] )
industries . insert ( 0 , {
' industry_id_count ' : partners_count ,
' industry_id ' : ( 0 , _ ( " All Sectors of Activity " ) )
} )
# group by country, based on customers found with the search(domain)
countries = Partner . sudo ( ) . read_group ( domain , [ " id " , " country_id " ] , groupby = " country_id " , orderby = " country_id " )
country_count = Partner . sudo ( ) . search_count ( domain )
if country :
domain + = [ ( ' country_id ' , ' = ' , country . id ) ]
if country . id not in ( x [ ' country_id ' ] [ 0 ] for x in countries if x [ ' country_id ' ] ) :
if country . exists ( ) :
countries . append ( {
' country_id_count ' : 0 ,
' country_id ' : ( country . id , country . name )
} )
countries . sort ( key = lambda d : ( d [ ' country_id ' ] or ( 0 , " " ) ) [ 1 ] )
countries . insert ( 0 , {
' country_id_count ' : country_count ,
' country_id ' : ( 0 , _ ( " All Countries " ) )
} )
# search customers to display
partner_count = Partner . sudo ( ) . search_count ( domain )
# pager
url = ' /customers '
if industry :
url + = ' /industry/ %s ' % industry . id
if country :
url + = ' /country/ %s ' % country . id
pager = request . website . pager (
url = url , total = partner_count , page = page , step = self . _references_per_page ,
scope = 7 , url_args = post
)
partners = Partner . sudo ( ) . search ( domain , offset = pager [ ' offset ' ] , limit = self . _references_per_page )
google_map_partner_ids = ' , ' . join ( str ( it ) for it in partners . ids )
google_maps_api_key = request . env [ ' ir.config_parameter ' ] . sudo ( ) . get_param ( ' google_maps_api_key ' )
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
tags = Tag . search ( [ ( ' website_published ' , ' = ' , True ) , ( ' website_ids ' , ' in ' , request . website . id ) , ( ' partner_ids ' , ' in ' , partners . ids ) ] , order = ' classname, name ASC ' )
2018-01-16 06:58:15 +01:00
tag = tag_id and Tag . browse ( tag_id ) or False
values = {
' countries ' : countries ,
' current_country_id ' : country . id if country else 0 ,
' current_country ' : country or False ,
' industries ' : industries ,
' current_industry_id ' : industry . id if industry else 0 ,
' current_industry ' : industry 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 ,
' google_maps_api_key ' : google_maps_api_key ,
}
return request . render ( " website_customer.index " , values )
# Do not use semantic controller due to SUPERUSER_ID
@http.route ( [ ' /customers/<partner_id> ' ] , type = ' http ' , auth = " public " , website = True )
def partners_detail ( self , partner_id , * * post ) :
_ , partner_id = unslug ( partner_id )
if partner_id :
partner = request . env [ ' res.partner ' ] . sudo ( ) . browse ( partner_id )
[IMP] Improve Multi-Website Functionalities:-
- Affected Modules:
website_sale, website_blog, website_partner, website_crm_partner_assign,
website_customer, website_slides, website_links, website_membership,
website_hr, website_hr_recruitment, website_payment, website_sale_delivery,
website_forum, website_event
- Remove unnecessary model `website.product.pricelist` from website_sale,
All its mechanism already transferd to existing model `product.pricelist`
- Change in `product.pricelist` model, make website_id(o2m) to website_ids(m2m),
As user can choose that same pricelist can be used in multiple websites
- Added `default_website` as default values in `website_ids(m2m)` & `website_id(m2o)` field in
almost all affected modules (mentioned above!!)
- To use/publish things(like... product, pricelist, blog, forum, events, etc...) in website,
User have to set `website_published` mechanism `on` (if it's available for that model/object),
Also have to set/assign different websites in `website_ids` field as per needs
2018-02-06 10:43:31 +01:00
if partner . exists ( ) and partner . website_published and request . website in partner . website_ids :
2018-01-16 06:58:15 +01:00
values = { }
values [ ' main_object ' ] = values [ ' partner ' ] = partner
return request . render ( " website_customer.details " , values )
return self . customers ( * * post )