1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
23 # Please note that these reports are not multi-currency !!!
26 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.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'),
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),
54 _order = 'name desc,price_total desc'
56 tools.sql.drop_view_if_exists(cr, 'report_purchase_order_product')
58 create or replace view report_purchase_order_product as (
61 to_char(s.date_order, 'YYYY') as name,
62 to_char(s.date_order, 'MM') as month,
65 sum(l.product_qty*u.factor) as quantity,
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
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
76 report_purchase_order_product()
78 class report_purchase_order_category(osv.osv):
79 _name = "report.purchase.order.category"
80 _description = "Purchases Orders by Categories"
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'),
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),
102 _order = 'name desc,price_total desc'
104 tools.sql.drop_view_if_exists(cr, 'report_purchase_order_category')
106 create or replace view report_purchase_order_category as (
109 to_char(s.date_order, 'YYYY') as name,
110 to_char(s.date_order, 'MM') as month,
112 t.categ_id as category_id,
113 sum(l.product_qty*u.factor) as quantity,
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
126 report_purchase_order_category()
128 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: