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

« back to all changes in this revision

Viewing changes to stock_block_prodlots/wizard/wizard_add_prodlots_tocase.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
"""wizard that add a prodlot recursively upstream and downstream to case created in_review state"""
 
24
 
 
25
from osv import osv, fields
 
26
from tools.translate import _
 
27
 
 
28
class lock_extra_production_lot_recursively(osv.osv_memory):
 
29
 
 
30
    _name = "lock.extra.production.lot.recursively"
 
31
 
 
32
    _columns = {
 
33
        'prodlot_id': fields.many2one('stock.production.lot', 'Production lot', required=True, readonly=True),
 
34
        'case_id': fields.many2one('block.prodlot.cases', 'Blockade case', required=True, domain=[('state', '=', 'in_review')]),
 
35
        'firmness_grade': fields.selection([('pessimistic', 'Pessimistic'), ('optimistic', 'Optimistic')], 'Firmness', required=True, help="Pessimistic block upstream and downstream, optimistic only upstream")
 
36
    }
 
37
 
 
38
    _defaults = {
 
39
        'firmness_grade': 'pessimistic'
 
40
    }
 
41
 
 
42
    def default_get(self, cr, uid, fields, context=None):
 
43
        """ To get default values for the object.
 
44
         @param self: The object pointer.
 
45
         @param cr: A database cursor
 
46
         @param uid: ID of the user currently logged in
 
47
         @param fields: List of fields for which we want default values
 
48
         @param context: A standard dictionary
 
49
         @return: A dictionary which of fields with values.
 
50
        """
 
51
        if context is None: context = {}
 
52
        prodlot_id = context and context.get('active_id', False) or False
 
53
        res = super(lock_extra_production_lot_recursively, self).default_get(cr, uid, fields, context=context)
 
54
 
 
55
        if 'prodlot_id' in fields:
 
56
            res.update({'prodlot_id': prodlot_id})
 
57
            
 
58
        return res
 
59
 
 
60
    def lock_production_lot(self, cr, uid, ids, context=None):
 
61
        """set in_alert a production lot and his affected lots in blockade case opened"""
 
62
        if context is None: context = {}
 
63
        #gets the objects
 
64
        production_lot_obj = self.pool.get('stock.production.lot')
 
65
        block_prodlot_case_obj = self.pool.get('block.prodlot.cases')
 
66
 
 
67
        obj = self.browse(cr, uid, ids)[0]
 
68
 
 
69
        #if production lot already blocked, raises an exception        
 
70
        if obj.case_id.id in [x.id for x in obj.prodlot_id.blocked_prodlots_cases_ids]:
 
71
            raise osv.except_osv(_('Message !'), _('Production Lot already is in one blockade case.'))
 
72
        else:
 
73
            #gets all prodlots when this prodlot tooks part
 
74
            affected_prodlots = production_lot_obj.search_affected_prodlots(cr, uid, obj.prodlot_id.id, obj.firmness_grade == 'optimistic')
 
75
 
 
76
            affected_prodlots.append(obj.prodlot_id.id)
 
77
 
 
78
            affected_prodlots = list(set(affected_prodlots + [x.id for x in obj.case_id.blocked_prodlots_ids]))
 
79
 
 
80
            block_prodlot_case_obj.write(cr, uid, [obj.case_id.id], {
 
81
                                            'blocked_prodlots_ids': [(6, 0, affected_prodlots)],
 
82
                                            })
 
83
 
 
84
            production_lot_obj.write(cr, uid, affected_prodlots, {})
 
85
 
 
86
            view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'block.prodlot.cases'), ('type', '=', 'tree')])[0]
 
87
 
 
88
            return {
 
89
                'name': _('Block Prodlot Case'),
 
90
                'view_type': 'form',
 
91
                'view_mode': 'tree,form',
 
92
                'res_model': 'block.prodlot.cases',
 
93
                'type': 'ir.actions.act_window',
 
94
                'view_id': (view_id, 'View'),
 
95
                'domain': [('id', '=', obj.case_id.id)],
 
96
                'nodestroy':True
 
97
            }
 
98
 
 
99
        return {'type': 'ir.actions.act_window_close'}
 
100
 
 
101
lock_extra_production_lot_recursively()
 
 
b'\\ No newline at end of file'