[IMP] french translations
[odoo/odoo.git] / addons / stock / wizard / wizard_return.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 import wizard
24 import pooler
25 from tools.misc import UpdateableStr
26
27 import netsvc
28 import time
29
30 from tools.translate import _
31
32 arch=UpdateableStr()
33 fields={}
34
35 def make_default(val):
36     def fct(obj, cr, uid):
37         return val
38     return fct
39
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]
44     res={}
45     fields.clear()
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'
55     else:
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)
60     return res
61
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')
67
68     pick=pick_obj.browse(cr, uid, [data['id']])[0]
69     new_picking=None
70     date_cur=time.strftime('%Y-%m-%d %H:%M:%S')
71
72     for move in move_obj.browse(cr, uid, data['form'].get('returns',[])):
73         if not new_picking:
74             if pick.type=='out':
75                 new_type='in'
76             elif pick.type=='in':
77                 new_type='out'
78             else:
79                 new_type='internal'
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
84
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,})
92     if new_picking:
93         wf_service = netsvc.LocalService("workflow")
94         if new_picking:
95             wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
96         pick_obj.force_assign(cr, uid, [new_picking], context)
97     return new_picking
98
99 def _action_open_window(self, cr, uid, data, context):
100     res=_create_returns(self, cr, uid, data, context)
101     if not res:
102         return {}
103     return {
104         'domain': "[('id', 'in', ["+str(res)+"])]",
105         'name': 'Packing List',
106         'view_type':'form',
107         'view_mode':'tree,form',
108         'res_model':'stock.picking',
109         'view_id':False,
110         'type':'ir.actions.act_window',
111     }
112
113 class wizard_return_picking(wizard.interface):
114     states={
115         'init':{
116             'actions':[_get_returns],
117             'result':{'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('return','Return')]}
118         },
119         'return':{
120             'actions':[],
121             'result':{'type':'action', 'action':_action_open_window, 'state':'end'}
122         }
123     }
124 wizard_return_picking('stock.return.picking')
125
126 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
127