Skip to content

Commit cd91426

Browse files
committed
[FIX] mrp: update the “stock.move” name after the MO creation
Steps to reproduce the bug: - Create a storable product “P1” with BOM: - component: 1 unit of “C1” - Consumption: Flexible - Create a MO to produce one “P1”: - Click on “Mark as todo” - Click on “produce” - In the window that opens, add one unit of "C1" in new line - Confirm the MO - Go to the product form of “C1”: - Click on the traceability button Problem: The `stock.move` for the additional unit component(not initially planned in the Bill of materials) is with reference “New” instead of the MO name Bug: The first `stock.move` will be created with the name `New` and after the MO creation, its reference will be updated but not its name: https://github.com/odoo/odoo/blob/13241c7a0ebb93998cd918b839e7372f332ec7b1/addons/mrp/models/mrp_production.py#L504-L508 So when an additional unit of the component will be added, the `_create_extra_move` function will be called, therefore a copy of the first stock.move will be made: https://github.com/odoo/odoo/blob/13.0/addons/stock/models/stock_move.py#L1371 But as its name is `new` the new `stock.move` will have the same name and its reference will be calculated based on the name: https://github.com/odoo/odoo/blob/0b9105cc2c02a714bf5c9a2f554cc181169838af/addons/stock/models/stock_move.py#L212-L215 opw-2839202 closes odoo#90926 Signed-off-by: Arnold Moyaux (arm) <[email protected]>
1 parent 3955d48 commit cd91426

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

addons/mrp/models/mrp_production.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ def create(self, values):
538538
production = super(MrpProduction, self).create(values)
539539
production.move_raw_ids.write({
540540
'group_id': production.procurement_group_id.id,
541-
'reference': production.name, # set reference when MO name is different than 'New'
542541
})
543542
# Trigger move_raw creation when importing a file
544543
if 'import_file' in self.env.context:

addons/mrp/models/stock_move.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ def _compute_is_done(self):
125125
for move in self:
126126
move.is_done = (move.state in ('done', 'cancel'))
127127

128+
@api.depends('raw_material_production_id.name')
129+
def _compute_reference(self):
130+
not_prod_move = self.env['stock.move']
131+
for move in self:
132+
if not move.raw_material_production_id:
133+
not_prod_move |= move
134+
continue
135+
move.write({
136+
'name': move.raw_material_production_id.name,
137+
'reference': move.raw_material_production_id.name,
138+
})
139+
super(StockMove, not_prod_move)._compute_reference()
140+
128141
@api.model
129142
def default_get(self, fields_list):
130143
defaults = super(StockMove, self).default_get(fields_list)

0 commit comments

Comments
 (0)