From 67bd3a5845e9a6119776509b720ca1e592b3b4ad Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 9 Jun 2011 19:32:34 +0530 Subject: [PATCH 1/2] [FIX] stock: Partial shipment impossible bzr revid: rha@tinyerp.com-20110609140234-xyt02s4qur6e3yzs --- addons/stock/wizard/stock_partial_picking.py | 62 ++++++++++++-------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index 3a83e077d5e..4f7a91edff1 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -32,7 +32,7 @@ class stock_partial_picking(osv.osv_memory): 'product_moves_out' : fields.one2many('stock.move.memory.out', 'wizard_id', 'Moves'), 'product_moves_in' : fields.one2many('stock.move.memory.in', 'wizard_id', 'Moves'), } - + def get_picking_type(self, cr, uid, picking, context=None): picking_type = picking.type for move in picking.move_lines: @@ -42,7 +42,7 @@ class stock_partial_picking(osv.osv_memory): else: picking_type = 'out' return picking_type - + def default_get(self, cr, uid, fields, context=None): """ To get default values for the object. @param self: The object pointer. @@ -54,7 +54,7 @@ class stock_partial_picking(osv.osv_memory): """ if context is None: context = {} - + pick_obj = self.pool.get('stock.picking') res = super(stock_partial_picking, self).default_get(cr, uid, fields, context=context) picking_ids = context.get('active_ids', []) @@ -76,10 +76,10 @@ class stock_partial_picking(osv.osv_memory): if 'date' in fields: res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')}) return res - + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) - + pick_obj = self.pool.get('stock.picking') picking_ids = context.get('active_ids', False) @@ -89,7 +89,7 @@ class stock_partial_picking(osv.osv_memory): for pick in pick_obj.browse(cr, uid, picking_ids, context=context): picking_type = self.get_picking_type(cr, uid, pick, context=context) - + _moves_arch_lst = """
@@ -99,7 +99,7 @@ class stock_partial_picking(osv.osv_memory): # add field related to picking type only _moves_fields.update({ - 'product_moves_' + picking_type: {'relation': 'stock.move.memory.'+picking_type, 'type' : 'one2many', 'string' : 'Product Moves'}, + 'product_moves_' + picking_type: {'relation': 'stock.move.memory.'+picking_type, 'type' : 'one2many', 'string' : 'Product Moves'}, }) _moves_arch_lst += """ @@ -116,19 +116,19 @@ class stock_partial_picking(osv.osv_memory): result['fields'] = _moves_fields return result - def __create_partial_picking_memory(self, picking, pick_type): + def __create_partial_picking_memory(self, move, pick_type): move_memory = { - 'product_id' : picking.product_id.id, - 'quantity' : picking.product_qty, - 'product_uom' : picking.product_uom.id, - 'prodlot_id' : picking.prodlot_id.id, - 'move_id' : picking.id, + 'product_id' : move.product_id.id, + 'quantity' : move.product_qty, + 'product_uom' : move.product_uom.id, + 'prodlot_id' : move.prodlot_id.id, + 'move_id' : move.id, } - + if pick_type == 'in': move_memory.update({ - 'cost' : picking.product_id.standard_price, - 'currency' : picking.product_id.company_id and picking.product_id.company_id.currency_id.id or False, + 'cost' : picking.product_id.standard_price, + 'currency' : picking.product_id.company_id and picking.product_id.company_id.currency_id.id or False, }) return move_memory @@ -142,7 +142,7 @@ class stock_partial_picking(osv.osv_memory): @return: A dictionary which of fields with values. """ pick_obj = self.pool.get('stock.picking') - + picking_ids = context.get('active_ids', False) partial = self.browse(cr, uid, ids[0], context=context) partial_datas = { @@ -153,17 +153,33 @@ class stock_partial_picking(osv.osv_memory): picking_type = self.get_picking_type(cr, uid, pick, context=context) moves_list = picking_type == 'in' and partial.product_moves_in or partial.product_moves_out + #Adding a check whether any move has been removed + if len(moves_list) < len(pick.move_lines): + raise osv.except_osv(_('Processing Error'),\ + _('You cannot remove any move while validating the picking, rather you can set the quantity as zero!')) + + #Adding a check whether any move has been added + if len(moves_list) > len(pick.move_lines): + raise osv.except_osv(_('Processing Error'),\ + _('You cannot add any new move while validating the picking, rather you can split the lines prior to validation!')) + for move in moves_list: + + #Adding a check whether any line has been added with new qty + if not move.move_id: + raise osv.except_osv(_('Processing Error'),\ + _('You cannot add any new move while validating the picking, rather you can split the lines prior to validation!')) + partial_datas['move%s' % (move.move_id.id)] = { - 'product_id': move.id, - 'product_qty': move.quantity, - 'product_uom': move.product_uom.id, - 'prodlot_id': move.prodlot_id.id, + 'product_id': move.product_id.id, + 'product_qty': move.quantity, + 'product_uom': move.product_uom.id, + 'prodlot_id': move.prodlot_id.id, } if (picking_type == 'in') and (move.product_id.cost_method == 'average'): partial_datas['move%s' % (move.move_id.id)].update({ - 'product_price' : move.cost, - 'product_currency': move.currency.id, + 'product_price' : move.cost, + 'product_currency': move.currency.id, }) pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context) return {'type': 'ir.actions.act_window_close'} From 6c1d237ef9d5a44cd40b304a4f5ff0cb1f1d2c15 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 30 Jun 2011 17:04:39 +0530 Subject: [PATCH 2/2] [FIX] stock: fix for deleting the move line from wizard bzr revid: rha@tinyerp.com-20110630113439-b2djiuukuf65hbps --- addons/stock/stock.py | 11 +++++------ addons/stock/wizard/stock_partial_picking.py | 16 ++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 5bc4bd3ab8a..c16e2c54a82 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1176,13 +1176,12 @@ class stock_picking(osv.osv): if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) - assert partial_data, _('Missing partial picking data for move #%s') % (move.id) - product_qty = partial_data.get('product_qty',0.0) + product_qty = partial_data and partial_data.get('product_qty') or 0.0 move_product_qty[move.id] = product_qty - product_uom = partial_data.get('product_uom',False) - product_price = partial_data.get('product_price',0.0) - product_currency = partial_data.get('product_currency',False) - prodlot_id = partial_data.get('prodlot_id') + product_uom = partial_data and partial_data.get('product_uom') or False + product_price = partial_data and partial_data.get('product_price') or 0.0 + product_currency = partial_data and partial_data.get('product_currency') or False + prodlot_id = partial_data and partial_data.get('prodlot_id') or False prodlot_ids[move.id] = prodlot_id if move.product_qty == product_qty: complete.append(move) diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index 21af463041f..c926658e0b7 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -154,11 +154,6 @@ class stock_partial_picking(osv.osv_memory): picking_type = self.get_picking_type(cr, uid, pick, context=context) moves_list = picking_type == 'in' and partial.product_moves_in or partial.product_moves_out - #Adding a check whether any move has been removed - if len(moves_list) < len(pick.move_lines): - raise osv.except_osv(_('Processing Error'),\ - _('You cannot remove any move while validating the picking, rather you can set the quantity as zero!')) - #Adding a check whether any move has been added if len(moves_list) > len(pick.move_lines): raise osv.except_osv(_('Processing Error'),\ @@ -171,21 +166,18 @@ class stock_partial_picking(osv.osv_memory): raise osv.except_osv(_('Processing Error'),\ _('You cannot add any new move while validating the picking, rather you can split the lines prior to validation!')) - if len(moves_list) == 1 and move.quantity == 0: - raise osv.except_osv(_('Processing Error'), \ - _('bass la na kar!!')) - calc_qty = uom_obj._compute_qty(cr, uid, move.product_uom.id, \ move.quantity, move.move_id.product_uom.id) #Adding a check whether any move line contains exceeding qty to original moveline if calc_qty > move.move_id.product_qty: raise osv.except_osv(_('Processing Error'), - _('Processing quantity %d for %s is larger than the available quantity %d !')\ - %(move.quantity, move.product_id.name, move.move_id.product_qty)) + _('Processing quantity %d %s for %s is larger than the available quantity %d %s !')\ + %(move.quantity, move.product_uom.name, move.product_id.name,\ + move.move_id.product_qty, move.move_id.product_uom.name)) #Adding a check whether any move line contains qty less than zero - if calc_qty < 0: + if calc_qty <= 0: raise osv.except_osv(_('Processing Error'), \ _('Can not process quantity %d for Product %s !') \ %(move.quantity, move.product_id.name))