Launchpad automatic translations update.
[odoo/odoo.git] / addons / sale_journal / sale_journal_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 osv import fields,osv
23 import tools
24
25 class report_sale_journal_sale(osv.osv):
26     _name = "sale_journal.sale.stats"
27     _description = "Sales Orders by Journal"
28     _auto = False
29     _columns = {
30         'name': fields.char('Year',size=64,required=False, readonly=True),
31         'state': fields.selection([
32             ('draft','Quotation'),
33             ('waiting_date','Waiting Schedule'),
34             ('manual','Manual in progress'),
35             ('progress','In progress'),
36             ('shipping_except','Shipping Exception'),
37             ('invoice_except','Invoice Exception'),
38             ('done','Done'),
39             ('cancel','Cancel')
40         ], 'Order State', readonly=True),
41         'journal_id':fields.many2one('sale_journal.sale.journal', 'Journal', readonly=True),
42         'quantity': fields.float('Quantities', readonly=True),
43         'price_total': fields.float('Total Price', readonly=True),
44         'price_average': fields.float('Average Price', readonly=True),
45         'count': fields.integer('# of Lines', readonly=True),
46         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
47                                   ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
48     }
49     _order = 'journal_id,name desc,price_total desc'
50     def init(self, cr):
51         tools.drop_view_if_exists(cr, 'sale_journal_sale_stats')
52         cr.execute("""
53             create or replace view sale_journal_sale_stats as (
54                 select
55                     min(l.id) as id,
56                     to_char(s.date_order, 'YYYY') as name,
57                     to_char(s.date_order,'MM') as month,
58                     s.state,
59                     s.journal_id,
60                     sum(l.product_uom_qty) as quantity,
61                     count(*),
62                     sum(l.product_uom_qty*l.price_unit) as price_total,
63                     (sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty))::decimal(16,2) as price_average
64                 from sale_order s
65                     right join sale_order_line l on (s.id=l.order_id)
66                 group by s.journal_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
67             )
68         """)
69 report_sale_journal_sale()
70
71
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
73