diff --git a/addons/crm/report/crm_lead_report_view.xml b/addons/crm/report/crm_lead_report_view.xml index 09853c6379e..23594a7f9e1 100644 --- a/addons/crm/report/crm_lead_report_view.xml +++ b/addons/crm/report/crm_lead_report_view.xml @@ -66,9 +66,6 @@ crm.lead.report - - - @@ -113,7 +110,7 @@ - @@ -165,9 +162,9 @@ Leads Analysis crm.lead.report form - {'search_default_year': 1,'search_default_lead': 1, "search_default_user":1, "search_default_this_month":1, 'group_by_no_leaf':1, 'group_by':[]} + {'search_default_year': 1, "search_default_user":1, "search_default_month":1, 'group_by_no_leaf':1, 'group_by':[]} tree,graph - [] + [('type','=', 'lead')] 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. @@ -187,8 +184,9 @@ Opportunities Analysis crm.lead.report form - {"search_default_year":1,"search_default_opportunity":1, "search_default_user":1,"search_default_this_month":1,'group_by_no_leaf':1,'group_by':[]} + {"search_default_year":1, "search_default_user":1,"search_default_month":1,'group_by_no_leaf':1,'group_by':[]} tree,graph + [('type','=', 'opportunity')] 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. diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index d5f07f863b9..d2f7849a958 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -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: diff --git a/addons/sale/report/sale_report_view.xml b/addons/sale/report/sale_report_view.xml index 4d0ac87bc13..28a6f83936a 100644 --- a/addons/sale/report/sale_report_view.xml +++ b/addons/sale/report/sale_report_view.xml @@ -50,8 +50,6 @@ - - diff --git a/addons/sale_crm/__openerp__.py b/addons/sale_crm/__openerp__.py index 7db1aa1eff0..25b1fb5f7f4 100644 --- a/addons/sale_crm/__openerp__.py +++ b/addons/sale_crm/__openerp__.py @@ -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', diff --git a/addons/sale_crm/report/__init__.py b/addons/sale_crm/report/__init__.py index d7c6d373468..d86b3e66de9 100644 --- a/addons/sale_crm/report/__init__.py +++ b/addons/sale_crm/report/__init__.py @@ -20,6 +20,7 @@ ############################################################################## import sales_crm_account_invoice_report +import sale_report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale_crm/report/sale_report.py b/addons/sale_crm/report/sale_report.py new file mode 100644 index 00000000000..f8fae28f600 --- /dev/null +++ b/addons/sale_crm/report/sale_report.py @@ -0,0 +1,37 @@ + # -*- coding: utf-8 -*- + ############################################################################## + # + # OpenERP, Open Source Management Solution + # Copyright (C) 2004-2010 Tiny SPRL (). + # + # 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 . + # + ############################################################################## + +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: diff --git a/addons/sale_crm/report/sale_report_view.xml b/addons/sale_crm/report/sale_report_view.xml new file mode 100644 index 00000000000..f054634cf1c --- /dev/null +++ b/addons/sale_crm/report/sale_report_view.xml @@ -0,0 +1,27 @@ + + + + + sale.report.tree.sale.crm + sale.report + + + + + + + + + + sale.report.search.sale.crm + sale.report + + + + + + + + + + \ No newline at end of file diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 4a624db44a1..7e0d6b27a3a 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -212,12 +212,13 @@ - Sales Analysis + Quotations Analysis sale.report form tree,graph - {'search_default_year':1,'search_default_month':1,'search_default_User':1,'search_default_Quotations':1,'group_by_no_leaf':1,'group_by':[]} - 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. + [('state','=','draft'),('section_id', '=', active_id)] + {'search_default_order_month':1,'search_default_User':1} + 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. @@ -225,8 +226,9 @@ sale.report form tree,graph - {'search_default_year':1,'search_default_month':1,'search_default_User':1,'search_default_Sales':1,'group_by_no_leaf':1,'group_by':[]} - 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. + [('state','not in',('draft','done','cancel')),('section_id', '=', active_id)] + {'search_default_order_month':1,'search_default_User':1} + 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. @@ -234,7 +236,8 @@ account.invoice.report form tree,graph - {'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,} + [('section_id', '=', active_id)] + {'search_default_month':1, 'search_default_user':1} 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. @@ -288,7 +291,7 @@ Quotations - Revenue of created quotations per month.
Click to see a detailed analysis of sales. + Revenue of created quotations per month.
Click to see a detailed analysis.
diff --git a/addons/sale_stock/report/sale_report.py b/addons/sale_stock/report/sale_report.py index 0feb3ee2392..7a8234fa7fa 100644 --- a/addons/sale_stock/report/sale_report.py +++ b/addons/sale_stock/report/sale_report.py @@ -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: diff --git a/addons/sale_stock/report/sale_report_view.xml b/addons/sale_stock/report/sale_report_view.xml index 6642bffcede..486cf3a7b11 100644 --- a/addons/sale_stock/report/sale_report_view.xml +++ b/addons/sale_stock/report/sale_report_view.xml @@ -17,6 +17,10 @@ sale.report + + + +