From 4e26a9025d7f380eb4cddccf927703e6572f5395 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Thu, 10 Nov 2011 11:46:39 +0530 Subject: [PATCH] [IMP] stock: Refectoring whole code after merged with addons bzr revid: ron@tinyerp.com-20111110061639-urd36emcw2gl6ne2 --- addons/stock/stock.py | 11 +++---- addons/stock/wizard/stock_partial_picking.py | 32 ++++++++++++++++++- .../wizard/stock_partial_picking_view.xml | 6 ++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 576c23366fa..0f1e47ec17a 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1168,7 +1168,7 @@ class stock_picking(osv.osv): for pick in self.browse(cr, uid, ids, context=context): new_picking = None complete, too_few = [], [] - move_product_qty,prodlot_ids, product_uoms, product_avail, partial_qty = {}, {}, {}, {}, {} + move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms = {},{}, {},{},{} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue @@ -1221,8 +1221,6 @@ class stock_picking(osv.osv): for move in too_few: - if move.product_qty < partial_qty[move.id]: - raise osv.except_osv(_('Error !'), _('You cannot select Quantity %s more then Picking Quantity %s.') % (partial_qty[move.id],move.product_qty,)) product_qty = move_product_qty[move.id] if not new_picking: new_picking = self.copy(cr, uid, pick.id, @@ -1239,7 +1237,7 @@ class stock_picking(osv.osv): 'state': 'assigned', 'move_dest_id': False, 'price_unit': move.price_unit, - 'product_uom':product_uoms[move.id], + 'product_uom':product_uoms[move.id] } prodlot_id = prodlot_ids[move.id] if prodlot_id: @@ -1254,11 +1252,10 @@ class stock_picking(osv.osv): if new_picking: move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking}) for move in complete: - product_qty = move_product_qty[move.id] - defaults = {'product_uom': product_uoms[move.id],'product_qty': product_qty} + defaults = {'product_uom': product_uoms[move.id],'product_qty': move_product_qty[move.id]} if prodlot_ids.get(move.id): defaults.update({'prodlot_id': prodlot_ids[move.id]}) - move_obj.write(cr, uid, move.id, defaults) + move_obj.write(cr, uid, [move.id], defaults) # At first we confirm the new picking (if necessary) if new_picking: diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index d617ea2b5da..8b71e6502eb 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -22,12 +22,25 @@ import time from osv import fields, osv from tools.misc import DEFAULT_SERVER_DATETIME_FORMAT +from tools.translate import _ class stock_partial_picking_line(osv.TransientModel): + + def _tracking(self, cursor, user, ids, name, arg, context=None): + res = {} + for tracklot in self.browse(cursor, user, ids, context=context): + tracking = False + if (tracklot.move_id.picking_id.type == 'in' and tracklot.product_id.track_incoming == True) or \ + (tracklot.move_id.picking_id.type == 'out' and tracklot.product_id.track_outgoing == True): + tracking = True + res[tracklot.id] = tracking + return res + + _name = "stock.partial.picking.line" _rec_name = 'product_id' _columns = { - 'product_id' : fields.many2one('product.product', string="Product", required=True, ondelete='CASCADE'), + 'product_id' : fields.many2one('product.product', string="Product", required=True, readonly=True, ondelete='CASCADE'), 'quantity' : fields.float("Quantity", required=True), 'product_uom': fields.many2one('product.uom', 'Unit of Measure', required=True, ondelete='CASCADE'), 'prodlot_id' : fields.many2one('stock.production.lot', 'Production Lot', ondelete='CASCADE'), @@ -38,6 +51,7 @@ class stock_partial_picking_line(osv.TransientModel): 'update_cost': fields.boolean('Need cost update'), 'cost' : fields.float("Cost", help="Unit Cost for this product line"), 'currency' : fields.many2one('res.currency', string="Currency", help="Currency in which Unit cost is expressed", ondelete='CASCADE'), + 'tracking': fields.function(_tracking, method=True, string='Tracking', type='boolean'), } class stock_partial_picking(osv.osv_memory): @@ -103,13 +117,29 @@ class stock_partial_picking(osv.osv_memory): assert len(ids) == 1, 'Partial picking processing may only be done one at a time' stock_picking = self.pool.get('stock.picking') stock_move = self.pool.get('stock.move') + uom_obj = self.pool.get('product.uom') partial = self.browse(cr, uid, ids[0], context=context) partial_data = { 'delivery_date' : partial.date } picking_type = partial.picking_id.type for move in partial.move_ids: + move_uom = move.move_id.product_uom + process_uom = move.product_uom move_id = move.move_id.id + + #Quantiny must be Positive + if move.quantity <= 0: + raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !')) + #Pikcing move product UOM factor must be bigger with respective wizard move product uom factor + if move_uom.factor < process_uom.factor: + raise osv.except_osv(_('Warning'), _('You can not process in UOM "%s" which is smaller than UOM "%s" of the current move.') % (process_uom.name, move_uom.name)) + #Compute the wizard Quantity for respective move. + toprocess = uom_obj._compute_qty(cr, uid, process_uom.id, move.quantity, move_uom.id) + #Compare wizard Quantity with respective picking move quantity if wizard move quantity bigger then it's giving warning. + if toprocess > move.move_id.product_qty: + raise osv.except_osv(_('Warning'), _('You can not process "%s %s" as the qty is more than "%s %s" of respective move.') % (move.quantity, process_uom.name, move.move_id.product_qty, move_uom.name)) + if not move_id: seq_obj_name = 'stock.picking.' + picking_type move_id = stock_move.create(cr,uid,{'name' : self.pool.get('ir.sequence').get(cr, uid, seq_obj_name), diff --git a/addons/stock/wizard/stock_partial_picking_view.xml b/addons/stock/wizard/stock_partial_picking_view.xml index be85d266673..396c53694e3 100644 --- a/addons/stock/wizard/stock_partial_picking_view.xml +++ b/addons/stock/wizard/stock_partial_picking_view.xml @@ -38,7 +38,8 @@ - + + @@ -56,7 +57,8 @@ - + +