1 ##############################################################################
3 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 # $Id: purchase.py 1005 2005-07-25 08:41:42Z nicoe $
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
31 # Please note that these reports are not multi-currency !!!
34 from osv import fields,osv
36 class report_purchase_order_product(osv.osv):
37 _name = "report.purchase.order.product"
38 _description = "Purchases Orders by Products"
41 'name': fields.date('Month', readonly=True),
42 'state': fields.selection([
43 ('draft','Quotation'),
44 ('waiting_date','Waiting Schedule'),
45 ('manual','Manual in progress'),
46 ('progress','In progress'),
47 ('shipping_except','Shipping Exception'),
48 ('invoice_except','Invoice Exception'),
51 ], 'Order State', readonly=True),
52 'product_id':fields.many2one('product.product', 'Product', readonly=True),
53 'quantity': fields.float('# of Products', readonly=True),
54 'price_total': fields.float('Total Price', readonly=True),
55 'price_average': fields.float('Average Price', readonly=True),
56 'count': fields.integer('# of Lines', readonly=True),
58 _order = 'name desc,price_total desc'
61 create or replace view report_purchase_order_product as (
64 to_char(s.date_order, 'YYYY-MM-01') as name,
67 sum(l.product_qty*u.factor) as quantity,
69 sum(l.product_qty*l.price_unit) as price_total,
70 (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
72 left join purchase_order_line l on (s.id=l.order_id)
73 left join product_uom u on (u.id=l.product_uom)
74 group by l.product_id, to_char(s.date_order, 'YYYY-MM-01'),s.state
77 report_purchase_order_product()
79 class report_purchase_order_category(osv.osv):
80 _name = "report.purchase.order.category"
81 _description = "Purchases Orders by Categories"
84 'name': fields.date('Month', readonly=True),
85 'state': fields.selection([
86 ('draft','Quotation'),
87 ('waiting_date','Waiting Schedule'),
88 ('manual','Manual in progress'),
89 ('progress','In progress'),
90 ('shipping_except','Shipping Exception'),
91 ('invoice_except','Invoice Exception'),
94 ], 'Order State', readonly=True),
95 'category_id': fields.many2one('product.category', 'Categories', readonly=True),
96 'quantity': fields.float('# of Products', readonly=True),
97 'price_total': fields.float('Total Price', readonly=True),
98 'price_average': fields.float('Average Price', readonly=True),
99 'count': fields.integer('# of Lines', readonly=True),
101 _order = 'name desc,price_total desc'
104 create or replace view report_purchase_order_category as (
107 to_char(s.date_order, 'YYYY-MM-01') as name,
109 t.categ_id as category_id,
110 sum(l.product_qty*u.factor) as quantity,
112 sum(l.product_qty*l.price_unit) as price_total,
113 (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
114 from purchase_order s
115 left join purchase_order_line l on (s.id=l.order_id)
116 left join product_product p on (p.id=l.product_id)
117 left join product_template t on (t.id=p.product_tmpl_id)
118 left join product_uom u on (u.id=l.product_uom)
119 group by t.categ_id, to_char(s.date_order, 'YYYY-MM-01'),s.state
122 report_purchase_order_category()