~julie-w/unifield-wm/UTP-925

« back to all changes in this revision

Viewing changes to stock_inventory_type/stock_move_report.py

  • Committer: jf
  • Date: 2011-10-07 10:48:42 UTC
  • mfrom: (350.6.7 uf-488)
  • Revision ID: jf@tempo4-20111007104842-wdy7jllpnht7x1aq
UF-488 [MERE] reason types moves

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) 2011 TeMPO Consulting, MSF
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
 
 
22
 
from osv import osv
23
 
from osv import fields
24
 
 
25
 
from decimal_precision import decimal_precision as dp
26
 
 
27
 
import tools
28
 
 
29
 
 
30
 
class report_stock_move(osv.osv):
31
 
    _name = 'report.stock.move'
32
 
    _inherit = 'report.stock.move'
33
 
    
34
 
    _columns = {
35
 
        'type_id': fields.many2one('stock.adjustment.type', string='Adjustment type'),
36
 
        'reason_type_id': fields.many2one('stock.reason.type', string='Reason type'),
37
 
    }
38
 
    
39
 
    def init(self, cr):
40
 
        # @@@override@ stock.report_stock_move.init
41
 
        tools.drop_view_if_exists(cr, 'report_stock_move')
42
 
        cr.execute("""
43
 
            CREATE OR REPLACE view report_stock_move AS (
44
 
                SELECT
45
 
                        min(sm_id) as id,
46
 
                        al.sm_type_id as type_id,
47
 
                        al.sm_reason_type_id as reason_type_id,
48
 
                        date_trunc('day',al.dp) as date,
49
 
                        al.curr_year as year,
50
 
                        al.curr_month as month,
51
 
                        al.curr_day as day,
52
 
                        al.curr_day_diff as day_diff,
53
 
                        al.curr_day_diff1 as day_diff1,
54
 
                        al.curr_day_diff2 as day_diff2,
55
 
                        al.location_id as location_id,
56
 
                        al.picking_id as picking_id,
57
 
                        al.company_id as company_id,
58
 
                        al.location_dest_id as location_dest_id,
59
 
                        al.product_qty,
60
 
                        al.out_qty as product_qty_out,
61
 
                        al.in_qty as product_qty_in,
62
 
                        al.address_id as partner_id,
63
 
                        al.product_id as product_id,
64
 
                        al.state as state ,
65
 
                        al.product_uom as product_uom,
66
 
                        al.categ_id as categ_id,
67
 
                        coalesce(al.type, 'other') as type,
68
 
                        al.stock_journal as stock_journal,
69
 
                        sum(al.in_value - al.out_value) as value
70
 
                    FROM (SELECT
71
 
                        CASE WHEN sp.type in ('out') THEN
72
 
                            sum(sm.product_qty * pu.factor)
73
 
                            ELSE 0.0
74
 
                            END AS out_qty,
75
 
                        CASE WHEN sp.type in ('in') THEN
76
 
                            sum(sm.product_qty * pu.factor)
77
 
                            ELSE 0.0
78
 
                            END AS in_qty,
79
 
                        CASE WHEN sp.type in ('out') THEN
80
 
                            sum(sm.product_qty * pu.factor) * pt.standard_price
81
 
                            ELSE 0.0
82
 
                            END AS out_value,
83
 
                        CASE WHEN sp.type in ('in') THEN
84
 
                            sum(sm.product_qty * pu.factor) * pt.standard_price
85
 
                            ELSE 0.0
86
 
                            END AS in_value,
87
 
                        min(sm.id) as sm_id,
88
 
                        sm.date as dp,
89
 
                        sm.type_id as sm_type_id,
90
 
                        sm.reason_type_id as sm_reason_type_id,
91
 
                        to_char(date_trunc('day',sm.date), 'YYYY') as curr_year,
92
 
                        to_char(date_trunc('day',sm.date), 'MM') as curr_month,
93
 
                        to_char(date_trunc('day',sm.date), 'YYYY-MM-DD') as curr_day,
94
 
                        avg(date(sm.date)-date(sm.create_date)) as curr_day_diff,
95
 
                        avg(date(sm.date_expected)-date(sm.create_date)) as curr_day_diff1,
96
 
                        avg(date(sm.date)-date(sm.date_expected)) as curr_day_diff2,
97
 
                        sm.location_id as location_id,
98
 
                        sm.location_dest_id as location_dest_id,
99
 
                        sum(sm.product_qty) as product_qty,
100
 
                        pt.categ_id as categ_id ,
101
 
                        sm.address_id as address_id,
102
 
                        sm.product_id as product_id,
103
 
                        sm.picking_id as picking_id,
104
 
                            sm.company_id as company_id,
105
 
                            sm.state as state,
106
 
                            sm.product_uom as product_uom,
107
 
                            sp.type as type,
108
 
                            sp.stock_journal_id AS stock_journal
109
 
                    FROM
110
 
                        stock_move sm
111
 
                        LEFT JOIN stock_picking sp ON (sm.picking_id=sp.id)
112
 
                        LEFT JOIN product_product pp ON (sm.product_id=pp.id)
113
 
                        LEFT JOIN product_uom pu ON (sm.product_uom=pu.id)
114
 
                        LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
115
 
                        LEFT JOIN stock_location sl ON (sm.location_id = sl.id)
116
 
 
117
 
                    GROUP BY
118
 
                        sm.id,sp.type, sm.date,sm.address_id, sm.type_id, sm.reason_type_id,
119
 
                        sm.product_id,sm.state,sm.product_uom,sm.date_expected,
120
 
                        sm.product_id,pt.standard_price, sm.picking_id, sm.product_qty,
121
 
                        sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id)
122
 
                    AS al
123
 
 
124
 
                    GROUP BY
125
 
                        al.out_qty,al.in_qty,al.curr_year,al.curr_month, al.sm_type_id, al.sm_reason_type_id,
126
 
                        al.curr_day,al.curr_day_diff,al.curr_day_diff1,al.curr_day_diff2,al.dp,al.location_id,al.location_dest_id,
127
 
                        al.address_id,al.product_id,al.state,al.product_uom,
128
 
                        al.picking_id,al.company_id,al.type,al.product_qty, al.categ_id, al.stock_journal
129
 
               )
130
 
        """)
131
 
        # @@@end
132
 
 
133
 
report_stock_move()