2010-03-01 21:44:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import tools
|
|
|
|
from osv import fields,osv
|
|
|
|
|
|
|
|
|
|
|
|
class sale_report(osv.osv):
|
|
|
|
_name = "sale.report"
|
|
|
|
_description = "Sales Orders Statistics"
|
|
|
|
_auto = False
|
|
|
|
_rec_name = 'date'
|
|
|
|
_columns = {
|
2010-06-02 12:28:55 +00:00
|
|
|
'date': fields.date('Date Order', readonly=True),
|
|
|
|
'date_confirm': fields.date('Date Confirm', readonly=True),
|
|
|
|
'shipped':fields.boolean('Shipped', readonly=True),
|
|
|
|
'paid':fields.float('Picked', readonly=True),
|
|
|
|
'shipped_qty_1':fields.integer('Shipped Qty', readonly=True),
|
|
|
|
'paid_qty':fields.float('Paid Qty', readonly=True),
|
2010-03-01 21:44:58 +00:00
|
|
|
'year': fields.char('Year', size=4, readonly=True),
|
|
|
|
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
|
2010-03-12 11:44:19 +00:00
|
|
|
('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
|
2010-03-01 21:44:58 +00:00
|
|
|
('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
|
2010-04-22 05:27:07 +00:00
|
|
|
'day': fields.char('Day', size=128, readonly=True),
|
2010-03-01 21:44:58 +00:00
|
|
|
'product_id':fields.many2one('product.product', 'Product', readonly=True),
|
2010-05-28 07:33:08 +00:00
|
|
|
|
2010-05-28 04:28:45 +00:00
|
|
|
'uom_id': fields.many2one('product.uom', 'Default Unit Of Measure', readonly=True),
|
|
|
|
'product_qty':fields.float('# of Qty', readonly=True),
|
2010-05-27 10:22:38 +00:00
|
|
|
'uom_name': fields.char('Default UoM', size=128, readonly=True),
|
2010-05-27 12:53:47 +00:00
|
|
|
'product_uom_qty':fields.float('# of Qty', readonly=True),
|
2010-05-28 07:33:08 +00:00
|
|
|
|
2010-03-01 21:44:58 +00:00
|
|
|
'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
|
|
|
|
'shop_id':fields.many2one('sale.shop', 'Shop', readonly=True),
|
|
|
|
'company_id':fields.many2one('res.company', 'Company', readonly=True),
|
|
|
|
'user_id':fields.many2one('res.users', 'Salesman', readonly=True),
|
|
|
|
'price_total':fields.float('Total Price', readonly=True),
|
2010-06-21 18:40:58 +00:00
|
|
|
'delay':fields.float('Commitment Delay', digits=(16,2), readonly=True),
|
2010-06-14 09:43:55 +00:00
|
|
|
'price_average':fields.float('Average Price', readonly=True,group_operator="avg"),
|
2010-05-25 10:20:06 +00:00
|
|
|
'categ_id': fields.many2one('product.category','Category of Product', readonly=True),
|
2010-03-01 21:44:58 +00:00
|
|
|
'nbr':fields.integer('# of Lines', readonly=True),
|
|
|
|
'state': fields.selection([
|
|
|
|
('draft', 'Quotation'),
|
|
|
|
('waiting_date', 'Waiting Schedule'),
|
|
|
|
('manual', 'Manual In Progress'),
|
|
|
|
('progress', 'In Progress'),
|
|
|
|
('shipping_except', 'Shipping Exception'),
|
|
|
|
('invoice_except', 'Invoice Exception'),
|
|
|
|
('done', 'Done'),
|
|
|
|
('cancel', 'Cancelled')
|
|
|
|
], 'Order State', readonly=True),
|
2010-05-25 10:20:06 +00:00
|
|
|
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', readonly=True),
|
2010-04-22 10:09:10 +00:00
|
|
|
'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
|
2010-03-01 21:44:58 +00:00
|
|
|
}
|
|
|
|
_order = 'date desc'
|
|
|
|
def init(self, cr):
|
2010-03-12 11:44:19 +00:00
|
|
|
tools.drop_view_if_exists(cr, 'sale_report')
|
2010-03-01 21:44:58 +00:00
|
|
|
cr.execute("""
|
|
|
|
create or replace view sale_report as (
|
2010-06-02 12:28:55 +00:00
|
|
|
select el.*,
|
2010-06-04 17:54:17 +00:00
|
|
|
-- (select count(1) from sale_order_line where order_id = s.id) as nbr,
|
|
|
|
(select 1) as nbr,
|
2010-03-01 21:44:58 +00:00
|
|
|
s.date_order as date,
|
2010-06-02 12:28:55 +00:00
|
|
|
s.date_confirm as date_confirm,
|
2010-03-01 21:44:58 +00:00
|
|
|
to_char(s.date_order, 'YYYY') as year,
|
|
|
|
to_char(s.date_order, 'MM') as month,
|
2010-04-22 05:27:07 +00:00
|
|
|
to_char(s.date_order, 'YYYY-MM-DD') as day,
|
2010-03-01 21:44:58 +00:00
|
|
|
s.partner_id as partner_id,
|
|
|
|
s.user_id as user_id,
|
|
|
|
s.shop_id as shop_id,
|
|
|
|
s.company_id as company_id,
|
2010-06-02 12:28:55 +00:00
|
|
|
extract(epoch from (s.date_confirm-s.create_date))/(24*60*60)::decimal(16,2) as delay,
|
2010-04-22 10:09:10 +00:00
|
|
|
s.state,
|
2010-06-02 12:28:55 +00:00
|
|
|
s.shipped,
|
|
|
|
s.shipped::integer as shipped_qty_1,
|
2010-04-22 10:09:10 +00:00
|
|
|
s.pricelist_id as pricelist_id,
|
2010-05-25 10:20:06 +00:00
|
|
|
s.project_id as analytic_account_id
|
2010-06-14 09:43:55 +00:00
|
|
|
from
|
2010-06-02 12:28:55 +00:00
|
|
|
sale_order s,
|
|
|
|
(
|
|
|
|
select l.id as id,
|
|
|
|
l.product_id as product_id,
|
|
|
|
u.name as uom_name,
|
|
|
|
sum(l.product_uom_qty * u.factor) as product_uom_qty,
|
|
|
|
sum(l.product_uom_qty*l.price_unit) as price_total,
|
2010-06-14 11:27:21 +00:00
|
|
|
(sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average,
|
2010-06-02 12:28:55 +00:00
|
|
|
pt.categ_id, l.order_id
|
|
|
|
from
|
2010-03-01 21:44:58 +00:00
|
|
|
sale_order_line l
|
2010-05-25 10:20:06 +00:00
|
|
|
left join product_uom u on (u.id=l.product_uom)
|
|
|
|
left join product_template pt on (pt.id=l.product_id)
|
2010-06-04 17:54:17 +00:00
|
|
|
group by l.id, l.order_id, l.product_id, u.name, pt.categ_id) el
|
2010-06-02 12:28:55 +00:00
|
|
|
where s.id = el.order_id
|
2010-03-01 21:44:58 +00:00
|
|
|
)
|
|
|
|
""")
|
|
|
|
sale_report()
|
|
|
|
|
2010-04-02 06:23:34 +00:00
|
|
|
|
|
|
|
|