New certificate number: added a prefix to tell if the module comes from extraaddons...
[odoo/odoo.git] / addons / report_purchase / report_purchase.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 #
24 # Please note that these reports are not multi-currency !!!
25 #
26
27 from osv import fields,osv
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.date('Month', 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     }
51     _order = 'name desc,price_total desc'
52     def init(self, cr):
53         cr.execute("""
54             create or replace view report_purchase_order_product as (
55                 select
56                     min(l.id) as id,
57                     to_char(s.date_order, 'YYYY-MM-01') as name,
58                     s.state,
59                     l.product_id,
60                     sum(l.product_qty*u.factor) as quantity,
61                     count(*),
62                     sum(l.product_qty*l.price_unit) as price_total,
63                     (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
64                 from purchase_order s
65                     left join purchase_order_line l on (s.id=l.order_id)
66                     left join product_uom u on (u.id=l.product_uom)
67                 where l.product_id is not null
68                 group by l.product_id, to_char(s.date_order, 'YYYY-MM-01'),s.state
69             )
70         """)
71 report_purchase_order_product()
72
73 class report_purchase_order_category(osv.osv):
74     _name = "report.purchase.order.category"
75     _description = "Purchases Orders by Categories"
76     _auto = False
77     _columns = {
78         'name': fields.date('Month', readonly=True),
79         'state': fields.selection([
80             ('draft','Quotation'),
81             ('waiting_date','Waiting Schedule'),
82             ('manual','Manual in progress'),
83             ('progress','In progress'),
84             ('shipping_except','Shipping Exception'),
85             ('invoice_except','Invoice Exception'),
86             ('done','Done'),
87             ('cancel','Cancel')
88         ], 'Order State', readonly=True),
89         'category_id': fields.many2one('product.category', 'Categories', readonly=True),
90         'quantity': fields.float('# of Products', readonly=True),
91         'price_total': fields.float('Total Price', readonly=True),
92         'price_average': fields.float('Average Price', readonly=True),
93         'count': fields.integer('# of Lines', readonly=True),
94     }
95     _order = 'name desc,price_total desc'
96     def init(self, cr):
97         cr.execute("""
98             create or replace view report_purchase_order_category as (
99                 select
100                     min(l.id) as id,
101                     to_char(s.date_order, 'YYYY-MM-01') as name,
102                     s.state,
103                     t.categ_id as category_id,
104                     sum(l.product_qty*u.factor) as quantity,
105                     count(*),
106                     sum(l.product_qty*l.price_unit) as price_total,
107                     (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
108                 from purchase_order s
109                     left join purchase_order_line l on (s.id=l.order_id)
110                     left join product_product p on (p.id=l.product_id)
111                     left join product_template t on (t.id=p.product_tmpl_id)
112                     left join product_uom u on (u.id=l.product_uom)
113                 where l.product_id is not null
114                 group by t.categ_id, to_char(s.date_order, 'YYYY-MM-01'),s.state
115              )
116         """)
117 report_purchase_order_category()
118
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
120