[IMP] Improved code of sale report to inherit and add fields in sale_crm,sale_stock modules, added proper domins on the actions in sales teams kanban

bzr revid: tpa@tinyerp.com-20130729101117-6sxwrsh2coz8ygkd
This commit is contained in:
Turkesh Patel (Open ERP) 2013-07-29 15:41:17 +05:30
parent c588dc4699
commit 0049c8efe8
10 changed files with 117 additions and 81 deletions

View File

@ -66,9 +66,6 @@
<field name="model">crm.lead.report</field>
<field name="arch" type="xml">
<search string="Leads Analysis">
<filter icon="terp-personal" name="lead" string="Lead" domain="[('type','=', 'lead')]" help="Show only lead"/>
<filter icon="terp-personal+" string="Opportunity" name="opportunity" domain="[('type','=','opportunity')]" help="Show only opportunity"/>
<separator/>
<filter icon="terp-check" string="New" domain="[('state','=','draft')]" help="Leads/Opportunities which are in New state"/>
<filter icon="terp-camera_test" string="Open" domain="[('state','=','open')]" help="Leads/Opportunities which are in open state"/>
<filter icon="gtk-media-pause" string="Pending" domain="[('state','=','pending')]" help="Leads/Opportunities which are in pending state"/>
@ -113,7 +110,7 @@
<separator orientation="vertical" />
<filter string="Year" icon="terp-go-year"
domain="[]" context="{'group_by':'creation_year'}"/>
<filter string="Month" icon="terp-go-month"
<filter string="Month" name="month" icon="terp-go-month"
domain="[]" context="{'group_by':'creation_month'}"/>
<filter string="Day" icon="terp-go-today"
domain="[]" context="{'group_by':'creation_day'}"/>
@ -165,9 +162,9 @@
<field name="name">Leads Analysis</field>
<field name="res_model">crm.lead.report</field>
<field name="view_type">form</field>
<field name="context">{'search_default_year': 1,'search_default_lead': 1, "search_default_user":1, "search_default_this_month":1, 'group_by_no_leaf':1, 'group_by':[]}</field>
<field name="context">{'search_default_year': 1, "search_default_user":1, "search_default_month":1, 'group_by_no_leaf':1, 'group_by':[]}</field>
<field name="view_mode">tree,graph</field>
<field name="domain">[]</field>
<field name="domain">[('type','=', 'lead')]</field>
<field name="help">Leads Analysis allows you to check different CRM related information like the treatment delays or number of leads per state. You can sort out your leads analysis by different groups to get accurate grained analysis.</field>
</record>
<record model="ir.actions.act_window.view" id="action_report_crm_lead_tree">
@ -187,8 +184,9 @@
<field name="name">Opportunities Analysis</field>
<field name="res_model">crm.lead.report</field>
<field name="view_type">form</field>
<field name="context">{"search_default_year":1,"search_default_opportunity":1, "search_default_user":1,"search_default_this_month":1,'group_by_no_leaf':1,'group_by':[]}</field>
<field name="context">{"search_default_year":1, "search_default_user":1,"search_default_month":1,'group_by_no_leaf':1,'group_by':[]}</field>
<field name="view_mode">tree,graph</field>
<field name="domain">[('type','=', 'opportunity')]</field>
<field name="help">Opportunities Analysis gives you an instant access to your opportunities with information such as the expected revenue, planned cost, missed deadlines or the number of interactions per opportunity. This report is mainly used by the sales manager in order to do the periodic review with the teams of the sales pipeline.</field>
</record>

View File

@ -60,12 +60,9 @@ class sale_report(osv.osv):
}
_order = 'date desc'
def init(self, cr):
tools.drop_view_if_exists(cr, 'sale_report')
cr.execute("""
create or replace view sale_report as (
select
min(l.id) as id,
def _select(self):
select_str = """
SELECT min(l.id) as id,
l.product_id as product_id,
t.uom_id as product_uom,
sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
@ -84,15 +81,23 @@ class sale_report(osv.osv):
t.categ_id as categ_id,
s.pricelist_id as pricelist_id,
s.project_id as analytic_account_id
from
sale_order s
"""
return select_str
def _from(self):
from_str = """
sale_order s
join sale_order_line l on (s.id=l.order_id)
left join product_product p on (l.product_id=p.id)
left join product_template t on (p.product_tmpl_id=t.id)
left join product_uom u on (u.id=l.product_uom)
left join product_uom u2 on (u2.id=t.uom_id)
group by
l.product_id,
"""
return from_str
def _group_by(self):
group_by_str = """
GROUP BY l.product_id,
l.product_uom_qty,
l.order_id,
t.uom_id,
@ -105,7 +110,16 @@ class sale_report(osv.osv):
s.state,
s.pricelist_id,
s.project_id
)
""")
"""
return group_by_str
def init(self, cr):
# self._table = sale_report
tools.drop_view_if_exists(cr, self._table)
cr.execute("""CREATE or REPLACE VIEW %s as (
%s
FROM ( %s )
%s
)""" % (self._table, self._select(), self._from(), self._group_by()))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -50,8 +50,6 @@
<filter icon="terp-document-new" name="Quotations" domain="[('state','=','draft')]"/>
<filter icon="terp-check" name="Sales" domain="[('state','not in',('draft','done','cancel'))]"/>
<separator/>
<filter icon="terp-accessories-archiver" string="Picked" domain="[('shipped','=',True)]"/>
<separator/>
<filter icon="terp-personal" string="My Sales" help="My Sales" domain="[('user_id','=',uid)]"/>
<field name="partner_id"/>
<field name="product_id"/>

View File

@ -46,6 +46,7 @@ modules.
'security/sale_crm_security.xml',
'security/ir.model.access.csv',
'report/sale_crm_account_invoice_report_view.xml',
'report/sale_report_view.xml',
],
'js': [
'static/lib/justgage.js',

View File

@ -20,6 +20,7 @@
##############################################################################
import sales_crm_account_invoice_report
import sale_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp import tools
class sale_report(osv.osv):
_inherit = "sale.report"
_columns = {
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
}
def _select(self):
return super(sale_report, self)._select() + ", s.section_id as section_id"
def _group_by(self):
return super(sale_report, self)._group_by() + ", s.section_id"
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_order_product_tree_sale_crm_inherit" model="ir.ui.view">
<field name="name">sale.report.tree.sale.crm</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_tree"/>
<field name="arch" type="xml">
<field name="product_uom_qty" position="after">
<field name="section_id" groups="base.group_multi_salesteams"/>
</field>
</field>
</record>
<record id="view_order_product_search_sale_crm_inherit" model="ir.ui.view">
<field name="name">sale.report.search.sale.crm</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_search"/>
<field name="arch" type="xml">
<filter string="My Sales" position="after">
<separator/>
<field name="section_id" groups="base.group_multi_salesteams"/>
</filter>
</field>
</record>
</data>
</openerp>

View File

@ -212,12 +212,13 @@
</record>
<record id="action_order_report_quotation_salesteam" model="ir.actions.act_window">
<field name="name">Sales Analysis</field>
<field name="name">Quotations Analysis</field>
<field name="res_model">sale.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="context">{'search_default_year':1,'search_default_month':1,'search_default_User':1,'search_default_Quotations':1,'group_by_no_leaf':1,'group_by':[]}</field>
<field name="help">This report performs analysis on your quotations and sales orders. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application.</field>
<field name="domain">[('state','=','draft'),('section_id', '=', active_id)]</field>
<field name="context">{'search_default_order_month':1,'search_default_User':1}</field>
<field name="help">This report performs analysis on your quotations. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application.</field>
</record>
<record id="action_order_report_so_salesteam" model="ir.actions.act_window">
@ -225,8 +226,9 @@
<field name="res_model">sale.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="context">{'search_default_year':1,'search_default_month':1,'search_default_User':1,'search_default_Sales':1,'group_by_no_leaf':1,'group_by':[]}</field>
<field name="help">This report performs analysis on your quotations and sales orders. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application.</field>
<field name="domain">[('state','not in',('draft','done','cancel')),('section_id', '=', active_id)]</field>
<field name="context">{'search_default_order_month':1,'search_default_User':1}</field>
<field name="help">This report performs analysis on your sales orders. Analysis check your sales revenues and sort it by different group criteria (salesman, partner, product, etc.) Use this report to perform analysis on sales not having invoiced yet. If you want to analyse your turnover, you should use the Invoice Analysis report in the Accounting application.</field>
</record>
<record id="action_account_invoice_report_salesteam" model="ir.actions.act_window">
@ -234,7 +236,8 @@
<field name="res_model">account.invoice.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="context">{'search_default_period':1, 'search_default_current':1, 'search_default_user':1, 'search_default_year': 1, 'search_default_category_product':1, 'search_default_customer':1, 'group_by':[], 'group_by_no_leaf':1,}</field>
<field name="domain">[('section_id', '=', active_id)]</field>
<field name="context">{'search_default_month':1, 'search_default_user':1}</field>
<field name="help">From this report, you can have an overview of the amount invoiced to your customer. The tool search can also be used to personalise your Invoices reports and so, match this analysis to your needs.</field>
</record>
@ -288,7 +291,7 @@
<a name="%(action_quotations_salesteams)d" type="action" class="oe_sparkline_bar_link">Quotations</a>
<a name="%(action_order_report_quotation_salesteam)d" type="action" class="oe_sparkline_bar_link">
<field name="monthly_quoted" widget="sparkline_bar">
Revenue of created quotations per month.<br/>Click to see a detailed analysis of sales.
Revenue of created quotations per month.<br/>Click to see a detailed analysis.
</field>
</a>
</div>

View File

@ -39,58 +39,11 @@ class sale_report(osv.osv):
('cancel', 'Cancelled')
], 'Order Status', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'sale_report')
cr.execute("""
create or replace view sale_report as (
select
min(l.id) as id,
l.product_id as product_id,
t.uom_id as product_uom,
sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
1 as nbr,
s.date_order as date,
s.date_confirm as date_confirm,
to_char(s.date_order, 'YYYY') as year,
to_char(s.date_order, 'MM') as month,
to_char(s.date_order, 'YYYY-MM-DD') as day,
s.partner_id as partner_id,
s.user_id as user_id,
s.company_id as company_id,
s.warehouse_id as warehouse_id,
extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
s.state,
t.categ_id as categ_id,
s.shipped,
s.shipped::integer as shipped_qty_1,
s.pricelist_id as pricelist_id,
s.project_id as analytic_account_id
from
sale_order s
join sale_order_line l on (s.id=l.order_id)
left join product_product p on (l.product_id=p.id)
left join product_template t on (p.product_tmpl_id=t.id)
left join product_uom u on (u.id=l.product_uom)
left join product_uom u2 on (u2.id=t.uom_id)
group by
l.product_id,
l.product_uom_qty,
l.order_id,
t.uom_id,
t.categ_id,
s.date_order,
s.date_confirm,
s.partner_id,
s.user_id,
s.warehouse_id,
s.company_id,
s.state,
s.shipped,
s.pricelist_id,
s.project_id
)
""")
def _select(self):
return super(sale_report, self)._select() + ", s.warehouse_id as warehouse_id, s.shipped, s.shipped::integer as shipped_qty_1"
def _group_by(self):
return super(sale_report, self)._group_by() + ", s.warehouse_id, s.shipped"
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -17,6 +17,10 @@
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_search"/>
<field name="arch" type="xml">
<filter name="Sales" position="after">
<separator/>
<filter icon="terp-accessories-archiver" string="Picked" domain="[('shipped','=',True)]"/>
</filter>
<xpath expr="//group/filter[@string='Status']" position="after">
<filter string="Warehouse" context="{'group_by':'warehouse_id'}"/>
</xpath>