1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
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
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.
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.
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.
28
##############################################################################
32
from tools.misc import UpdateableStr
38
def make_default(val):
39
def fct(obj, cr, uid):
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]
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'
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)
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]
69
date_cur=time.strftime('%Y-%m-%d %H:%M:%S')
71
for move in move_obj.browse(cr, uid, data['form'].get('returns',[])):
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'],})
83
new_location=pick.loc_move_id.id
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,})
92
def _action_open_window(self, cr, uid, data, context):
93
res=_create_returns(self, cr, uid, data, context)
97
'domain': "[('id', 'in', ["+str(res)+"])]",
98
'name': 'Picking List',
100
'view_mode':'tree,form',
101
'res_model':'stock.picking',
103
'type':'ir.actions.act_window',
106
class wizard_return_picking(wizard.interface):
109
'actions':[_get_returns],
110
'result':{'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('return','Return')]}
114
'result':{'type':'action', 'action':_action_open_window, 'state':'end'}
117
wizard_return_picking('stock.return.picking')