[MIG] website_customer : migraton to new api
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import main
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import openerp
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.web import http
|
||||
@@ -26,10 +28,9 @@ class WebsiteCustomer(http.Controller):
|
||||
'/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='', 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']
|
||||
Country = request.env['res.country']
|
||||
Tag = request.env['res.partner.tag']
|
||||
Partner = request.env['res.partner']
|
||||
partner_name = post.get('search', '')
|
||||
|
||||
domain = [('website_published', '=', True), ('assigned_partner_id', '!=', False)]
|
||||
@@ -45,23 +46,20 @@ class WebsiteCustomer(http.Controller):
|
||||
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"],
|
||||
groupby="country_id", orderby="country_id", context=request.context)
|
||||
country_count = partner_obj.search(
|
||||
cr, openerp.SUPERUSER_ID, domain, count=True, context=request.context)
|
||||
countries = Partner.sudo().read_group(domain, ["id", "country_id"], groupby="country_id", orderby="country_id")
|
||||
country_count = Partner.sudo().search_count(domain)
|
||||
|
||||
if country_id:
|
||||
domain += [('country_id', '=', country_id)]
|
||||
if not any(x['country_id'][0] == country_id for x in countries if x['country_id']):
|
||||
country = country_obj.read(cr, uid, country_id, ['name'], context)
|
||||
country = Country.browse(country_id).read(['name'])
|
||||
if country:
|
||||
countries.append({
|
||||
'country_id_count': 0,
|
||||
'country_id': (country_id, country['name'])
|
||||
})
|
||||
countries.sort(key=lambda d: d['country_id'] and d['country_id'][1])
|
||||
curr_country = country_obj.browse(cr, uid, country_id, context)
|
||||
curr_country = Country.browse(country_id)
|
||||
|
||||
countries.insert(0, {
|
||||
'country_id_count': country_count,
|
||||
@@ -69,7 +67,7 @@ class WebsiteCustomer(http.Controller):
|
||||
})
|
||||
|
||||
# search customers to display
|
||||
partner_count = partner_obj.search_count(cr, openerp.SUPERUSER_ID, domain, context=request.context)
|
||||
partner_count = Partner.sudo().search_count(domain)
|
||||
|
||||
# pager
|
||||
url = '/customers'
|
||||
@@ -80,22 +78,16 @@ class WebsiteCustomer(http.Controller):
|
||||
scope=7, url_args=post
|
||||
)
|
||||
|
||||
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)
|
||||
partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page)
|
||||
google_map_partner_ids = ','.join(map(str, partners.ids))
|
||||
|
||||
tag_obj = request.registry['res.partner.tag']
|
||||
tag_ids = tag_obj.search(cr, uid, [('website_published', '=', True), ('partner_ids', 'in', partner_ids)],
|
||||
order='classname, name ASC', 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
|
||||
tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC')
|
||||
tag = tag_id and Tag.browse(tag_id) or False
|
||||
|
||||
values = {
|
||||
'countries': countries,
|
||||
'current_country_id': country_id or 0,
|
||||
'current_country': country_id and curr_country or False,
|
||||
'current_country': curr_country if country_id else False,
|
||||
'partners': partners,
|
||||
'google_map_partner_ids': google_map_partner_ids,
|
||||
'pager': pager,
|
||||
@@ -111,7 +103,7 @@ class WebsiteCustomer(http.Controller):
|
||||
def partners_detail(self, partner_id, **post):
|
||||
_, partner_id = unslug(partner_id)
|
||||
if partner_id:
|
||||
partner = request.registry['res.partner'].browse(request.cr, SUPERUSER_ID, partner_id, context=request.context)
|
||||
partner = request.env['res.partner'].sudo().browse(partner_id)
|
||||
if partner.exists() and partner.website_published:
|
||||
values = {}
|
||||
values['main_object'] = values['partner'] = partner
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="base.res_partner_2" model="res.partner">
|
||||
@@ -118,6 +118,5 @@
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class res_partner(osv.Model):
|
||||
class Partner(models.Model):
|
||||
|
||||
_inherit = 'res.partner'
|
||||
|
||||
_columns = {
|
||||
'website_tag_ids': fields.many2many('res.partner.tag', id1='partner_id', id2='tag_id', string='Website tags', oldname="tag_ids"),
|
||||
}
|
||||
website_tag_ids = fields.Many2many('res.partner.tag', 'res_partner_res_partner_tag_rel', 'partner_id', 'tag_id', string='Website tags')
|
||||
|
||||
|
||||
class res_partner_tags(osv.Model):
|
||||
_description = 'Partner Tags - These tags can be used on website to find customers by sector, or ... '
|
||||
class Tags(models.Model):
|
||||
|
||||
_name = 'res.partner.tag'
|
||||
_description = 'Partner Tags - These tags can be used on website to find customers by sector, or ... '
|
||||
_inherit = 'website.published.mixin'
|
||||
|
||||
def get_selection_class(self, cr, uid, context=None):
|
||||
@api.model
|
||||
def get_selection_class(self):
|
||||
classname = ['default', 'primary', 'success', 'warning', 'danger']
|
||||
return [(x, str.title(x)) for x in classname]
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Category Name', required=True, translate=True),
|
||||
'partner_ids': fields.many2many('res.partner', 'res_partner_res_partner_tag_rel', id1='tag_id', id2='partner_id', string='Partners'),
|
||||
'classname': fields.selection(get_selection_class, 'Class', help="Bootstrap class to customize the color", required=True),
|
||||
'active': fields.boolean('Active'),
|
||||
}
|
||||
_defaults = {
|
||||
'active': True,
|
||||
'website_published': True,
|
||||
'classname': 'default',
|
||||
}
|
||||
name = fields.Char('Category Name', required=True, translate=True)
|
||||
partner_ids = fields.Many2many('res.partner', 'res_partner_res_partner_tag_rel', 'tag_id', 'partner_id', string='Partners')
|
||||
classname = fields.Selection(get_selection_class, 'Class', default='default', help="Bootstrap class to customize the color", required=True)
|
||||
active = fields.Boolean('Active', default=True)
|
||||
website_published = fields.Boolean(default=True)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.rule" id="website_customer_res_partner_tag_public">
|
||||
<field name="name">Partner Tag: published only</field>
|
||||
@@ -9,5 +8,4 @@
|
||||
<field name="groups" eval="[(4, ref('base.group_public')), (4, ref('base.group_portal'))]"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
<record id="view_partners_form_website" model="ir.ui.view">
|
||||
<field name="name">view.res.partner.form.website.tags</field>
|
||||
<field name="model">res.partner</field>
|
||||
@@ -66,5 +65,5 @@
|
||||
parent="sales_team.menu_config_address_book"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<!-- Layout add nav and footer -->
|
||||
<template id="footer_custom" inherit_id="website.footer_default" name="Footer Customer References Link">
|
||||
@@ -207,5 +206,4 @@
|
||||
</t>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user