~pexego/openobject-addons/6.1-pexego-sale_commission

« back to all changes in this revision

Viewing changes to full_stock_traceability/wizard/stock_traceability.py

  • Committer: Omar (pexego)
  • Date: 2012-07-27 08:40:22 UTC
  • Revision ID: omar@pexego.es-20120727084022-qp3ludpr3vsuyuf6
[ADD] Traceability modules ported to 6.1

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-2011 Pexego (<www.pexego.es>). All Rights Reserved
 
6
#    $Omar Castiñeira Saavedra$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import osv
 
24
from tools.translate import _
 
25
 
 
26
class action_traceability(osv.osv_memory):
 
27
    """
 
28
    This class defines a function action_traceability for wizard
 
29
 
 
30
    """
 
31
    _inherit = "action.traceability"
 
32
 
 
33
    def action_traceability(self, cr, uid, ids, context=None):
 
34
        """ It traces the information of a product
 
35
        @param self: The object pointer.
 
36
        @param cr: A database cursor
 
37
        @param uid: ID of the user currently logged in
 
38
        @param ids: List of IDs selected
 
39
        @param context: A standard dictionary
 
40
        @return: A dictionary of values
 
41
        """
 
42
        lot_id = ids
 
43
        if context is None:
 
44
            context = {}
 
45
        type1 = context['type'] or 'move_history_ids2'
 
46
        field = context['field'] or 'tracking_id'
 
47
        if field == 'prodlot_id':
 
48
            model = "valid.stock.moves"
 
49
        else:
 
50
            model = "stock.move"
 
51
            
 
52
        obj = self.pool.get(model)
 
53
        ids = obj.search(cr, uid, [(field, 'in',lot_id)])
 
54
        cr.execute("""select valid_stock_moves.id from valid_stock_moves inner join stock_production_lot
 
55
            on valid_stock_moves.prodlot_id = stock_production_lot.id where valid_stock_moves.id in %s and
 
56
            (valid_stock_moves.id not in (select child_id from stock_move_history_ids) or
 
57
            (is_mix = True and prodlot_id not in (select distinct prodlot_id from valid_stock_moves AS sm
 
58
            inner join stock_move_history_ids on sm.id = parent_id
 
59
            where child_id in (valid_stock_moves.id))) or production_id is not null)""", (tuple(ids),))
 
60
 
 
61
        ids = []
 
62
        for (parent_id,) in cr.fetchall():
 
63
            ids.append(parent_id)
 
64
 
 
65
        cr.execute('select id from ir_ui_view where model=%s and field_parent=%s and type=%s', (model, type1, 'tree'))
 
66
        view_id = cr.fetchone()[0]
 
67
        value = {
 
68
            'domain': "[('id','in',["+','.join(map(str, ids))+"])]",
 
69
            'name': ((type1=='move_history_ids2') and _('Upstream Traceability')) or _('Downstream Traceability'),
 
70
            'view_type': 'tree',
 
71
            'view_mode':'tree',
 
72
            'res_model': model,
 
73
            'field_parent': type1,
 
74
            'view_id': (view_id,'View'),
 
75
            'type': 'ir.actions.act_window',
 
76
            'nodestroy':True,
 
77
        }
 
78
        return value
 
79
 
 
80
action_traceability()
 
 
b'\\ No newline at end of file'