[ADD, REF]: Converted all simple wizards to osv_memory wizards in stock
[odoo/odoo.git] / addons / report_purchase / report_purchase.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 #
23 # Please note that these reports are not multi-currency !!!
24 #
25
26 from osv import fields,osv
27 import tools
28
29 class report_purchase_order_product(osv.osv):
30     _name = "report.purchase.order.product"
31     _description = "Purchases Orders by Products"
32     _auto = False
33     _columns = {
34         'name': fields.char('Year',size=64,required=False, readonly=True),
35         'state': fields.selection([
36             ('draft','Quotation'),
37             ('waiting_date','Waiting Schedule'),
38             ('manual','Manual in progress'),
39             ('progress','In progress'),
40             ('shipping_except','Shipping Exception'),
41             ('invoice_except','Invoice Exception'),
42             ('done','Done'),
43             ('cancel','Cancel')
44         ], 'Order State', readonly=True),
45         'product_id':fields.many2one('product.product', 'Product', readonly=True),
46         'quantity': fields.float('# of Products', readonly=True),
47         'price_total': fields.float('Total Price', readonly=True),
48         'price_average': fields.float('Average Price', readonly=True),
49         'count': fields.integer('# of Lines', readonly=True),
50         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
51                           ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
52
53     }
54     _order = 'name desc,price_total desc'
55     def init(self, cr):
56         tools.sql.drop_view_if_exists(cr, 'report_purchase_order_product')
57         cr.execute("""
58             create or replace view report_purchase_order_product as (
59                 select
60                     min(l.id) as id,
61                     to_char(s.date_order, 'YYYY') as name,
62                     to_char(s.date_order, 'MM') as month,
63                     s.state,
64                     l.product_id,
65                     sum(l.product_qty*u.factor) as quantity,
66                     count(*),
67                     sum(l.product_qty*l.price_unit) as price_total,
68                     (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
69                 from purchase_order s
70                     left join purchase_order_line l on (s.id=l.order_id)
71                     left join product_uom u on (u.id=l.product_uom)
72                 where l.product_id is not null
73                 group by l.product_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
74             )
75         """)
76 report_purchase_order_product()
77
78 class report_purchase_order_category(osv.osv):
79     _name = "report.purchase.order.category"
80     _description = "Purchases Orders by Categories"
81     _auto = False
82     _columns = {
83         'name': fields.char('Year',size=64,required=False, readonly=True),
84         'state': fields.selection([
85             ('draft','Quotation'),
86             ('waiting_date','Waiting Schedule'),
87             ('manual','Manual in progress'),
88             ('progress','In progress'),
89             ('shipping_except','Shipping Exception'),
90             ('invoice_except','Invoice Exception'),
91             ('done','Done'),
92             ('cancel','Cancel')
93         ], 'Order State', readonly=True),
94         'category_id': fields.many2one('product.category', 'Categories', readonly=True),
95         'quantity': fields.float('# of Products', readonly=True),
96         'price_total': fields.float('Total Price', readonly=True),
97         'price_average': fields.float('Average Price', readonly=True),
98         'count': fields.integer('# of Lines', readonly=True),
99         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
100                   ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
101     }
102     _order = 'name desc,price_total desc'
103     def init(self, cr):
104         tools.sql.drop_view_if_exists(cr, 'report_purchase_order_category')
105         cr.execute("""
106             create or replace view report_purchase_order_category as (
107                 select
108                     min(l.id) as id,
109                     to_char(s.date_order, 'YYYY') as name,
110                     to_char(s.date_order, 'MM') as month,
111                     s.state,
112                     t.categ_id as category_id,
113                     sum(l.product_qty*u.factor) as quantity,
114                     count(*),
115                     sum(l.product_qty*l.price_unit) as price_total,
116                     (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
117                 from purchase_order s
118                     left join purchase_order_line l on (s.id=l.order_id)
119                     left join product_product p on (p.id=l.product_id)
120                     left join product_template t on (t.id=p.product_tmpl_id)
121                     left join product_uom u on (u.id=l.product_uom)
122                 where l.product_id is not null
123                 group by t.categ_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
124              )
125         """)
126 report_purchase_order_category()
127
128 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
129