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.osv import fields, osv
23 from openerp import tools
25 class sale_report(osv.osv):
26 _inherit = "sale.report"
28 'shipped': fields.boolean('Shipped', readonly=True),
29 'shipped_qty_1': fields.integer('Shipped', readonly=True),
30 'state': fields.selection([
31 ('draft', 'Quotation'),
32 ('waiting_date', 'Waiting Schedule'),
33 ('manual', 'Manual In Progress'),
34 ('progress', 'In Progress'),
35 ('shipping_except', 'Shipping Exception'),
36 ('invoice_except', 'Invoice Exception'),
38 ('cancel', 'Cancelled')
39 ], 'Order Status', readonly=True),
43 tools.drop_view_if_exists(cr, 'sale_report')
45 create or replace view sale_report as (
48 l.product_id as product_id,
49 t.uom_id as product_uom,
50 sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
51 sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
54 s.date_confirm as date_confirm,
55 to_char(s.date_order, 'YYYY') as year,
56 to_char(s.date_order, 'MM') as month,
57 to_char(s.date_order, 'YYYY-MM-DD') as day,
58 s.partner_id as partner_id,
61 s.company_id as company_id,
62 extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
64 t.categ_id as categ_id,
66 s.shipped::integer as shipped_qty_1,
67 s.pricelist_id as pricelist_id,
68 s.project_id as analytic_account_id
71 left join sale_order_line l on (s.id=l.order_id)
72 left join product_product p on (l.product_id=p.id)
73 left join product_template t on (p.product_tmpl_id=t.id)
74 left join product_uom u on (u.id=l.product_uom)
75 left join product_uom u2 on (u2.id=t.uom_id)
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: