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

« back to all changes in this revision

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