~openerp-dev/openobject-addons/new_account_menu_structure

« back to all changes in this revision

Viewing changes to stock/report/report_stock_picking.py

  • Committer: pap(openerp)
  • Date: 2010-06-16 13:35:15 UTC
  • mfrom: (3604.1.29 trunk-dev-addons3)
  • Revision ID: pap@tinyerp.co.in-20100616133515-j2t05tg2m350t0ub
[Merge]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
from osv import fields,osv
 
22
import tools
 
23
 
 
24
class report_stock_picking(osv.osv):
 
25
    _name = "report.stock.picking"
 
26
    _description = "Stock Picking Report"
 
27
    _auto = False
 
28
    _columns = {
 
29
        'year': fields.char('Year',size=64,required=False, readonly=True),
 
30
        'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
 
31
                                  ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
 
32
        'day': fields.char('Day', size=128, readonly=True),
 
33
        'nbr': fields.integer('# of Lines', readonly=True),
 
34
        'nbp': fields.integer('# of Picking', readonly=True),
 
35
        'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
 
36
        'product_qty': fields.float('# of Products', readonly=True),
 
37
        'product_uos_qty': fields.float('# of Products', readonly=True),
 
38
        'product_id': fields.many2one('product.product', 'Product', readonly=True),
 
39
        'date': fields.date('Date', readonly=True),
 
40
        'avg_days_to_deliver': fields.float('Avg Days to Deliver', digits=(16,2), readonly=True, group_operator="avg",
 
41
                                       help="Number of  Avg Days to deliver"),
 
42
        'state': fields.selection([('draft', 'Draft'),('auto', 'Waiting'),('confirmed', 'Confirmed'),('assigned', 'Available'),('done', 'Done'),('cancel', 'Cancelled')], 'State'),
 
43
        'type': fields.selection([('out', 'Sending Goods'), ('in', 'Getting Goods'), ('internal', 'Internal'), ('delivery', 'Delivery')], 'Shipping Type', required=True),
 
44
        'company_id': fields.many2one('res.company', 'Company', readonly=True),
 
45
        'invoice_state': fields.selection([
 
46
            ("invoiced", "Invoiced"),
 
47
            ("2binvoiced", "To Be Invoiced"),
 
48
            ("none", "Not from Picking")], "Invoice Status",readonly=True),
 
49
        'min_date': fields.date('Expected Date',help="Expected date for Picking. Default it takes current date"),
 
50
        'order_date': fields.date('Order Date', help="Date of Order"),
 
51
        'date_done': fields.date('Date Done', help="Date of completion"),
 
52
        'location_id': fields.many2one('stock.location', 'Source Location', help="Sets a location if you produce at a fixed location. This can be a partner location if you subcontract the manufacturing operations."),
 
53
        'location_dest_id': fields.many2one('stock.location', 'Dest. Location', help="Location where the system will stock the finished products."),
 
54
        'max_date': fields.date('Max.Expected Date'),
 
55
        'product_uos': fields.many2one('product.uom', 'Product UOS'),
 
56
        'product_uom': fields.many2one('product.uom', 'Product UOM'),
 
57
    }
 
58
    def init(self, cr):
 
59
        tools.drop_view_if_exists(cr, 'report_stock_picking')
 
60
        cr.execute("""
 
61
            create or replace view report_stock_picking as (
 
62
                select
 
63
                    min(sm.id) as id,
 
64
                    date_trunc('day',sp.min_date) as min_date,
 
65
                    date_trunc('day',sp.date) as order_date,
 
66
                    date_trunc('day',sp.date_done) as date_done,
 
67
                    date_trunc('day',sp.max_date) as max_date,
 
68
                    to_char(sp.create_date, 'YYYY') as year,
 
69
                    to_char(sp.create_date, 'MM') as month,
 
70
                    to_char(sp.create_date, 'YYYY-MM-DD') as day,
 
71
                    sp.address_id as partner_id,
 
72
                    to_date(to_char(sp.create_date, 'MM-dd-YYYY'),'MM-dd-YYYY') as date,
 
73
                    count(sm.id) as nbr,
 
74
                    count(distinct sp.id) as nbp,
 
75
                    sum(sm.product_qty) as product_qty,
 
76
                    sum(sm.product_uos_qty) as product_uos_qty,
 
77
                    sm.product_id as product_id,
 
78
                    sm.location_dest_id as location_dest_id,
 
79
                    sm.location_id as location_id,
 
80
                    sp.type,
 
81
                    sm.product_uos,
 
82
                    sm.product_uom,
 
83
                    sp.invoice_state,
 
84
                    sp.company_id as company_id,
 
85
                    avg(extract('epoch' from (sp.date_done-sp.create_date)))/(3600*24) as  avg_days_to_deliver,
 
86
                    sp.state
 
87
                from stock_move as sm
 
88
                left join stock_picking as sp ON (sm.picking_id=sp.id)
 
89
                group by sp.type,
 
90
                         sp.create_date,
 
91
                         sp.address_id,
 
92
                         sm.product_id,
 
93
                         to_char(sp.create_date, 'YYYY'),
 
94
                         sm.location_dest_id,
 
95
                         sm.location_id,
 
96
                         to_char(sp.create_date, 'MM'),
 
97
                         to_char(sp.create_date, 'YYYY-MM-DD'),
 
98
                         sm.product_uos,
 
99
                         sm.product_uom,
 
100
                         date_trunc('day',sp.min_date),
 
101
                         date_trunc('day',sp.date),
 
102
                         date_trunc('day',sp.date_done),
 
103
                         date_trunc('day',sp.max_date),
 
104
                         sp.invoice_state,
 
105
                         sp.company_id,
 
106
                         sp.state
 
107
 
 
108
            )""")
 
109
report_stock_picking()
 
110
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: