1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21 ##############################################################################
24 # Please note that these reports are not multi-currency !!!
27 from osv import fields,osv
29 class report_purchase_order_product(osv.osv):
30 _name = "report.purchase.order.product"
31 _description = "Purchases Orders by Products"
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'),
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),
51 _order = 'name desc,price_total desc'
54 create or replace view report_purchase_order_product as (
57 to_char(s.date_order, 'YYYY-MM-01') as name,
60 sum(l.product_qty*u.factor) as quantity,
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
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
71 report_purchase_order_product()
73 class report_purchase_order_category(osv.osv):
74 _name = "report.purchase.order.category"
75 _description = "Purchases Orders by Categories"
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'),
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),
95 _order = 'name desc,price_total desc'
98 create or replace view report_purchase_order_category as (
101 to_char(s.date_order, 'YYYY-MM-01') as name,
103 t.categ_id as category_id,
104 sum(l.product_qty*u.factor) as quantity,
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
117 report_purchase_order_category()
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: