[FIX] mrp, stock: Duplicate Detailed Operations

Steps to reproduce the bug:

- Create a stockable product P tracked by serial number with route BUY
- Create PO with 5 P and validate the PO
- On the picking, just set one serial number and create a backorder
- Go on the backorder

Bug:

8 lines were created:
    - 4 lines with one reserved quantity
    - 4 lines with no reserved quantity

Now only 4 lines with one reserved quantity are created.

opw:1847714
This commit is contained in:
Goffin Simon
2018-06-12 10:01:18 +02:00
parent 651a7bdada
commit bf3bb5ef50
3 changed files with 27 additions and 8 deletions
+7
View File
@@ -73,6 +73,13 @@ class StockMove(models.Model):
order_finished_lot_ids = fields.Many2many('stock.production.lot', compute='_compute_order_finished_lot_ids')
finished_lots_exist = fields.Boolean('Finished Lots Exist', compute='_compute_order_finished_lot_ids')
def _unreserve_initial_demand(self, new_move):
# If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move
self.filtered(lambda m: m.production_id or m.raw_material_production_id)\
.mapped('move_line_ids')\
.filtered(lambda ml: ml.qty_done == 0.0)\
.write({'move_id': new_move, 'product_uom_qty': 0})
@api.depends('active_move_line_ids.qty_done', 'active_move_line_ids.product_uom_id')
def _compute_done_quantity(self):
super(StockMove, self)._compute_done_quantity()
+4 -3
View File
@@ -1067,6 +1067,9 @@ class StockMove(models.Model):
break
return extra_move
def _unreserve_initial_demand(self, new_move):
pass
def _action_done(self):
self.filtered(lambda move: move.state == 'draft')._action_confirm() # MRP allows scrapping draft moves
@@ -1107,9 +1110,7 @@ class StockMove(models.Model):
move_line.write({'product_uom_qty': move_line.qty_done})
except UserError:
pass
# If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move
move.move_line_ids.filtered(lambda x: x.qty_done == 0.0).write({'move_id': new_move, 'product_uom_qty': 0})
move._unreserve_initial_demand(new_move)
move.move_line_ids._action_done()
# Check the consistency of the result packages; there should be an unique location across
# the contained quants.
+16 -5
View File
@@ -1753,16 +1753,27 @@ class StockMove(TransactionCase):
backorder_wizard = self.env[(res_dict_for_back_order.get('res_model'))].browse(res_dict_for_back_order.get('res_id'))
backorder_wizard.with_context(debug=True).process()
backorder = self.env['stock.picking'].search([('backorder_id', '=', picking_pack_cust.id)])
backordered_ml = backorder.move_line_ids
quant_lot3 = self.env['stock.quant'].search([('lot_id', '=', backordered_ml.lot_id.id)])
backordered_move = backorder.move_lines
# due to the rounding, the backordered quantity is 0.999 ; we shoudln't be able to reserve
# 0.999 on a tracked by serial number quant
self.assertEqual(backordered_ml.product_uom_qty, 0)
self.assertTrue(backordered_ml.lot_id)
backordered_move._action_assign()
self.assertEqual(backordered_move.reserved_availability, 0)
# force the serial number and validate
backordered_ml.qty_done = 1
lot3 = self.env['stock.production.lot'].search([('name', '=', "lot3")])
backorder.write({'move_line_ids': [(0, 0, {
'product_id': self.product2.id,
'product_uom_id': self.uom_unit.id,
'qty_done': 1,
'product_uom_qty': 0,
'lot_id': lot3.id,
'package_id': False,
'result_package_id': False,
'location_id': backordered_move.location_id.id,
'location_dest_id': backordered_move.location_dest_id.id,
'move_id': backordered_move.id,
})]})
overprocessed_wizard = backorder.button_validate()
overprocessed_wizard = self.env['stock.overprocessed.transfer'].browse(overprocessed_wizard['res_id'])