[FIX] mrp: avoid a traceback when using SN in a transfer

Steps to reproduce the bug:
- Go to Inventory→ Configuration→ Warehouse Management →Operations Types
- Go inside “Receipts”, and enable the checkbox “Create New Lots/Serial
Numbers for Components” and `Use Existing Lots/Serial Numbers`under the
traceability section
- Create a receipt transfers with a traceable product
- Mark as to do the transfer
- Try to add a SN for the product

Problem:
Traceback is triggered: “key error: raw_material_production_id”
because we use this field to add it in the context from the parent in
the `stock.move.line` view:
https://github.com/odoo/odoo/blob/15.0/addons/mrp/views/stock_move_views .xml#L53

But this field is not present in all views of the `stock.move` model

Solution:
To avoid adding this field in all the `stock.move` views, it is better
to add it in the context from the `python` code

closes odoo/odoo#98110

X-original-commit: 545713ae0a559e7f2747dd3cb4211ab752e1ef0c
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-08-16 09:19:28 +02:00
committed by Adrien Widart
parent d2291a4f90
commit f4e9e15618
2 changed files with 2 additions and 4 deletions
+1
View File
@@ -357,6 +357,7 @@ class StockMove(models.Model):
action['views'] = [(self.env.ref('mrp.view_stock_move_operations_raw').id, 'form')]
action['context']['show_destination_location'] = False
action['context']['force_manual_consumption'] = True
action['context']['active_mo_id'] = self.raw_material_production_id.id
elif self.production_id:
action['views'] = [(self.env.ref('mrp.view_stock_move_operations_finished').id, 'form')]
action['context']['show_source_location'] = False
+1 -4
View File
@@ -21,9 +21,6 @@
<xpath expr="//label[@for='quantity_done']" position="attributes">
<attribute name="string">Consumed</attribute>
</xpath>
<xpath expr="//field[@name='quantity_done']" position='after'>
<field name="raw_material_production_id" invisible="1"/>
</xpath>
</field>
</record>
@@ -50,7 +47,7 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='lot_id']" position="attributes">
<attribute name="context">{
'active_mo_id': parent.raw_material_production_id,
'active_mo_id': context.get('active_mo_id'),
'active_picking_id': picking_id,
'default_company_id': parent.company_id,
'default_product_id': parent.product_id,