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 from osv import fields,osv
25 class account_invoice_report(osv.osv):
26 _name = "account.invoice.report"
27 _description = "Invoices Statistics"
31 'date': fields.date('Date', readonly=True),
32 'year': fields.char('Year', size=4, readonly=True),
33 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
34 ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
35 ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
36 'product_id':fields.many2one('product.product', 'Product', readonly=True),
37 'product_qty':fields.float('Qty', readonly=True),
38 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
39 'company_id':fields.many2one('res.company', 'Company', readonly=True),
40 'user_id':fields.many2one('res.users', 'Salesman', readonly=True),
41 'price_total':fields.float('Total Price', readonly=True),
42 'price_average':fields.float('Average Price', readonly=True),
43 'nbr':fields.integer('# of Lines', readonly=True),
44 'state': fields.selection([
46 ('proforma','Pro-forma'),
47 ('proforma2','Pro-forma'),
50 ('cancel','Cancelled')
51 ], 'Order State', readonly=True),
55 tools.drop_view_if_exists(cr, 'report_account_invoice_report')
57 create or replace view account_invoice_report as (
60 s.date_invoice as date,
61 to_char(s.date_invoice, 'YYYY') as year,
62 to_char(s.date_invoice, 'MM') as month,
63 l.product_id as product_id,
64 sum(l.quantity * u.factor) as product_qty,
65 s.partner_id as partner_id,
67 s.company_id as company_id,
68 sum(l.quantity*l.price_unit) as price_total,
69 (sum(l.quantity*l.price_unit)/sum(l.quantity * u.factor))::decimal(16,2) as price_average,
73 account_invoice_line l
75 account_invoice s on (s.id=l.invoice_id)
76 left join product_uom u on (u.id=l.uos_id)
78 s.date_invoice, s.partner_id, l.product_id,
79 l.uos_id, s.user_id, s.state,
83 account_invoice_report()