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 'type': fields.selection([
45 ('out_invoice','Customer Invoice'),
46 ('in_invoice','Supplier Invoice'),
47 ('out_refund','Customer Refund'),
48 ('in_refund','Supplier Refund'),
49 ],'Type', readonly=True),
50 'state': fields.selection([
52 ('proforma','Pro-forma'),
53 ('proforma2','Pro-forma'),
56 ('cancel','Cancelled')
57 ], 'Order State', readonly=True),
61 tools.drop_view_if_exists(cr, 'report_account_invoice_report')
63 create or replace view account_invoice_report as (
66 s.date_invoice as date,
67 to_char(s.date_invoice, 'YYYY') as year,
68 to_char(s.date_invoice, 'MM') as month,
69 l.product_id as product_id,
70 sum(l.quantity * u.factor) as product_qty,
71 s.partner_id as partner_id,
73 s.company_id as company_id,
74 sum(l.quantity*l.price_unit) as price_total,
75 (sum(l.quantity*l.price_unit)/sum(l.quantity * u.factor))::decimal(16,2) as price_average,
80 account_invoice_line l
82 account_invoice s on (s.id=l.invoice_id)
83 left join product_uom u on (u.id=l.uos_id)
85 s.type,s.date_invoice, s.partner_id, l.product_id,
86 l.uos_id, s.user_id, s.state,
90 account_invoice_report()