~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to stock/wizard/wizard_return.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id$
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import wizard
 
31
import pooler
 
32
from tools.misc import UpdateableStr
 
33
import time
 
34
 
 
35
arch=UpdateableStr()
 
36
fields={}
 
37
 
 
38
def make_default(val):
 
39
        def fct(obj, cr, uid):
 
40
                return val
 
41
        return fct
 
42
 
 
43
def _get_returns(self, cr, uid, data, context):
 
44
        pick_obj=pooler.get_pool(cr.dbname).get('stock.picking')
 
45
        pick=pick_obj.browse(cr, uid, [data['id']])[0]
 
46
        res={}
 
47
        fields.clear()
 
48
        arch_lst=['<?xml version="1.0"?>', '<form string="Return lines">', '<label string="Indicate here the quantity of the return line." colspan="4"/>']
 
49
        for m in [line for line in pick.move_lines]:
 
50
                quantity=m.product_qty
 
51
                arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
 
52
                fields['return%s' % m.id]={'string':m.product_id.name, 'type':'float', 'required':True, 'default':make_default(quantity)}
 
53
                res.setdefault('returns', []).append(m.id)
 
54
        arch_lst.append('<field name="invoice_state"/>\n<newline/>')
 
55
        if pick.invoice_state=='invoiced':
 
56
                new_invoice_state='2binvoiced'
 
57
        else:
 
58
                new_invoice_state=pick.invoice_state
 
59
        fields['invoice_state']={'string':'Invoice state', 'type':'selection', 'default':make_default(new_invoice_state), 'selection':[('2binvoiced', 'to be invoiced'), ('none', 'None')]}
 
60
        arch_lst.append('</form>')
 
61
        arch.string='\n'.join(arch_lst)
 
62
        return res
 
63
 
 
64
def _create_returns(self, cr, uid, data, context):
 
65
        move_obj=pooler.get_pool(cr.dbname).get('stock.move')
 
66
        pick_obj=pooler.get_pool(cr.dbname).get('stock.picking')
 
67
        pick=pick_obj.browse(cr, uid, [data['id']])[0]
 
68
        new_picking=None
 
69
        date_cur=time.strftime('%Y-%m-%d %H:%M:%S')
 
70
 
 
71
        for move in move_obj.browse(cr, uid, data['form'].get('returns',[])):
 
72
                if not new_picking:
 
73
                        if pick.type=='out':
 
74
                                new_type='in'
 
75
                        elif pick.type=='in':
 
76
                                new_type='out'
 
77
                        else:
 
78
                                new_type='internal'
 
79
                        new_picking=pick_obj.copy(cr, uid, pick.id, {'name':'%s (return)' % pick.name,
 
80
                                        'move_lines':[], 'state':'draft', 'type':new_type, 'loc_move_id':False,
 
81
                                        'date':date_cur, 'invoice_state':data['form']['invoice_state'],})
 
82
                if pick.loc_move_id:
 
83
                        new_location=pick.loc_move_id.id
 
84
                else:
 
85
                        new_location=move.location_dest_id.id
 
86
                new_move=move_obj.copy(cr, uid, move.id, {'product_qty':data['form']['return%s' % move.id],
 
87
                                'picking_id':new_picking, 'state':'draft',
 
88
                                'location_id':new_location, 'location_dest_id':move.location_id.id,
 
89
                                'date':date_cur, 'date_planned':date_cur,})
 
90
        return new_picking
 
91
 
 
92
def _action_open_window(self, cr, uid, data, context):
 
93
        res=_create_returns(self, cr, uid, data, context)
 
94
        if not res:
 
95
                return {}
 
96
        return {
 
97
                'domain': "[('id', 'in', ["+str(res)+"])]",
 
98
                'name': 'Picking List',
 
99
                'view_type':'form',
 
100
                'view_mode':'tree,form',
 
101
                'res_model':'stock.picking',
 
102
                'view_id':False,
 
103
                'type':'ir.actions.act_window',
 
104
        }
 
105
 
 
106
class wizard_return_picking(wizard.interface):
 
107
        states={
 
108
                'init':{
 
109
                        'actions':[_get_returns],
 
110
                        'result':{'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('return','Return')]}
 
111
                },
 
112
                'return':{
 
113
                        'actions':[],
 
114
                        'result':{'type':'action', 'action':_action_open_window, 'state':'end'}
 
115
                }
 
116
        }
 
117
wizard_return_picking('stock.return.picking')