diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index 29e37f9532b..6041bc5163c 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -506,7 +506,7 @@ - + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index a403c141be4..f1b7e34d1d5 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1309,7 +1309,40 @@ class stock_move(osv.osv): wf_service.trg_trigger(uid, 'stock.move', id, cr) #self.action_cancel(cr,uid, ids2, context) return True - + + def action_scrap(self, cr, uid, ids,context=None): + ''' + add the damaged product into consumed product by updating its state to cancel and + add same product since we need that product to manufacture the parent product. + + :param cr: the database cursor + :param uid: the user id + :param ids: ids of product object to be scraped + :param context: context arguments + :return: + ''' +# to find the parent id(manufacturing order) of the active record(product to consume), +# obtain active record id 1st and then get the production_id from mrp_production_move_ids + active_id=ids[0] + cr.execute("select production_id from mrp_production_move_ids where move_id=%s" % (active_id)) +# it gives parent id in [list(tuple)] format so extract it [(21,)] + parent_id = int(cr.fetchall()[0][0]) +# get the parent object + parent_obj = self.pool.get('mrp.production').browse(cr, uid, parent_id) +# create copy for multiple id processing for product to consume which r scraped + for id in ids: + #create copy of the product records which are scraped due to damage since they are + #still required to manufacture the product. + new_rec_id = self.copy(cr, uid, id, {'state': 'waiting'}, context) + + #assign all new products which will replace damaged product to the current manufacturing order + cr.execute('insert into mrp_production_move_ids (production_id,move_id) values (%s,%s)', (parent_id, new_rec_id)) + +# all damaged product needs to be in consumed product window having cancel state. + vals={'state': 'cancel', 'date_planned': time.strftime('%Y-%m-%d %H:%M:%S')} + self.pool.get('stock.move').write(cr, uid, ids,vals ) + + return True def action_done(self, cr, uid, ids, context=None): track_flag = False picking_ids = [] @@ -1563,7 +1596,9 @@ class stock_move(osv.osv): self.write(cr, uid, [move.id], update_val) if consume: - self.action_done(cr, uid, res) + self.action_done(cr, uid, res) + else: + self.action_scrap(cr, uid, res,context) return res def scrap_moves(self, cr, uid, ids, quantity, location_dest_id, context=None):