[IMP] account_payment: use the new signal_xxx methods instead of trg_validate.
[odoo/odoo.git] / addons / sale_stock / report / sale_report.py
1  # -*- coding: utf-8 -*-
2  ##############################################################################
3  #
4  #    OpenERP, Open Source Management Solution
5  #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6  #
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.
11  #
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.
16  #
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/>.
19  #
20  ############################################################################## 
21  
22 from openerp.osv import fields, osv
23 from openerp import tools
24
25 class sale_report(osv.osv):
26     _inherit = "sale.report"
27     _columns = {
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'),
37             ('done', 'Done'),
38             ('cancel', 'Cancelled')
39             ], 'Order Status', readonly=True),
40     }
41     
42     def init(self, cr):
43         tools.drop_view_if_exists(cr, 'sale_report')
44         cr.execute("""
45             create or replace view sale_report as (
46                 select
47                     min(l.id) as id,
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,
52                     1 as nbr,
53                     s.date_order as date,
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,
59                     s.user_id as user_id,
60                     s.shop_id as shop_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,
63                     s.state,
64                     t.categ_id as categ_id,
65                     s.shipped,
66                     s.shipped::integer as shipped_qty_1,
67                     s.pricelist_id as pricelist_id,
68                     s.project_id as analytic_account_id
69                 from
70                     sale_order s
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)
76                 group by
77                     l.product_id,
78                     l.product_uom_qty,
79                     l.order_id,
80                     t.uom_id,
81                     t.categ_id,
82                     s.date_order,
83                     s.date_confirm,
84                     s.partner_id,
85                     s.user_id,
86                     s.shop_id,
87                     s.company_id,
88                     s.state,
89                     s.shipped,
90                     s.pricelist_id,
91                     s.project_id
92             )
93         """)
94 sale_report()
95
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: