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_invoice_type_stats(osv.osv):
26 _name = "sale_journal.invoice.type.stats"
27 _description = "Stats on picking by invoice method"
30 'name': fields.char('Year',size=64,required=False, readonly=True),
31 'invoice_state':fields.selection([
32 ("invoiced","invoiced"),
33 ("2binvoiced","to be invoiced"),
35 ], "Invoice state", readonly=True),
36 'state': fields.selection([
39 ('confirmed','confirmed'),
40 ('assigned','assigned'),
43 ], 'State', readonly=True),
44 'invoice_type_id':fields.many2one('sale_journal.invoice.type', 'Invoicing method', readonly=True),
45 'quantity': fields.float('Quantities', readonly=True),
46 'price_total': fields.float('Total Price', readonly=True),
47 'price_average': fields.float('Average Price', readonly=True),
48 'count': fields.integer('# of Lines', readonly=True),
49 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
50 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
53 _order = 'state,invoice_state,name desc'
55 tools.drop_view_if_exists(cr, 'sale_journal_invoice_type_stats')
57 create or replace view sale_journal_invoice_type_stats as (
60 to_char(s.date, 'YYYY') as name,
61 to_char(s.date, 'MM') as month,
65 sum(l.product_qty) as quantity,
67 sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0)) as price_total,
68 (sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0))/sum(l.product_qty))::decimal(16,2) as price_average
70 left join stock_move l on (s.id=l.picking_id)
71 left join sale_order_line ol on (l.sale_line_id=ol.id)
72 group by s.invoice_type_id, to_char(s.date, 'YYYY'),to_char(s.date, 'MM'),s.state, s.invoice_state
73 order by s.invoice_type_id, s.invoice_state, s.state
76 report_sale_journal_invoice_type_stats()
78 class report_sale_journal_picking(osv.osv):
79 _name = "sale_journal.picking.stats"
80 _description = "Picking lists by Journal"
83 'name': fields.char('Year',size=64,required=False, readonly=True),
84 'state': fields.selection([
87 ('confirmed','confirmed'),
88 ('assigned','assigned'),
91 ], 'State', readonly=True),
92 'journal_id':fields.many2one('sale_journal.picking.journal', 'Journal', readonly=True),
93 'quantity': fields.float('Quantities', readonly=True),
94 'price_total': fields.float('Total Price', readonly=True),
95 'price_average': fields.float('Average Price', readonly=True),
96 'count': fields.integer('# of Lines', readonly=True),
97 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
98 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
101 _order = 'journal_id,name desc,price_total desc'
103 tools.drop_view_if_exists(cr, 'sale_journal_picking_stats')
105 create or replace view sale_journal_picking_stats as (
108 to_char(s.date, 'YYYY') as name,
109 to_char(s.date, 'MM') as month,
112 sum(l.product_qty) as quantity,
114 sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0)) as price_total,
115 (sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0))/sum(l.product_qty))::decimal(16,2) as price_average
117 right join stock_move l on (s.id=l.picking_id)
118 right join sale_order_line ol on (l.sale_line_id=ol.id)
119 group by s.journal_id, to_char(s.date, 'YYYY'),to_char(s.date, 'MM'),s.state
122 report_sale_journal_picking()
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: