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 ##############################################################################
22 from osv import fields,osv
25 class report_sale_journal_sale(osv.osv):
26 _name = "sale_journal.sale.stats"
27 _description = "Sales Orders by Journal"
30 'name': fields.char('Year',size=64,required=False, readonly=True),
31 'state': fields.selection([
32 ('draft','Quotation'),
33 ('waiting_date','Waiting Schedule'),
34 ('manual','Manual in progress'),
35 ('progress','In progress'),
36 ('shipping_except','Shipping Exception'),
37 ('invoice_except','Invoice Exception'),
40 ], 'Order State', readonly=True),
41 'journal_id':fields.many2one('sale_journal.sale.journal', 'Journal', readonly=True),
42 'quantity': fields.float('Quantities', readonly=True),
43 'price_total': fields.float('Total Price', readonly=True),
44 'price_average': fields.float('Average Price', readonly=True),
45 'count': fields.integer('# of Lines', readonly=True),
46 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
47 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
49 _order = 'journal_id,name desc,price_total desc'
51 tools.drop_view_if_exists(cr, 'sale_journal_sale_stats')
53 create or replace view sale_journal_sale_stats as (
56 to_char(s.date_order, 'YYYY') as name,
57 to_char(s.date_order,'MM') as month,
60 sum(l.product_uom_qty) as quantity,
62 sum(l.product_uom_qty*l.price_unit) as price_total,
63 (sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty))::decimal(16,2) as price_average
65 right join sale_order_line l on (s.id=l.order_id)
66 group by s.journal_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
69 report_sale_journal_sale()
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: