1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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
25
from decimal_precision import decimal_precision as dp
30
class report_stock_move(osv.osv):
31
_name = 'report.stock.move'
32
_inherit = 'report.stock.move'
35
'type_id': fields.many2one('stock.adjustment.type', string='Adjustment type'),
36
'reason_type_id': fields.many2one('stock.reason.type', string='Reason type'),
40
# @@@override@ stock.report_stock_move.init
41
tools.drop_view_if_exists(cr, 'report_stock_move')
43
CREATE OR REPLACE view report_stock_move AS (
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,
50
al.curr_month as month,
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,
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,
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
71
CASE WHEN sp.type in ('out') THEN
72
sum(sm.product_qty * pu.factor)
75
CASE WHEN sp.type in ('in') THEN
76
sum(sm.product_qty * pu.factor)
79
CASE WHEN sp.type in ('out') THEN
80
sum(sm.product_qty * pu.factor) * pt.standard_price
83
CASE WHEN sp.type in ('in') THEN
84
sum(sm.product_qty * pu.factor) * pt.standard_price
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,
106
sm.product_uom as product_uom,
108
sp.stock_journal_id AS stock_journal
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)
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)
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