[IMP] website_portal: hide menu when no documents available

This commit impact website_portal, website_portal_sale,
website_project, website_project_issue, and website_crm_partner_assign.

The idea is to hide menu items and dashboard entry in customer
portal when there no document available. Only Sales Orders and
Opportunities are always displayed to avoid empty dashboard.

Also, resequence menu items to be more consistent and to prepare
to insert more items in the future.
This commit is contained in:
fwi-odoo
2017-03-23 14:50:32 +01:00
committed by Jérome Maes
parent ce72152679
commit 936b215adf
8 changed files with 57 additions and 87 deletions
@@ -31,13 +31,15 @@ class WebsiteAccount(website_account):
('type', '=', 'opportunity')
]
@http.route()
def account(self, **kw):
response = super(WebsiteAccount, self).account(**kw)
def _prepare_portal_layout_values(self):
values = super(WebsiteAccount, self)._prepare_portal_layout_values()
lead_count = request.env['crm.lead'].search_count(self.get_domain_my_lead(request.env.user))
opp_count = request.env['crm.lead'].search_count(self.get_domain_my_opp(request.env.user))
response.qcontext.update({'lead_count': lead_count, 'opp_count': opp_count})
return response
values.update({
'lead_count': lead_count,
'opp_count': opp_count,
})
return values
@http.route(['/my/leads', '/my/leads/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_leads(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
@@ -192,12 +192,14 @@
<script type="text/javascript" src="/website_crm_partner_assign/static/src/js/crm_partner_assign.js" />
</xpath>
</template>
<template id="portal_my_home_menu_lead" name="Portal layout : lead menu entry" inherit_id="website_portal.portal_layout" priority="22">
<template id="portal_my_home_menu_lead" name="Portal layout : lead menu entry" inherit_id="website_portal.portal_layout" priority="15">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]" position="inside">
<t t-if="user.commercial_partner_id.grade_id">
<t t-if="user.commercial_partner_id.grade_id and lead_count">
<li t-att-class="page_name == 'lead' and 'active'">
<a href="/my/leads">Leads</a>
</li>
</t>
<t t-if="user.commercial_partner_id.grade_id">
<li t-att-class="page_name == 'opportunity' and 'active'">
<a href="/my/opportunities">Opportunities</a>
</li>
@@ -205,18 +207,13 @@
</xpath>
</template>
<template id="portal_my_home_lead" name="Portal My Home : lead entries" inherit_id="website_portal.portal_my_home" priority="22">
<template id="portal_my_home_lead" name="Portal My Home : lead entries" inherit_id="website_portal.portal_my_home" priority="15">
<xpath expr="//div[contains(@class,'o_my_home_content')]" position="inside">
<t t-if="user.commercial_partner_id.grade_id">
<h3 class="page-header">
<h3 t-if="lead_count" class="page-header">
<a href="/my/leads">Your Leads
<small class="ml8">
<t t-if="lead_count">
<span class='badge'><t t-esc="lead_count"/></span>
</t>
<t t-if="not lead_count">
There are currently no leads.
</t>
<span class='badge'><t t-esc="lead_count"/></span>
</small>
</a>
</h3>
@@ -10,10 +10,8 @@ from odoo.addons.website_portal.controllers.main import website_account, get_rec
class website_account(website_account):
@http.route()
def account(self, **kw):
""" Add sales documents to main account page """
response = super(website_account, self).account(**kw)
def _prepare_portal_layout_values(self):
values = super(website_account, self)._prepare_portal_layout_values()
partner = request.env.user.partner_id
SaleOrder = request.env['sale.order']
@@ -32,12 +30,12 @@ class website_account(website_account):
('state', 'in', ['open', 'paid', 'cancel'])
])
response.qcontext.update({
values.update({
'quotation_count': quotation_count,
'order_count': order_count,
'invoice_count': invoice_count,
})
return response
return values
#
# Quotations and Sales Orders
@@ -6,33 +6,28 @@
</xpath>
</template>
<template id="portal_my_home_menu_sale" name="Portal layout : sales menu entries" inherit_id="website_portal.portal_layout" priority="25">
<template id="portal_my_home_menu_sale" name="Portal layout : sales menu entries" inherit_id="website_portal.portal_layout" priority="20">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]" position="inside">
<li t-att-class="page_name == 'quote' and 'active'">
<a href="/my/quotes">Quotations</a>
<li t-if="quotation_count" t-att-class="page_name == 'quote' and 'active'">
<a href="/my/quotes">Quotes</a>
</li>
<li t-att-class="page_name == 'order' and 'active'">
<a href="/my/orders">Orders</a>
</li>
<li t-att-class="page_name == 'invoice' and 'active'">
<li t-if="invoice_count" t-att-class="page_name == 'invoice' and 'active'">
<a href="/my/invoices">Invoices</a>
</li>
</xpath>
</template>
<template id="portal_my_home_sale" name="Portal My Home : sales entries" inherit_id="website_portal.portal_my_home" priority="25">
<template id="portal_my_home_sale" name="Portal My Home : sales entries" inherit_id="website_portal.portal_my_home" priority="20">
<xpath expr="//div[contains(@class,'o_my_home_content')]" position="inside">
<h3 class="page-header">
<a href="/my/quotes">Your Quotations
<small class="ml8">
<t t-if="quotation_count">
<span class='badge'><t t-esc="quotation_count"/></span>
</t>
<t t-if="not quotation_count">
There are currently no quotations.
</t>
</small>
</a>
<h3 t-if="quotation_count" class="page-header">
<a href="/my/quotes">Your Quotes
<small class="ml8">
<span class='badge'><t t-esc="quotation_count"/></span>
</small>
</a>
</h3>
<h3 class="page-header">
<a href="/my/orders">Your Orders
@@ -46,17 +41,12 @@
</small>
</a>
</h3>
<h3 class="page-header">
<a href="/my/invoices">Your Invoices
<small class="ml8">
<t t-if="invoice_count">
<span class='badge'><t t-esc="invoice_count"/></span>
</t>
<t t-if="not invoice_count">
There are currently no invoices and payments.
</t>
</small>
</a>
<h3 t-if="invoice_count" class="page-header">
<a href="/my/invoices">Your Invoices and Payments
<small class="ml8">
<span class='badge'><t t-esc="invoice_count"/></span>
</small>
</a>
</h3>
</xpath>
</template>
+4 -5
View File
@@ -11,14 +11,13 @@ from odoo.addons.website_portal.controllers.main import website_account, get_rec
class WebsiteAccount(website_account):
@http.route()
def account(self, **kw):
response = super(WebsiteAccount, self).account(**kw)
response.qcontext.update({
def _prepare_portal_layout_values(self):
values = super(WebsiteAccount, self)._prepare_portal_layout_values()
values.update({
'project_count': request.env['project.project'].search_count([('privacy_visibility', '=', 'portal')]),
'task_count': request.env['project.task'].search_count([('project_id.privacy_visibility', '=', 'portal')])
})
return response
return values
@http.route(['/my/projects', '/my/projects/page/<int:page>'], type='http', auth="user", website=True)
def my_projects(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
@@ -1,39 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="portal_layout" name="Portal layout: project menu entry" inherit_id="website_portal.portal_layout" priority="28">
<template id="portal_layout" name="Portal layout: project menu entry" inherit_id="website_portal.portal_layout" priority="40">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]" position="inside">
<li t-att-class="page_name == 'project' and 'active' or ''">
<li t-if="project_count" t-att-class="page_name == 'project' and 'active'">
<a href="/my/projects">Projects</a>
</li>
<li t-att-class="page_name == 'task' and 'active' or ''">
<li t-if="task_count" t-att-class="page_name == 'task' and 'active'">
<a href="/my/tasks">Tasks</a>
</li>
</xpath>
</template>
<template id="portal_my_home" name="Portal My Home: project entries" inherit_id="website_portal.portal_my_home" priority="28">
<template id="portal_my_home" name="Portal My Home: project entries" inherit_id="website_portal.portal_my_home" priority="40">
<xpath expr="//div[contains(@class,'o_my_home_content')]" position="inside">
<h3 class="page-header">
<h3 t-if="project_count" class="page-header">
<a href="/my/projects">Your Projects
<small class="ml8">
<t t-if="project_count">
<span class='badge'><t t-esc="project_count"/></span>
</t>
<t t-if="not project_count">
There are currently no projects.
</t>
<span class='badge'><t t-esc="project_count"/></span>
</small>
</a>
</h3>
<h3 class="page-header">
<h3 t-if="task_count" class="page-header">
<a href="/my/tasks">Your Tasks
<small class="ml8">
<t t-if="task_count">
<span class='badge'><t t-esc="task_count"/></span>
</t>
<t t-if="not task_count">
There are currently no quotes.
</t>
<span class='badge'><t t-esc="task_count"/></span>
</small>
</a>
</h3>
@@ -11,16 +11,15 @@ from odoo.osv.expression import OR
class WebsiteAccount(website_account):
@http.route()
def account(self, **kw):
response = super(WebsiteAccount, self).account(**kw)
def _prepare_portal_layout_values(self):
values = super(WebsiteAccount, self)._prepare_portal_layout_values()
# domain is needed to hide non portal project for employee
# portal users can't see the privacy_visibility, fetch the domain for them in sudo
portal_projects = request.env['project.project'].sudo().search([('privacy_visibility', '=', 'portal')])
response.qcontext.update({
values.update({
'issue_count': request.env['project.issue'].search_count([('project_id', 'in', portal_projects.ids)])
})
return response
return values
@http.route(['/my/issues', '/my/issues/page/<int:page>'], type='http', auth="user", website=True)
def my_issues(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, search=None, search_in='content', **kw):
@@ -1,25 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="portal_layout" name="Portal layout: Issues menu entry" inherit_id="website_portal.portal_layout" priority="30">
<template id="portal_layout" name="Portal layout: Issues menu entry" inherit_id="website_portal.portal_layout" priority="45">
<xpath expr="//ul[contains(@class,'o_portal_submenu')]" position="inside">
<li t-att-class="page_name == 'issue' and 'active' or ''">
<a href="/my/issues">Issues</a>
<li t-if="issue_count" t-att-class="page_name == 'issue' and 'active'">
<a href="/my/issues">Issues</a>
</li>
</xpath>
</template>
<template id="portal_my_home" name="Portal My Home: Issue entries" inherit_id="website_portal.portal_my_home" priority="30">
<template id="portal_my_home" name="Portal My Home: Issue entries" inherit_id="website_portal.portal_my_home" priority="45">
<xpath expr="//div[contains(@class,'o_my_home_content')]" position="inside">
<h3 class="page-header">
<h3 t-if="issue_count" class="page-header">
<a href="/my/issues">Your Issues
<small class="ml8">
<t t-if="issue_count">
<span class='badge'><t t-esc="issue_count"/></span>
</t>
<t t-if="not issue_count">
There are currently no issues.
</t>
<span class='badge'><t t-esc="issue_count"/></span>
</small>
</a>
</h3>