1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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 ##############################################################################
25 from tools.misc import UpdateableStr
30 from tools.translate import _
35 def make_default(val):
36 def fct(obj, cr, uid):
40 def _get_returns(self, cr, uid, data, context):
41 pool = pooler.get_pool(cr.dbname)
42 pick_obj=pool.get('stock.picking')
43 pick=pick_obj.browse(cr, uid, [data['id']])[0]
46 arch_lst=['<?xml version="1.0"?>', '<form string="%s">' % _('Return lines'), '<label string="%s" colspan="4"/>' % _('Provide the quantities of the returned products.')]
47 for m in [line for line in pick.move_lines]:
48 quantity=m.product_qty
49 arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
50 fields['return%s' % m.id]={'string':m.product_id.name, 'type':'float', 'required':True, 'default':make_default(quantity)}
51 res.setdefault('returns', []).append(m.id)
52 arch_lst.append('<field name="invoice_state"/>\n<newline/>')
53 if pick.invoice_state=='invoiced':
54 new_invoice_state='2binvoiced'
56 new_invoice_state=pick.invoice_state
57 fields['invoice_state']={'string':_('Invoice state'), 'type':'selection', 'default':make_default(new_invoice_state), 'required':True, 'selection':[('2binvoiced', _('to be invoiced')), ('none', _('None'))]}
58 arch_lst.append('</form>')
59 arch.string='\n'.join(arch_lst)
62 def _create_returns(self, cr, uid, data, context):
63 pool = pooler.get_pool(cr.dbname)
64 move_obj = pool.get('stock.move')
65 pick_obj = pool.get('stock.picking')
66 uom_obj = pool.get('product.uom')
68 pick=pick_obj.browse(cr, uid, [data['id']])[0]
70 date_cur=time.strftime('%Y-%m-%d %H:%M:%S')
72 for move in move_obj.browse(cr, uid, data['form'].get('returns',[])):
80 new_picking=pick_obj.copy(cr, uid, pick.id, {'name':'%s (return)' % pick.name,
81 'move_lines':[], 'state':'draft', 'type':new_type,
82 'date':date_cur, 'invoice_state':data['form']['invoice_state'],})
83 new_location=move.location_dest_id.id
85 new_move=move_obj.copy(cr, uid, move.id, {
86 'product_qty': data['form']['return%s' % move.id],
87 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
88 data['form']['return%s' % move.id], move.product_uos.id),
89 'picking_id':new_picking, 'state':'draft',
90 'location_id':new_location, 'location_dest_id':move.location_id.id,
91 'date':date_cur, 'date_planned':date_cur,})
93 wf_service = netsvc.LocalService("workflow")
95 wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
96 pick_obj.force_assign(cr, uid, [new_picking], context)
99 def _action_open_window(self, cr, uid, data, context):
100 res=_create_returns(self, cr, uid, data, context)
104 'domain': "[('id', 'in', ["+str(res)+"])]",
105 'name': 'Packing List',
107 'view_mode':'tree,form',
108 'res_model':'stock.picking',
110 'type':'ir.actions.act_window',
113 class wizard_return_picking(wizard.interface):
116 'actions':[_get_returns],
117 'result':{'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('return','Return')]}
121 'result':{'type':'action', 'action':_action_open_window, 'state':'end'}
124 wizard_return_picking('stock.return.picking')
126 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: