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 a prodlot recursively upstream and downstream to case created in_review state"""
25
from osv import osv, fields
26
from tools.translate import _
28
class lock_extra_production_lot_recursively(osv.osv_memory):
30
_name = "lock.extra.production.lot.recursively"
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")
39
'firmness_grade': 'pessimistic'
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.
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)
55
if 'prodlot_id' in fields:
56
res.update({'prodlot_id': prodlot_id})
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 = {}
64
production_lot_obj = self.pool.get('stock.production.lot')
65
block_prodlot_case_obj = self.pool.get('block.prodlot.cases')
67
obj = self.browse(cr, uid, ids)[0]
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.'))
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')
76
affected_prodlots.append(obj.prodlot_id.id)
78
affected_prodlots = list(set(affected_prodlots + [x.id for x in obj.case_id.blocked_prodlots_ids]))
80
block_prodlot_case_obj.write(cr, uid, [obj.case_id.id], {
81
'blocked_prodlots_ids': [(6, 0, affected_prodlots)],
84
production_lot_obj.write(cr, uid, affected_prodlots, {})
86
view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'block.prodlot.cases'), ('type', '=', 'tree')])[0]
89
'name': _('Block Prodlot Case'),
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)],
99
return {'type': 'ir.actions.act_window_close'}
101
lock_extra_production_lot_recursively()
b'\\ No newline at end of file'