1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) Copyright (C) 2011 MSF, TeMPO Consulting.
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
23
from tools.translate import _
24
import decimal_precision as dp
29
class enter_reason(osv.osv_memory):
31
wizard called to split a memory stock move from create picking wizard
33
_name = "enter.reason"
34
_columns = {'picking_id': fields.many2one('stock.picking', string='Incoming Shipment', readonly=True),
35
'change_reason': fields.char(string='Change Reason', size=1024),
37
_defaults = {'picking_id': lambda obj, cr, uid, c: c and c.get('picking_id', False),
40
def do_cancel(self, cr, uid, ids, context=None):
41
# quick integrity check
42
assert context, 'No context defined, problem on method call'
43
if isinstance(ids, (int, long)):
46
picking_obj = self.pool.get('stock.picking')
48
wf_service = netsvc.LocalService("workflow")
49
# depending on the button clicked the behavior is different
50
cancel_type = context.get('cancel_type', False)
52
picking_ids = context['active_ids']
54
for obj in self.browse(cr, uid, ids, context=context):
55
if not obj.change_reason:
56
raise osv.except_osv(_('Error !'), _('You must specify a reason.'))
59
data = self.read(cr, uid, ids, ['change_reason'], context=context)[0]
60
change_reason = data['change_reason']
61
values = {'change_reason': change_reason}
63
for obj in picking_obj.browse(cr, uid, picking_ids, context=context):
65
obj.write({'change_reason': change_reason}, context=context)
67
wf_service.trg_validate(uid, 'stock.picking', obj.id, 'button_cancel', cr)
68
# if full cancel (no resource), we updated corresponding out and correct po state
69
if cancel_type == 'update_out':
70
picking_obj.cancel_and_update_out(cr, uid, [obj.id], context=context)
72
return {'type': 'ir.actions.act_window_close'}