2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-03-10 07:27:42 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-03-10 07:27:42 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
#
|
|
|
|
# Please note that these reports are not multi-currency !!!
|
|
|
|
#
|
|
|
|
|
|
|
|
from osv import fields,osv
|
2009-11-24 13:58:06 +00:00
|
|
|
import tools
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-03-10 07:27:42 +00:00
|
|
|
class report_purchase_order(osv.osv):
|
|
|
|
_name = "report.purchase.order"
|
|
|
|
_description = "Purchases Orders"
|
2008-07-22 15:11:28 +00:00
|
|
|
_auto = False
|
|
|
|
_columns = {
|
2010-03-10 07:27:42 +00:00
|
|
|
'date': fields.date('Date', readonly=True),
|
2009-11-24 13:58:06 +00:00
|
|
|
'name': fields.char('Year',size=64,required=False, readonly=True),
|
2008-07-22 15:11:28 +00:00
|
|
|
'state': fields.selection([
|
|
|
|
('draft','Quotation'),
|
|
|
|
('waiting_date','Waiting Schedule'),
|
|
|
|
('manual','Manual in progress'),
|
|
|
|
('progress','In progress'),
|
|
|
|
('shipping_except','Shipping Exception'),
|
|
|
|
('invoice_except','Invoice Exception'),
|
|
|
|
('done','Done'),
|
|
|
|
('cancel','Cancel')
|
|
|
|
], 'Order State', readonly=True),
|
|
|
|
'product_id':fields.many2one('product.product', 'Product', readonly=True),
|
2010-03-10 07:27:42 +00:00
|
|
|
'category_id': fields.many2one('product.category', 'Categories', readonly=True),
|
|
|
|
'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
|
|
|
|
'company_id':fields.many2one('res.company', 'Company', readonly=True),
|
|
|
|
'user_id':fields.many2one('res.users', 'Responsible', readonly=True),
|
2008-07-22 15:11:28 +00:00
|
|
|
'quantity': fields.float('# of Products', readonly=True),
|
|
|
|
'price_total': fields.float('Total Price', readonly=True),
|
|
|
|
'price_average': fields.float('Average Price', readonly=True),
|
|
|
|
'count': fields.integer('# of Lines', readonly=True),
|
2009-11-24 13:58:06 +00:00
|
|
|
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
|
|
|
|
('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
|
|
|
_order = 'name desc,price_total desc'
|
|
|
|
def init(self, cr):
|
2010-03-10 07:27:42 +00:00
|
|
|
tools.sql.drop_view_if_exists(cr, 'report_purchase_order')
|
2008-07-22 15:11:28 +00:00
|
|
|
cr.execute("""
|
2010-03-10 07:27:42 +00:00
|
|
|
create or replace view report_purchase_order as (
|
2008-07-22 15:11:28 +00:00
|
|
|
select
|
|
|
|
min(l.id) as id,
|
2010-03-10 07:27:42 +00:00
|
|
|
s.date_order as date,
|
2009-11-24 13:58:06 +00:00
|
|
|
to_char(s.date_order, 'YYYY') as name,
|
|
|
|
to_char(s.date_order, 'MM') as month,
|
2008-07-22 15:11:28 +00:00
|
|
|
s.state,
|
2010-03-10 07:27:42 +00:00
|
|
|
s.partner_id as partner_id,
|
|
|
|
s.create_uid as user_id,
|
|
|
|
s.company_id as company_id,
|
2008-07-22 15:11:28 +00:00
|
|
|
l.product_id,
|
|
|
|
t.categ_id as category_id,
|
|
|
|
sum(l.product_qty*u.factor) as quantity,
|
|
|
|
count(*),
|
|
|
|
sum(l.product_qty*l.price_unit) as price_total,
|
|
|
|
(sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
|
|
|
|
from purchase_order s
|
|
|
|
left join purchase_order_line l on (s.id=l.order_id)
|
|
|
|
left join product_product p on (p.id=l.product_id)
|
|
|
|
left join product_template t on (t.id=p.product_tmpl_id)
|
|
|
|
left join product_uom u on (u.id=l.product_uom)
|
2008-08-19 13:28:54 +00:00
|
|
|
where l.product_id is not null
|
2010-03-10 07:27:42 +00:00
|
|
|
group by s.company_id,s.create_uid,s.partner_id,
|
|
|
|
t.categ_id,l.product_id,s.date_order,
|
|
|
|
to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
|
|
|
|
)
|
2008-07-22 15:11:28 +00:00
|
|
|
""")
|
2010-03-10 07:27:42 +00:00
|
|
|
report_purchase_order()
|
2008-07-23 14:41:47 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|