diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 6de1a2f542e..12080dd6a8f 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -31,7 +31,7 @@ class StockMove(osv.osv): _inherit = 'stock.move' _columns = { - 'production_id': fields.many2one('mrp.production', 'Production Order for Produced Products', select=True), + 'production_id': fields.many2one('mrp.production', 'Production Order for Produced Products', select=True, copy=False), 'raw_material_production_id': fields.many2one('mrp.production', 'Production Order for Raw Materials', select=True), 'consumed_for': fields.many2one('stock.move', 'Consumed for', help='Technical field used to make the traceability of produced products'), } @@ -192,6 +192,8 @@ class StockMove(osv.osv): quantity_rest_uom = move.product_uom_qty - self.pool.get("product.uom")._compute_qty_obj(cr, uid, move.product_id.uom_id, product_qty, move.product_uom) if float_compare(quantity_rest_uom, 0, precision_rounding=move.product_uom.rounding) != 0: new_mov = self.split(cr, uid, move, quantity_rest, context=context) + if move.production_id: + self.write(cr, uid, [new_mov], {'production_id': move.production_id.id}, context=context) res.append(new_mov) vals = {'restrict_lot_id': restrict_lot_id, 'restrict_partner_id': restrict_partner_id, @@ -223,9 +225,9 @@ class StockMove(osv.osv): production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])]) for prod_id in production_ids: production_obj.signal_workflow(cr, uid, [prod_id], 'button_produce') - for new_move in new_moves: - production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]}) - res.append(new_move) + if move.production_id.id: + self.write(cr, uid, new_moves, {'production_id': move.production_id.id}, context=context) + res.append(new_moves) return res def write(self, cr, uid, ids, vals, context=None):