From 819f2a33feaaac3924479513e3b5db3b87359191 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Fri, 19 Feb 2010 16:21:45 +0530 Subject: [PATCH 01/11] [IMP]: stock: Improvement for wizards of consume and scrap moves + converted simple wizards to osv_memory wizards bzr revid: rpa@openerp.co.in-20100219105145-f9pvx6g8ua9fjq0r --- addons/stock/__init__.py | 2 + addons/stock/__terp__.py | 1 + addons/stock/stock.py | 117 +++++++++++++++++++ addons/stock/stock_osv_wizards.xml | 102 +++++++++++++++++ addons/stock/stock_wizard.py | 107 ++++++++++++++++++ addons/stock/stock_wizard.xml | 10 +- addons/stock/wizard/__init__.py | 2 +- addons/stock/wizard/wizard_track_line.py | 138 ----------------------- 8 files changed, 332 insertions(+), 147 deletions(-) create mode 100644 addons/stock/stock_osv_wizards.xml create mode 100644 addons/stock/stock_wizard.py delete mode 100644 addons/stock/wizard/wizard_track_line.py diff --git a/addons/stock/__init__.py b/addons/stock/__init__.py index 216fa82d01a..d728efbf2fe 100644 --- a/addons/stock/__init__.py +++ b/addons/stock/__init__.py @@ -27,6 +27,8 @@ import report import wizard import report_stock +import stock_wizard + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/__terp__.py b/addons/stock/__terp__.py index 7ddf97553de..f492b6b0ed9 100644 --- a/addons/stock/__terp__.py +++ b/addons/stock/__terp__.py @@ -45,6 +45,7 @@ Thanks to the double entry management, the inventory controlling is powerful and "stock_data.xml", "stock_incoterms.xml", "stock_wizard.xml", + "stock_osv_wizards.xml", "stock_view.xml", "stock_report.xml", "stock_sequence.xml", diff --git a/addons/stock/stock.py b/addons/stock/stock.py index b7e43705fd1..66a65602e50 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1493,6 +1493,123 @@ class stock_move(osv.osv): return super(stock_move, self).unlink( cr, uid, ids, context=context) + def _track_lines(self, cr, uid, ids, data, context=None): + move_obj = self.pool.get('stock.move').browse(cr, uid, ids) + prodlot_obj = self.pool.get('stock.production.lot') + ir_sequence_obj = self.pool.get('ir.sequence') + + sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial') + if not sequence: + raise wizard.except_wizard(_('Error!'), _('No production sequence defined')) + if data['tracking_prefix']: + sequence=data['tracking_prefix']+'/'+(sequence or '') + + move = self.browse(cr, uid, [ids])[0] + + quantity=data['quantity'] + if quantity <= 0 or move.product_qty == 0: + return {} + uos_qty=quantity/move.product_qty*move.product_uos_qty + + quantity_rest = move.product_qty%quantity + uos_qty_rest = quantity_rest/move.product_qty*move.product_uos_qty + + update_val = { + 'product_qty': quantity, + 'product_uos_qty': uos_qty, + } + new_move = [] + for idx in range(int(move.product_qty//quantity)): + if idx: + current_move = self.copy(cr, uid, move.id, {'state': move.state}) + new_move.append(current_move) + else: + current_move = move.id + new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id}) + update_val['prodlot_id'] = new_prodlot + self.write(cr, uid, [current_move], update_val) + + if quantity_rest > 0: + idx = int(move.product_qty//quantity) + update_val['product_qty']=quantity_rest + update_val['product_uos_qty']=uos_qty_rest + if idx: + current_move = self.copy(cr, uid, move.id, {'state': move.state}) + new_move.append(current_move) + else: + current_move = move.id + new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id}) + update_val['prodlot_id'] = new_prodlot + self.write(cr, uid, [current_move], update_val) + return new_move + + def split_moves(self, cr, uid, ids, datas, context=None): + new_move = None + if not context: + context = {} + qty = datas['product_qty'] + if qty <= 0: + raise wizard.except_wizard(_('Warning!'), _('Please provide Proper Quantity !')) + + move = self.browse(cr, uid, ids, context=context) + move_qty = move.product_qty + + if qty > move_qty: + qty = move_qty + rest = 0 + + if qty <= move_qty: + rest= move_qty - qty + vals = { + 'product_qty' : qty, + 'product_uos_qty': qty, + 'location_id': datas['location_id'], + } + track = move.product_id.track_production + self.write(cr, uid, move.id, vals) + if track: + data = {'tracking_prefix': '', 'quantity': 1} + newmoves = self._track_lines(cr, uid, ids, data, context=None) + self.action_done(cr, uid, [move.id]) + + if rest: + defaults = {'product_qty': rest, + 'product_uos_qty': rest, + 'state': move.state} + new_move = self.copy(cr, uid, move.id, default=defaults) + return new_move + + def scrap_moves(self, cr, uid, ids, datas, context=None): + new_move = None + qty = datas['product_qty'] + if qty <= 0: + raise wizard.except_wizard(_('Warning!'), _('Please provide Proper Quantity !')) + + move = self.browse(cr, uid, ids, context=context) + location = move.location_dest_id.id + move_qty = move.product_qty + + if qty > move_qty: + qty = move_qty + rest = 0 + + if qty <= move_qty: + rest= move_qty - qty + vals = { + 'product_qty': qty, + 'state': move.state, + 'location_dest_id': datas['location_id'] + } + self.write(cr, uid, ids, vals) + + if rest: + defaults = {'product_qty': rest, + 'product_uos_qty': rest, + 'location_dest_id': location, + 'state': move.state} + new_move = self.copy(cr, uid, move.id, default=defaults) + return new_move + stock_move() diff --git a/addons/stock/stock_osv_wizards.xml b/addons/stock/stock_osv_wizards.xml new file mode 100644 index 00000000000..ad5b74a6cce --- /dev/null +++ b/addons/stock/stock_osv_wizards.xml @@ -0,0 +1,102 @@ + + + + + + Tracking a move + stock.move.track + form + +
+ + + + +