1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
6
# $Omar Castiñeira Saavedra$
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.
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.
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/>.
21
##############################################################################
23
"""wizard that add the functionally of blocked a production lot and prodlots affected"""
25
from osv import osv, fields
26
from tools.translate import _
28
class block_production_lot(osv.osv_memory):
30
_name = "block.production.lot"
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")
40
'firmness_grade': 'pessimistic'
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.
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)
56
if 'prodlot_id' in fields:
57
res.update({'prodlot_id': prodlot_id})
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 = {}
65
production_lot_obj = self.pool.get('stock.production.lot')
66
obj = self.browse(cr, uid, ids)[0]
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.'))
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')
77
affected_prodlots.append(obj.prodlot_id.id)
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
86
production_lot_obj.write(cr, uid, affected_prodlots, {})
88
view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'block.prodlot.cases'), ('type', '=', 'tree')])[0]
91
'name': _('Block Prodlot Case'),
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)],
101
return {'type': 'ir.actions.act_window_close'}
103
block_production_lot()
b'\\ No newline at end of file'