1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp import tools
23 from openerp.osv import fields, osv
25 class sale_report(osv.osv):
27 _description = "Sales Orders Statistics"
32 'date': fields.datetime('Date Order', readonly=True), # TDE FIXME master: rename into date_order
33 'date_confirm': fields.date('Date Confirm', readonly=True),
34 'product_id': fields.many2one('product.product', 'Product', readonly=True),
35 'product_uom': fields.many2one('product.uom', 'Unit of Measure', readonly=True),
36 'product_uom_qty': fields.float('# of Qty', readonly=True),
38 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
39 'company_id': fields.many2one('res.company', 'Company', readonly=True),
40 'user_id': fields.many2one('res.users', 'Salesperson', readonly=True),
41 'price_total': fields.float('Total Price', readonly=True),
42 'delay': fields.float('Commitment Delay', digits=(16,2), readonly=True),
43 'categ_id': fields.many2one('product.category','Category of Product', readonly=True),
44 'nbr': fields.integer('# of Lines', readonly=True), # TDE FIXME master: rename into nbr_lines
45 'state': fields.selection([
46 ('draft', 'Quotation'),
47 ('waiting_date', 'Waiting Schedule'),
48 ('manual', 'Manual In Progress'),
49 ('progress', 'In Progress'),
50 ('invoice_except', 'Invoice Exception'),
52 ('cancel', 'Cancelled')
53 ], 'Order Status', readonly=True),
54 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', readonly=True),
55 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
56 'team_id': fields.many2one('crm.team', 'Sales Team', oldname='section_id'),
62 SELECT min(l.id) as id,
63 l.product_id as product_id,
64 t.uom_id as product_uom,
65 sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
66 sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
69 s.date_confirm as date_confirm,
70 s.partner_id as partner_id,
72 s.company_id as company_id,
73 extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
75 t.categ_id as categ_id,
76 s.pricelist_id as pricelist_id,
77 s.project_id as analytic_account_id,
85 join sale_order s on (l.order_id=s.id)
86 left join product_product p on (l.product_id=p.id)
87 left join product_template t on (p.product_tmpl_id=t.id)
88 left join product_uom u on (u.id=l.product_uom)
89 left join product_uom u2 on (u2.id=t.uom_id)
95 GROUP BY l.product_id,
112 # self._table = sale_report
113 tools.drop_view_if_exists(cr, self._table)
114 cr.execute("""CREATE or REPLACE VIEW %s as (
118 )""" % (self._table, self._select(), self._from(), self._group_by()))
120 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: