Merge lp:~openerp-dev/openobject-addons/trunk-oldstyle-wiz-conversion into lp:openobject-addons

Proposed by Rucha (Open ERP)
Status: Merged
Merged at revision: 4534
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-oldstyle-wiz-conversion
Merge into: lp:openobject-addons
Diff against target: 979 lines (+237/-512)
11 files modified
mrp/wizard/mrp_track_prod.py (+0/-129)
mrp/wizard/mrp_track_prod_view.xml (+0/-16)
point_of_sale/test/point_of_sale_test.yml (+3/-1)
point_of_sale/wizard/pos_return.py (+53/-129)
point_of_sale/wizard/pos_return_view.xml (+55/-10)
stock/stock.py (+2/-1)
stock/wizard/stock_partial_picking.py (+1/-1)
stock/wizard/stock_return_picking.py (+77/-83)
stock/wizard/stock_return_picking_view.xml (+46/-1)
stock/wizard/stock_split_move.py (+0/-124)
stock/wizard/stock_split_move_view.xml (+0/-17)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-oldstyle-wiz-conversion
Reviewer Review Type Date Requested Status
qdp (OpenERP) Pending
Review via email: mp+52809@code.launchpad.net

Description of the change

RD Project: old style wizard conversion
Improvement in dynamic addition of fields into the columns of the osv objects by making them as osv_memory one2many(stock_return and pos_return wizard)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'mrp/wizard/mrp_track_prod.py'
2--- mrp/wizard/mrp_track_prod.py 2011-01-14 00:11:01 +0000
3+++ mrp/wizard/mrp_track_prod.py 1970-01-01 00:00:00 +0000
4@@ -1,129 +0,0 @@
5-# -*- coding: utf-8 -*-
6-##############################################################################
7-#
8-# OpenERP, Open Source Management Solution
9-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
10-#
11-# This program is free software: you can redistribute it and/or modify
12-# it under the terms of the GNU Affero General Public License as
13-# published by the Free Software Foundation, either version 3 of the
14-# License, or (at your option) any later version.
15-#
16-# This program is distributed in the hope that it will be useful,
17-# but WITHOUT ANY WARRANTY; without even the implied warranty of
18-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19-# GNU Affero General Public License for more details.
20-#
21-# You should have received a copy of the GNU Affero General Public License
22-# along with this program. If not, see <http://www.gnu.org/licenses/>.
23-#
24-##############################################################################
25-
26-from osv import osv, fields
27-
28-class mrp_track_move(osv.osv_memory):
29- _name = 'mrp.production.track'
30- _description = 'Production Track'
31-
32- def view_init(self, cr, uid, fields_list, context=None):
33- """ Creates view dynamically and adding fields at runtime.
34- @param self: The object pointer.
35- @param cr: A database cursor
36- @param uid: ID of the user currently logged in
37- @param context: A standard dictionary
38- @return: New arch of view with new columns.
39- """
40- res = super(mrp_track_move, self).view_init(cr, uid, fields_list, context=context)
41- record_id = context and context.get('active_id', False) or False
42- if record_id:
43- prod_obj = self.pool.get('mrp.production')
44- try:
45- prod = prod_obj.browse(cr, uid, record_id, context=context)
46- for m in [line for line in prod.move_created_ids]:
47- if 'track%s'%(m.id) not in self._columns:
48- self._columns['track%s'%(m.id)] = fields.boolean(string=m.product_id.name)
49- except:
50- return res
51- return res
52-
53- def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
54- """ Changes the view dynamically
55- @param self: The object pointer.
56- @param cr: A database cursor
57- @param uid: ID of the user currently logged in
58- @param context: A standard dictionary
59- @return: New arch of view.
60- """
61- if context is None:
62- context = {}
63- res = super(mrp_track_move, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
64- record_id = context and context.get('active_id', False) or False
65- active_model = context.get('active_model')
66-
67- if not record_id or (active_model and active_model != 'mrp.production'):
68- return res
69-
70- prod_obj = self.pool.get('mrp.production')
71- prod = prod_obj.browse(cr, uid, record_id, context=context)
72- if prod.state != 'done':
73- res['arch'] = '''<form string="Track lines">
74- <label colspan="4" string="You can not split an unfinished production Output." />
75- <group col="2" colspan="4">
76- <button icon='gtk-cancel' special="cancel"
77- string="Exit" />
78- </group>
79- </form>
80- '''
81- else:
82- arch_lst = ['<form string="Track lines">', '<label colspan="4" string="The field on each line says whether this lot should be tracked or not." />']
83- for m in [line for line in prod.move_created_ids]:
84- quantity = m.product_qty
85- res['fields']['track%s' %m.id] = {'string' : m.product_id.name, 'type' : 'boolean', 'default' : lambda x,y,z: False}
86- arch_lst.append('<field name="track%s" />\n<newline />' %m.id)
87- arch_lst.append('<group col="2" colspan="4">')
88- arch_lst.append('<button icon=\'gtk-cancel\' special="cancel" string="Cancel" />')
89- arch_lst.append('<button name="track_lines" string="Track" colspan="1" type="object" icon="gtk-ok" />')
90- arch_lst.append('</group>')
91- arch_lst.append('</form>')
92- res['arch'] = '\n'.join(arch_lst)
93-
94- return res
95-
96- def track_lines(self, cr, uid, ids, context=None):
97- """ Tracks Finished products and splits products to finish lines.
98- @param self: The object pointer.
99- @param cr: A database cursor
100- @param uid: ID of the user currently logged in
101- @param ids: List of IDs selected
102- @param context: A standard dictionary
103- @return:
104- """
105- if context is None:
106- context = {}
107- record_id = context and context.get('active_id', False) or False
108- assert record_id, 'Active ID not found'
109- data = self.read(cr, uid, ids[0])
110- prod_obj = self.pool.get('mrp.production')
111- prod = prod_obj.browse(cr, uid, record_id, context=context)
112- if not prod.move_created_ids and prod.state != 'done':
113- return {}
114- prodlot_obj = self.pool.get('stock.production.lot')
115- move_obj = self.pool.get('stock.move')
116- move_ids = [m.id for m in [line for line in prod.move_created_ids]]
117- for idx, move in enumerate(move_obj.browse(cr, uid, move_ids, context=context)):
118- if data['track%s' %move.id]:
119- for idx in range(int(move.product_qty)):
120- update_val = {'product_qty': 1}
121- if idx:
122- current_move = move_obj.copy(cr, uid, move.id, {'state': move.state, 'production_id': move.production_id.id})
123- else:
124- current_move = move.id
125- new_prodlot = prodlot_obj.create(cr, uid, {'name': 'PRODUCTION:%d:LOT:%d' % (record_id, idx+1), 'product_id': move.product_id.id})
126- update_val['prodlot_id'] = new_prodlot
127- move_obj.write(cr, uid, [current_move], update_val)
128- return {'type': 'ir.actions.act_window_close'}
129-
130-mrp_track_move()
131-
132-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
133-
134
135=== removed file 'mrp/wizard/mrp_track_prod_view.xml'
136--- mrp/wizard/mrp_track_prod_view.xml 2011-01-14 00:11:01 +0000
137+++ mrp/wizard/mrp_track_prod_view.xml 1970-01-01 00:00:00 +0000
138@@ -1,16 +0,0 @@
139-<?xml version="1.0" encoding="utf-8"?>
140-<openerp>
141- <data>
142-
143- <!-- Track Production -->
144-
145- <act_window name="Track Production"
146- res_model="mrp.production.track"
147- src_model="mrp.production"
148- view_mode="form"
149- target="new"
150- key2="client_action_multi"
151- id="act_production_track"/>
152-
153- </data>
154-</openerp>
155
156=== modified file 'point_of_sale/test/point_of_sale_test.yml'
157--- point_of_sale/test/point_of_sale_test.yml 2011-02-03 13:15:11 +0000
158+++ point_of_sale/test/point_of_sale_test.yml 2011-03-15 10:56:31 +0000
159@@ -374,7 +374,9 @@
160 I click on Return Picking button.
161 -
162 !record {model: pos.return, id: pos_return_0}:
163- {}
164+ pos_moves_ids:
165+ - product_id: product_product_hppaviliondesktoppcs0
166+ quantity: 5.0
167 -
168 I Return the product.
169 -
170
171=== modified file 'point_of_sale/wizard/pos_return.py'
172--- point_of_sale/wizard/pos_return.py 2011-02-15 12:13:39 +0000
173+++ point_of_sale/wizard/pos_return.py 2011-03-15 10:56:31 +0000
174@@ -24,9 +24,25 @@
175 from tools.translate import _
176 import time
177
178+class pos_return_memory(osv.osv_memory):
179+ _name = "pos.return.memory"
180+ _rec_name = 'product_id'
181+ _columns = {
182+ 'product_id' : fields.many2one('product.product', string="Product", required=True),
183+ 'quantity' : fields.float("Quantity", required=True),
184+ 'pos_moves_id' : fields.many2one('pos.return', string="Move"),
185+ 'line_id': fields.integer('Line Id'),
186+ }
187+
188+pos_return_memory()
189+
190+
191 class pos_return(osv.osv_memory):
192 _name = 'pos.return'
193 _description = 'Point of sale return'
194+ _columns = {
195+ 'pos_moves_ids' : fields.one2many('pos.return.memory', 'pos_moves_id', 'Moves'),
196+ }
197
198 def default_get(self, cr, uid, fields, context=None):
199 """
200@@ -41,97 +57,21 @@
201 @return: A dictionary which of fields with values.
202
203 """
204-
205 res = super(pos_return, self).default_get(cr, uid, fields, context=context)
206 order_obj = self.pool.get('pos.order')
207 if context is None:
208 context={}
209 active_ids = context.get('active_ids')
210- for order in order_obj.browse(cr, uid, active_ids, context=context):
211- for line in order.lines:
212- if 'return%s'%(line.id) in fields:
213- res['return%s'%(line.id)] = line.qty
214- return res
215-
216- def view_init(self, cr, uid, fields_list, context=None):
217- """
218- Creates view dynamically and adding fields at runtime.
219- @param self: The object pointer.
220- @param cr: A database cursor
221- @param uid: ID of the user currently logged in
222- @param context: A standard dictionary
223- @return: New arch of view with new columns.
224- """
225- res = super(pos_return, self).view_init(cr, uid, fields_list, context=context)
226- order_obj=self.pool.get('pos.order')
227- if context is None:
228- context={}
229-
230- active_ids=context.get('active_ids')
231- for order in order_obj.browse(cr, uid, active_ids, context=context):
232- for line in order.lines:
233- if 'return%s'%(line.id) not in self._columns:
234- self._columns['return%s'%(line.id)] = fields.float("Quantity")
235-
236- return res
237-
238- def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
239-
240- """
241- Changes the view dynamically
242-
243- @param self: The object pointer.
244- @param cr: A database cursor
245- @param uid: ID of the user currently logged in
246- @param context: A standard dictionary
247-
248- @return: New arch of view.
249-
250- """
251- result = super(pos_return, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
252- if context is None:
253- context={}
254- active_model = context.get('active_model')
255- if not active_model and active_model != 'pos.order':
256- return result
257- order_obj = self.pool.get('pos.order')
258- active_id = context.get('active_id', False)
259- if active_id:
260- _moves_arch_lst="""<?xml version="1.0"?>
261- <form string="Return lines">
262- <label string="Quantities you enter, match to products that will return to the stock." colspan="4"/>"""
263- _line_fields = result['fields']
264- order=order_obj.browse(cr, uid, active_id, context=context)
265- for line in order.lines:
266- quantity=line.qty
267- _line_fields.update({
268- 'return%s'%(line.id) : {
269- 'string': line.product_id.name,
270- 'type' : 'float',
271- 'required': True,
272- 'default':quantity
273- },
274- })
275- _moves_arch_lst += """
276- <field name="return%s"/>
277- <newline/>
278- """%(line.id)
279-
280- _moves_arch_lst+="""
281- <newline/>
282- <separator colspan="4"/>
283- <button icon='gtk-cancel' special="cancel"
284- string="Cancel" />
285- <button icon='gtk-ok' name= "create_returns"
286- string="Return with Exchange" type="object"/>
287- <button icon='gtk-ok' name="create_returns2"
288- string="Refund Without Exchange" type="object"/>
289- </form>"""
290-
291- result['arch'] = _moves_arch_lst
292- result['fields'] = _line_fields
293- return result
294-
295+ result=[]
296+ for order in order_obj.browse(cr, uid, active_ids, context=context):
297+ for line in order.lines:
298+ result.append({
299+ 'product_id' : line.product_id.id,
300+ 'quantity' : line.qty,
301+ 'line_id':line.id
302+ })
303+ res.update({'pos_moves_ids': result})
304+ return res
305
306 def create_returns(self, cr, uid, data, context=None):
307 """
308@@ -145,23 +85,15 @@
309 """
310 if context is None:
311 context = {}
312- current_rec = self.read(cr, uid, data[0], context=context)
313+ current_rec = self.browse(cr, uid, data, context=context)[0]
314 order_obj =self.pool.get('pos.order')
315 line_obj = self.pool.get('pos.order.line')
316 pos_current = order_obj.browse(cr, uid, context.get('active_id'), context=context)
317- pos_line_ids = pos_current.lines
318- if pos_line_ids:
319- for pos_line in pos_line_ids:
320- line_field = "return"+str(pos_line.id)
321- pos_list = current_rec.keys()
322- newline_vals = {}
323- if line_field in pos_list :
324- less_qty = current_rec.get(line_field)
325- pos_cur_line = line_obj.browse(cr, uid, pos_line.id, context=context)
326- qty = pos_cur_line.qty
327- qty = qty - less_qty
328- newline_vals.update({'qty':qty})
329- line_obj.write(cr, uid, pos_line.id, newline_vals, context=context)
330+ for pos_line in pos_current.lines:
331+ for record in current_rec.pos_moves_ids:
332+ if pos_line.id == record.line_id:
333+ less_qty = record.quantity
334+ line_obj.write(cr, uid, pos_line.id, {'qty':pos_line.qty - less_qty}, context=context)
335 return {
336 'name': _('Add Product'),
337 'view_type': 'form',
338@@ -174,6 +106,7 @@
339 'type': 'ir.actions.act_window',
340 }
341 def create_returns2(self, cr, uid, ids, context=None):
342+
343 if context is None:
344 context = {}
345 active_id = context.get('active_id', False)
346@@ -187,18 +120,16 @@
347 wf_service = netsvc.LocalService("workflow")
348 #Todo :Need to clean the code
349 if active_id:
350- data = self.read(cr, uid, ids)[0]
351+ data = self.browse(cr, uid, ids, context=context)[0]
352 date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
353
354 for order_id in order_obj.browse(cr, uid, [active_id], context=context):
355- prop_ids = property_obj.search(cr, uid,[('name', '=', 'property_stock_customer')])
356- val = property_obj.browse(cr, uid, prop_ids[0], context=context).value_reference
357+ stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
358 cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
359 "WHERE w.lot_stock_id=s.id AND w.id=%s ",
360 (order_id.shop_id.warehouse_id.id,))
361 res = cr.fetchone()
362 location_id = res and res[0] or None
363- stock_dest_id = val.id
364 new_picking = picking_obj.copy(cr, uid, order_id.picking_id.id, {'name':'%s (return)' % order_id.name,
365 'move_lines': [],
366 'state':'draft',
367@@ -212,25 +143,23 @@
368 account_def = property_obj.get(cr, uid, 'property_account_payable', 'res.partner', context=context)
369 amount = 0.0
370 for line in order_id.lines:
371- if line.id:
372- try:
373- qty = data['return%s' %line.id]
374+ for record in data.pos_moves_ids:
375+ if line.id == record.line_id:
376+ qty = record.quantity
377 amount += qty * line.price_unit
378- except :
379- qty = line.qty
380- stock_move_obj.create(cr, uid, {
381- 'product_qty': qty ,
382- 'product_uos_qty': uom_obj._compute_qty(cr, uid, qty ,line.product_id.uom_id.id),
383- 'picking_id': new_picking,
384- 'product_uom': line.product_id.uom_id.id,
385- 'location_id': location_id,
386- 'product_id': line.product_id.id,
387- 'location_dest_id': stock_dest_id,
388- 'name': '%s (return)' %order_id.name,
389- 'date': date_cur
390- })
391- if qty != 0.0:
392- line_obj.copy(cr, uid, line.id, {'qty': -qty, 'order_id': new_order})
393+ stock_move_obj.create(cr, uid, {
394+ 'product_qty': qty ,
395+ 'product_uos_qty': uom_obj._compute_qty(cr, uid, qty ,line.product_id.uom_id.id),
396+ 'picking_id': new_picking,
397+ 'product_uom': line.product_id.uom_id.id,
398+ 'location_id': location_id,
399+ 'product_id': line.product_id.id,
400+ 'location_dest_id': stock_dest_id,
401+ 'name': '%s (return)' %order_id.name,
402+ 'date': date_cur
403+ })
404+ if qty != 0.0:
405+ line_obj.copy(cr, uid, line.id, {'qty': -qty, 'order_id': new_order})
406 statementl_obj.create(cr, uid, {
407 'name': 'Refund %s'%order_id.name,
408 'statement_id': order_id.statement_ids[0].statement_id.id,
409@@ -290,15 +219,12 @@
410 for order_id in order_obj.browse(cr, uid, [active_id], context=context):
411 prod=data['product_id']
412 qty=data['quantity']
413- prop_ids = property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')])
414- val = property_obj.browse(cr, uid, prop_ids[0]).value_reference
415+ stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
416 cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
417 "WHERE w.lot_stock_id=s.id AND w.id=%s ",
418 (order_id.shop_id.warehouse_id.id,))
419 res=cr.fetchone()
420 location_id=res and res[0] or None
421- stock_dest_id = val.id
422-
423 prod_id=prod_obj.browse(cr, uid, prod, context=context)
424 new_picking=picking_obj.create(cr, uid, {
425 'name':'%s (Added)' %order_id.name,
426@@ -357,14 +283,12 @@
427 order_obj.add_product(cr, uid, active_ids[0], self_data['product_id'], self_data['quantity'], context=context)
428
429 for order_id in order_obj.browse(cr, uid, active_ids, context=context):
430- prop_ids =property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')])
431- val = property_obj.browse(cr, uid, prop_ids[0]).value_reference
432+ stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
433 cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
434 " WHERE w.lot_stock_id=s.id AND w.id=%s ",
435 (order_id.shop_id.warehouse_id.id,))
436 res=cr.fetchone()
437 location_id=res and res[0] or None
438- stock_dest_id = val.id
439
440 order_obj.write(cr,uid,[order_id.id],{'type_rec':'Exchange'})
441 if order_id.invoice_id:
442
443=== modified file 'point_of_sale/wizard/pos_return_view.xml'
444--- point_of_sale/wizard/pos_return_view.xml 2011-01-14 00:11:01 +0000
445+++ point_of_sale/wizard/pos_return_view.xml 2011-03-15 10:56:31 +0000
446@@ -1,13 +1,58 @@
447 <?xml version="1.0" encoding="utf-8"?>
448 <openerp>
449- <data>
450- <record id="action_view_pos_return" model="ir.actions.act_window">
451- <field name="name">Return lines</field>
452- <field name="res_model">pos.return</field>
453- <field name="view_type">form</field>
454- <field name="view_mode">form</field>
455- <field name="target">new</field>
456- </record>
457+ <data>
458+ <record id="pos_return_form" model="ir.ui.view">
459+ <field name="name">pos.return</field>
460+ <field name="model">pos.return</field>
461+ <field name="type">form</field>
462+ <field name="arch" type="xml">
463+ <form string="Return lines">
464+ <label string=" Enter the quantities which you want to return." colspan="4"/>
465+ <separator colspan="4"/>
466+ <field name="pos_moves_ids" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" >
467+ </field>
468+ <newline/>
469+ <separator colspan="4"/>
470+ <button icon='gtk-cancel' special="cancel" string="Cancel" />
471+ <button icon='gtk-ok' name= "create_returns" string="Return With Exchange" type="object"/>
472+ <button icon='gtk-ok' name="create_returns2" string="Refund Without Exchange" type="object"/>
473+ </form>
474+ </field>
475+ </record>
476+
477+ <record id="action_view_pos_return" model="ir.actions.act_window">
478+ <field name="name">Return lines</field>
479+ <field name="res_model">pos.return</field>
480+ <field name="view_type">form</field>
481+ <field name="view_mode">form</field>
482+ <field name="target">new</field>
483+ </record>
484+
485+ <record id="pos_return_tree_in" model="ir.ui.view">
486+ <field name="name">pos.return.memory</field>
487+ <field name="model">pos.return.memory</field>
488+ <field name="type">tree</field>
489+ <field name="arch" type="xml">
490+ <tree editable="bottom" string="Return Product">
491+ <field name="product_id" />
492+ <field name="quantity" />
493+ <field name="line_id" invisible="1"/>
494+ </tree>
495+ </field>
496+ </record>
497+
498+ <record id="pos_return_form_in" model="ir.ui.view">
499+ <field name="name">pos.return.memory</field>
500+ <field name="model">pos.return.memory</field>
501+ <field name="type">form</field>
502+ <field name="arch" type="xml">
503+ <form>
504+ <field name="product_id" />
505+ <field name="quantity" />
506+ <field name="line_id" invisible="1"/>
507+ </form>
508+ </field>
509+ </record>
510
511- </data>
512-</openerp>
513+ </data>
514+</openerp>
515
516=== modified file 'stock/stock.py'
517--- stock/stock.py 2011-03-09 13:14:25 +0000
518+++ stock/stock.py 2011-03-15 10:56:31 +0000
519@@ -691,7 +691,7 @@
520 if res:
521 picking_obj = self.browse(cr, uid, res, context=context)
522 for move in picking_obj.move_lines:
523- move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False})
524+ move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False, 'move_history_ids2': [(6, 0, [])], 'move_history_ids': [(6, 0, [])]})
525 return res
526
527 def onchange_partner_in(self, cr, uid, context=None, partner_id=None):
528@@ -1623,6 +1623,7 @@
529 if default is None:
530 default = {}
531 default = default.copy()
532+ default.update({'move_history_ids2': [], 'move_history_ids': []})
533 return super(stock_move, self).copy(cr, uid, id, default, context=context)
534
535 def _auto_init(self, cursor, context=None):
536
537=== modified file 'stock/wizard/stock_partial_picking.py'
538--- stock/wizard/stock_partial_picking.py 2011-03-09 16:52:46 +0000
539+++ stock/wizard/stock_partial_picking.py 2011-03-15 10:56:31 +0000
540@@ -68,7 +68,7 @@
541 if m.state in ('done', 'cancel'):
542 continue
543 result.append(self.__create_partial_picking_memory(m, pick_type))
544-
545+
546 if 'product_moves_in' in fields:
547 res.update({'product_moves_in': result})
548 if 'product_moves_out' in fields:
549
550=== modified file 'stock/wizard/stock_return_picking.py'
551--- stock/wizard/stock_return_picking.py 2011-02-03 14:21:24 +0000
552+++ stock/wizard/stock_return_picking.py 2011-03-15 10:56:31 +0000
553@@ -25,9 +25,26 @@
554 from osv import osv,fields
555 from tools.translate import _
556
557+class stock_return_picking_memory(osv.osv_memory):
558+ _name = "stock.return.picking.memory"
559+ _rec_name = 'product_id'
560+ _columns = {
561+ 'product_id' : fields.many2one('product.product', string="Product", required=True),
562+ 'quantity' : fields.float("Quantity", required=True),
563+ 'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
564+ 'move_id' : fields.many2one('stock.move', "Move"),
565+ }
566+
567+stock_return_picking_memory()
568+
569+
570 class stock_return_picking(osv.osv_memory):
571 _name = 'stock.return.picking'
572 _description = 'Return Picking'
573+ _columns = {
574+ 'product_return_moves' : fields.one2many('stock.return.picking.memory', 'wizard_id', 'Moves'),
575+ 'invoice_state': fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], 'Invoicing',required=True),
576+ }
577
578 def default_get(self, cr, uid, fields, context=None):
579 """
580@@ -39,6 +56,7 @@
581 @param context: A standard dictionary
582 @return: A dictionary with default values for all field in ``fields``
583 """
584+ result1 = []
585 if context is None:
586 context = {}
587 res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
588@@ -48,13 +66,16 @@
589 if pick:
590 if 'invoice_state' in fields:
591 if pick.invoice_state=='invoiced':
592- res['invoice_state'] = '2binvoiced'
593+ res.update({'invoice_state': '2binvoiced'})
594 else:
595- res['invoice_state'] = 'none'
596+ res.update({'invoice_state': 'none'})
597+ return_history = self.get_return_history(cr, uid, record_id, context)
598 for line in pick.move_lines:
599- return_id = 'return%s'%(line.id)
600- if return_id in fields:
601- res[return_id] = line.product_qty
602+ qty = line.product_qty - return_history[line.id]
603+ if qty > 0:
604+ result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id})
605+ if 'product_return_moves' in fields:
606+ res.update({'product_return_moves': result1})
607 return res
608
609 def view_init(self, cr, uid, fields_list, context=None):
610@@ -75,62 +96,34 @@
611 pick = pick_obj.browse(cr, uid, record_id, context=context)
612 if pick.state not in ['done','confirmed','assigned']:
613 raise osv.except_osv(_('Warning !'), _("You may only return pickings that are Confirmed, Available or Done!"))
614- return_history = {}
615 valid_lines = 0
616- for m in [line for line in pick.move_lines]:
617- if m.state == 'done':
618- return_history[m.id] = 0
619- for rec in m.move_history_ids2:
620- return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
621- if m.product_qty * m.product_uom.factor >= return_history[m.id]:
622+ return_history = self.get_return_history(cr, uid, record_id, context)
623+ for m in pick.move_lines:
624+ if m.product_qty * m.product_uom.factor > return_history[m.id]:
625 valid_lines += 1
626- if 'return%s'%(m.id) not in self._columns:
627- self._columns['return%s'%(m.id)] = fields.float(string=m.name, required=True)
628- if 'invoice_state' not in self._columns:
629- self._columns['invoice_state'] = fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], string='Invoicing', required=True)
630 if not valid_lines:
631 raise osv.except_osv(_('Warning !'), _("There are no products to return (only lines in Done state and not fully returned yet can be returned)!"))
632 return res
633-
634- def fields_view_get(self, cr, uid, view_id=None, view_type='form',
635- context=None, toolbar=False, submenu=False):
636- """
637- Changes the view dynamically
638+
639+ def get_return_history(self, cr, uid, pick_id, context=None):
640+ """
641+ Get return_history.
642 @param self: The object pointer.
643 @param cr: A database cursor
644 @param uid: ID of the user currently logged in
645+ @param pick_id: Picking id
646 @param context: A standard dictionary
647- @return: New arch of view.
648+ @return: A dictionary which of values.
649 """
650- res = super(stock_return_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
651- record_id = context and context.get('active_id', False)
652- active_model = context.get('active_model')
653- if active_model != 'stock.picking':
654- return res
655- if record_id:
656- pick_obj = self.pool.get('stock.picking')
657- pick = pick_obj.browse(cr, uid, record_id)
658- return_history = {}
659- res['fields'].clear()
660- arch_lst=['<?xml version="1.0"?>', '<form string="%s">' % _('Return lines'), '<label string="%s" colspan="4"/>' % _('Provide the quantities of the returned products.')]
661- for m in pick.move_lines:
662+ pick_obj = self.pool.get('stock.picking')
663+ pick = pick_obj.browse(cr, uid, pick_id, context=context)
664+ return_history = {}
665+ for m in pick.move_lines:
666+ if m.state == 'done':
667 return_history[m.id] = 0
668 for rec in m.move_history_ids2:
669- return_history[m.id] += rec.product_qty
670- quantity = m.product_qty
671- if m.state=='done' and quantity > return_history[m.id]:
672- arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
673- res['fields']['return%s' % m.id]={'string':m.name, 'type':'float', 'required':True}
674- res.setdefault('returns', []).append(m.id)
675- arch_lst.append('<field name="invoice_state"/>\n<newline/>')
676- res['fields']['invoice_state']={'string':_('Invoicing'), 'type':'selection','required':True, 'selection':[('2binvoiced', _('To be refunded/invoiced')), ('none', _('No invoicing'))]}
677- arch_lst.append('<group col="2" colspan="4">')
678- arch_lst.append('<button icon="gtk-cancel" special="cancel" string="Cancel" />')
679- arch_lst.append('<button name="create_returns" string="Return" colspan="1" type="object" icon="gtk-apply" />')
680- arch_lst.append('</group>')
681- arch_lst.append('</form>')
682- res['arch'] = '\n'.join(arch_lst)
683- return res
684+ return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
685+ return return_history
686
687 def create_returns(self, cr, uid, ids, context=None):
688 """
689@@ -148,48 +141,49 @@
690 move_obj = self.pool.get('stock.move')
691 pick_obj = self.pool.get('stock.picking')
692 uom_obj = self.pool.get('product.uom')
693+ data_obj = self.pool.get('stock.return.picking.memory')
694 wf_service = netsvc.LocalService("workflow")
695-
696 pick = pick_obj.browse(cr, uid, record_id, context=context)
697 data = self.read(cr, uid, ids[0], context=context)
698 new_picking = None
699 date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
700-
701 set_invoice_state_to_none = True
702 returned_lines = 0
703- for move in pick.move_lines:
704- if not new_picking:
705- if pick.type=='out':
706- new_type = 'in'
707- elif pick.type=='in':
708- new_type = 'out'
709- else:
710- new_type = 'internal'
711- new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
712- 'move_lines':[], 'state':'draft', 'type':new_type,
713- 'date':date_cur, 'invoice_state':data['invoice_state'],})
714+
715+# Create new picking for returned products
716+ if pick.type=='out':
717+ new_type = 'in'
718+ elif pick.type=='in':
719+ new_type = 'out'
720+ else:
721+ new_type = 'internal'
722+ new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
723+ 'move_lines':[], 'state':'draft', 'type':new_type,
724+ 'date':date_cur, 'invoice_state':data['invoice_state'],})
725+
726+ val_id = data['product_return_moves']
727+ for v in val_id:
728+ data_get = data_obj.read(cr, uid, v)
729+ mov_id = data_get['move_id']
730+ new_qty = data_get['quantity']
731+ move = move_obj.browse(cr, uid, mov_id, context=context)
732 new_location=move.location_dest_id.id
733- if move.state=='done':
734- new_qty = data['return%s' % move.id]
735- returned_qty = move.product_qty
736-
737- for rec in move.move_history_ids2:
738- returned_qty -= rec.product_qty
739-
740- if returned_qty != new_qty:
741- set_invoice_state_to_none = False
742-
743- if new_qty:
744- returned_lines += 1
745- new_move=move_obj.copy(cr, uid, move.id, {
746- 'product_qty': new_qty,
747- 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
748- new_qty, move.product_uos.id),
749- 'picking_id':new_picking, 'state':'draft',
750- 'location_id':new_location, 'location_dest_id':move.location_id.id,
751- 'date':date_cur,})
752- move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
753-
754+ returned_qty = move.product_qty
755+ for rec in move.move_history_ids2:
756+ returned_qty -= rec.product_qty
757+
758+ if returned_qty != new_qty:
759+ set_invoice_state_to_none = False
760+ if new_qty:
761+ returned_lines += 1
762+ new_move=move_obj.copy(cr, uid, move.id, {
763+ 'product_qty': new_qty,
764+ 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
765+ new_qty, move.product_uos.id),
766+ 'picking_id':new_picking, 'state':'draft',
767+ 'location_id':new_location, 'location_dest_id':move.location_id.id,
768+ 'date':date_cur,})
769+ move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
770 if not returned_lines:
771 raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
772
773
774=== modified file 'stock/wizard/stock_return_picking_view.xml'
775--- stock/wizard/stock_return_picking_view.xml 2011-01-14 00:11:01 +0000
776+++ stock/wizard/stock_return_picking_view.xml 2011-03-15 10:56:31 +0000
777@@ -9,5 +9,50 @@
778 key2="client_action_multi"
779 multi="True"
780 id="act_stock_return_picking"/>
781- </data>
782+
783+ <record id="stock_return_memory_tree_in" model="ir.ui.view">
784+ <field name="name">stock.return.picking.memory.tree</field>
785+ <field name="model">stock.return.picking.memory</field>
786+ <field name="type">tree</field>
787+ <field name="arch" type="xml">
788+ <tree editable="bottom" string="Product Moves">
789+ <field name="product_id" />
790+ <field name="quantity" />
791+
792+ </tree>
793+ </field>
794+ </record>
795+
796+ <record id="stock_return_memory_form_in" model="ir.ui.view">
797+ <field name="name">stock.return.picking.memory.from</field>
798+ <field name="model">stock.return.picking.memory</field>
799+ <field name="type">form</field>
800+ <field name="arch" type="xml">
801+ <form>
802+ <field name="product_id" />
803+ <field name="quantity" />
804+ </form>
805+ </field>
806+ </record>
807+
808+ <record id="view_stock_return_picking_form" model="ir.ui.view">
809+ <field name="name">Return lines</field>
810+ <field name="model">stock.return.picking</field>
811+ <field name="type">form</field>
812+ <field name="arch" type="xml">
813+ <form string="Return lines">
814+ <label string="Provide the quantities of the returned products." colspan="4"/>
815+ <separator string="" colspan="4"/>
816+ <field name="product_return_moves" nolabel="1" colspan="6"/>
817+ <field name="invoice_state" />
818+ <separator string="" colspan="4" />
819+ <group col="2" colspan="4">
820+ <button special="cancel" string="_Cancel" icon="gtk-cancel"/>
821+ <button name="create_returns" string="Return" colspan="1" type="object" icon="gtk-apply" />
822+ </group>
823+ </form>
824+ </field>
825+ </record>
826+
827+ </data>
828 </openerp>
829
830=== removed file 'stock/wizard/stock_split_move.py'
831--- stock/wizard/stock_split_move.py 2011-02-15 13:27:07 +0000
832+++ stock/wizard/stock_split_move.py 1970-01-01 00:00:00 +0000
833@@ -1,124 +0,0 @@
834-# -*- coding: utf-8 -*-
835-##############################################################################
836-#
837-# OpenERP, Open Source Management Solution
838-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
839-#
840-# This program is free software: you can redistribute it and/or modify
841-# it under the terms of the GNU Affero General Public License as
842-# published by the Free Software Foundation, either version 3 of the
843-# License, or (at your option) any later version.
844-#
845-# This program is distributed in the hope that it will be useful,
846-# but WITHOUT ANY WARRANTY; without even the implied warranty of
847-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
848-# GNU Affero General Public License for more details.
849-#
850-# You should have received a copy of the GNU Affero General Public License
851-# along with this program. If not, see <http://www.gnu.org/licenses/>.
852-#
853-##############################################################################
854-
855-from osv import osv, fields
856-
857-class stock_split_move_line(osv.osv_memory):
858- _name = 'stock.move.line.split'
859- _description = "Split Moves"
860-
861- def default_get(self, cr, uid, fields, context=None):
862- """ To get default values for the object.
863- @param self: The object pointer.
864- @param cr: A database cursor
865- @param uid: ID of the user currently logged in
866- @param fields: List of fields for which we want default values
867- @param context: A standard dictionary
868- @return: A dictionary which of fields with values.
869- """
870- if context is None:
871- context = {}
872- res = super(stock_split_move_line, self).default_get(cr, uid, fields, context=context)
873- record_id = context and context.get('active_id', False) or False
874- pick_obj = self.pool.get('stock.picking')
875- pick = pick_obj.browse(cr, uid, record_id, context=context)
876- for m in [line for line in pick.move_lines]:
877- res['move%s'%(m.id)] = m.product_qty
878- return res
879-
880- def view_init(self, cr, uid, fields_list, context=None):
881- """ Creates view dynamically and adding fields at runtime.
882- @param self: The object pointer.
883- @param cr: A database cursor
884- @param uid: ID of the user currently logged in
885- @param context: A standard dictionary
886- @return: New arch of view with new columns.
887- """
888- res = super(stock_split_move_line, self).view_init(cr, uid, fields_list, context=context)
889- record_id = context and context.get('active_id', False) or False
890- if record_id:
891- pick_obj = self.pool.get('stock.picking')
892- try:
893- pick = pick_obj.browse(cr, uid, record_id, context=context)
894- for m in [line for line in pick.move_lines]:
895- if 'move%s' % m.id not in self._columns:
896- self._columns['move%s' % m.id] = fields.float(string=m.product_id.name)
897- except:
898- return res
899- return res
900-
901- def fields_view_get(self, cr, uid, view_id=None, view_type='form',
902- context=None, toolbar=False, submenu=False):
903- """ Changes the view dynamically
904- @param self: The object pointer.
905- @param cr: A database cursor
906- @param uid: ID of the user currently logged in
907- @param context: A standard dictionary
908- @return: New arch of view.
909- """
910- res = super(stock_split_move_line, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
911- record_id = context and context.get('active_id', False) or False
912- assert record_id,'Active ID not found'
913- pick_obj = self.pool.get('stock.picking')
914- pick = pick_obj.browse(cr, uid, record_id, context=context)
915- arch_lst = ['<?xml version="1.0"?>', '<form string="Split lines">', '<label string="Indicate here the quantity of the new line. A quantity of zero will not split the line." colspan="4"/>']
916- for m in [line for line in pick.move_lines]:
917- quantity = m.product_qty
918- arch_lst.append('<field name="move%s" />\n<newline />' % (m.id,))
919- res['fields']['move%s' % m.id] = {'string' : m.product_id.name, 'type' : 'float', 'required' : True}
920- arch_lst.append('<group col="2" colspan="4">')
921- arch_lst.append('<button icon="gtk-cancel" special="cancel" string="Cancel" />')
922- arch_lst.append('<button name="split_lines" string="Split" colspan="1" type="object" icon="gtk-apply" />')
923- arch_lst.append('</group>')
924- arch_lst.append('</form>')
925- res['arch'] = '\n'.join(arch_lst)
926- return res
927-
928- def split_lines(self, cr, uid, ids, context=None):
929- """ Splits moves in quantity given in the wizard.
930- @param self: The object pointer.
931- @param cr: A database cursor
932- @param uid: ID of the user currently logged in
933- @param ids: List of ids selected
934- @param context: A standard dictionary
935- @return: A dictionary which of fields with values.
936- """
937- if context is None:
938- context = {}
939- move_obj = self.pool.get('stock.move')
940- record_id = context and context.get('active_id', False) or False
941- pick_obj = self.pool.get('stock.picking')
942- pick = pick_obj.browse(cr, uid, record_id, context=context)
943- data = self.read(cr, uid, ids[0])
944- for move in pick.move_lines:
945- quantity = data['move%s' % move.id]
946- if 0 < quantity < move.product_qty:
947- new_qty = move.product_qty - quantity
948- new_uos_qty = new_qty / move.product_qty * move.product_uos_qty
949- new_obj = move_obj.copy(cr, uid, move.id, {'product_qty' : new_qty, 'product_uos_qty': new_uos_qty, 'state':move.state})
950- uos_qty = quantity / move.product_qty * move.product_uos_qty
951- move_obj.write(cr, uid, [move.id], {'product_qty' : quantity, 'product_uos_qty': uos_qty})
952- return {'type': 'ir.actions.act_window_close'}
953-
954-stock_split_move_line()
955-
956-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
957-
958
959=== removed file 'stock/wizard/stock_split_move_view.xml'
960--- stock/wizard/stock_split_move_view.xml 2011-01-14 00:11:01 +0000
961+++ stock/wizard/stock_split_move_view.xml 1970-01-01 00:00:00 +0000
962@@ -1,17 +0,0 @@
963-<?xml version="1.0" encoding="utf-8"?>
964-<openerp>
965- <data>
966-
967- <!-- Split Moves -->
968-
969- <record id="act_split_moves" model="ir.actions.act_window">
970- <field name="name">Split Moves</field>
971- <field name="type">ir.actions.act_window</field>
972- <field name="res_model">stock.move.line.split</field>
973- <field name="view_type">form</field>
974- <field name="view_mode">form</field>
975- <field name="target">new</field>
976- </record>
977-
978- </data>
979-</openerp>

Subscribers

People subscribed via source and target branches

to all changes: