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 openerp import tools
23 from openerp.osv import fields,osv
25 class pos_order_report(osv.osv):
26 _name = "report.pos.order"
27 _description = "Point of Sale Orders Statistics"
30 'date': fields.date('Date Order', readonly=True),
31 'year': fields.char('Year', size=4, readonly=True),
32 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
33 ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
34 ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
35 'day': fields.char('Day', size=128, readonly=True),
36 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
37 'product_id':fields.many2one('product.product', 'Product', readonly=True),
38 'state': fields.selection([('draft', 'New'), ('paid', 'Closed'), ('done', 'Synchronized'), ('invoiced', 'Invoiced'), ('cancel', 'Cancelled')],
40 'user_id':fields.many2one('res.users', 'Salesperson', readonly=True),
41 'price_total':fields.float('Total Price', readonly=True),
42 'total_discount':fields.float('Total Discount', readonly=True),
43 'average_price': fields.float('Average Price', readonly=True,group_operator="avg"),
44 'shop_id':fields.many2one('sale.shop', 'Shop', readonly=True),
45 'company_id':fields.many2one('res.company', 'Company', readonly=True),
46 'nbr':fields.integer('# of Lines', readonly=True),
47 'product_qty':fields.integer('# of Qty', readonly=True),
48 'journal_id': fields.many2one('account.journal', 'Journal'),
49 'delay_validation': fields.integer('Delay Validation'),
54 tools.drop_view_if_exists(cr, 'report_pos_order')
56 create or replace view report_pos_order as (
60 to_date(to_char(s.date_order, 'dd-MM-YYYY'),'dd-MM-YYYY') as date,
61 sum(l.qty * u.factor) as product_qty,
62 sum(l.qty * l.price_unit) as price_total,
63 sum((l.qty * l.price_unit) * (l.discount / 100)) as total_discount,
64 (sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal(16,2) as average_price,
65 sum(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') as int)) as delay_validation,
66 to_char(s.date_order, 'YYYY') as year,
67 to_char(s.date_order, 'MM') as month,
68 to_char(s.date_order, 'YYYY-MM-DD') as day,
69 s.partner_id as partner_id,
73 s.company_id as company_id,
74 s.sale_journal as journal_id,
75 l.product_id as product_id
76 from pos_order_line as l
77 left join pos_order s on (s.id=l.order_id)
78 left join product_product p on (p.id=l.product_id)
79 left join product_template pt on (pt.id=p.product_tmpl_id)
80 left join product_uom u on (u.id=pt.uom_id)
82 to_char(s.date_order, 'dd-MM-YYYY'),to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),
83 to_char(s.date_order, 'YYYY-MM-DD'), s.partner_id,s.state,
84 s.user_id,s.shop_id,s.company_id,s.sale_journal,l.product_id,s.create_date
86 sum(l.qty * u.factor) != 0)""")
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: