~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to delivery_mechanism/wizard/enter_reason.py

  • Committer: jf
  • Date: 2011-05-16 09:55:17 UTC
  • mfrom: (129.1.1 unifield-wm)
  • Revision ID: jf@tempo4-20110516095517-giuzv2mouka39jb8
UF-270 Advance return in a currency that is not the functional currency

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) Copyright (C) 2011 MSF, TeMPO Consulting.
6
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
from osv import fields, osv
23
 
from tools.translate import _
24
 
import decimal_precision as dp
25
 
 
26
 
import netsvc
27
 
 
28
 
 
29
 
class enter_reason(osv.osv_memory):
30
 
    '''
31
 
    wizard called to split a memory stock move from create picking wizard
32
 
    '''
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),
36
 
                }
37
 
    _defaults = {'picking_id': lambda obj, cr, uid, c: c and c.get('picking_id', False),
38
 
                 }
39
 
 
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)):
44
 
            ids = [ids]
45
 
        # objects
46
 
        picking_obj = self.pool.get('stock.picking')
47
 
        # workflow
48
 
        wf_service = netsvc.LocalService("workflow")
49
 
        # depending on the button clicked the behavior is different
50
 
        cancel_type = context.get('cancel_type', False)
51
 
        # picking ids
52
 
        picking_ids = context['active_ids']
53
 
        # integrity check
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.'))
57
 
        
58
 
        # change 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}
62
 
        # update the object
63
 
        for obj in picking_obj.browse(cr, uid, picking_ids, context=context):
64
 
            # set the reason
65
 
            obj.write({'change_reason': change_reason}, context=context)
66
 
            # cancel the IN
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)
71
 
                
72
 
        return {'type': 'ir.actions.act_window_close'}
73
 
    
74
 
enter_reason()