58cc26a32242ad87c4ab8146cd550992d75802a5
[odoo/odoo.git] / addons / stock / wizard / stock_traceability.py
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
22 import wizard
23 import netsvc
24 import time
25 import pooler
26
27 from osv import osv
28
29 def action_traceability(type='move_history_ids', field='tracking_id'):
30     def open_tab(self, cr, uid, data, context):
31         obj = pooler.get_pool(cr.dbname).get('stock.move')
32         ids = obj.search(cr, uid, [(field, 'in', data['ids'])])
33         cr.execute('select id from ir_ui_view where model=%s and field_parent=%s and type=%s', ('stock.move', type, 'tree'))
34         view_id = cr.fetchone()[0]
35         value = {
36             'domain': "[('id','in',["+','.join(map(str, ids))+"])]",
37             'name': ((type=='move_history_ids') and 'Upstream Traceability') or 'Downstream Traceability',
38             'view_type': 'tree',
39             'res_model': 'stock.move',
40             'field_parent': type,
41             'view_id': (view_id,'View'),
42             'type': 'ir.actions.act_window'
43         }
44         return value
45     return open_tab
46
47 class wiz_journal(wizard.interface):
48     states = {
49         'init': {
50             'actions': [],
51             'result': {'type': 'action', 'action': action_traceability('move_history_ids2'), 'state':'end'}
52         }
53     }
54 wiz_journal('stock.traceability.downstream')
55
56 class wiz_journal2(wizard.interface):
57     states = {
58         'init': {
59             'actions': [],
60             'result': {'type': 'action', 'action': action_traceability(), 'state':'end'}
61         }
62     }
63 wiz_journal2('stock.traceability.upstream')
64
65 class wiz_journal3(wizard.interface):
66     states = {
67         'init': {
68             'actions': [],
69             'result': {'type': 'action', 'action': action_traceability(field='prodlot_id'), 'state':'end'}
70         }
71     }
72 wiz_journal3('stock.traceability.lot.upstream')
73
74 class wiz_journal4(wizard.interface):
75     states = {
76         'init': {
77             'actions': [],
78             'result': {'type': 'action', 'action': action_traceability('move_history_ids2', 'prodlot_id'), 'state':'end'}
79         }
80     }
81 wiz_journal4('stock.traceability.lot.downstream')
82
83
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
85