diff --git a/commown_devices/models/stock_move_line.py b/commown_devices/models/stock_move_line.py
index daff0879..8b317d61 100644
--- a/commown_devices/models/stock_move_line.py
+++ b/commown_devices/models/stock_move_line.py
@@ -26,6 +26,23 @@ def _compute_show_validate_picking(self):
rec.move_id.picking_id and rec.move_id.picking_id.state == "assigned"
)
+ def action_open_parent(self):
+ if self.move_id.scrap_ids:
+ res_model = "stock.scrap"
+ res_id = self.move_id.scrap_ids.id
+ else:
+ res_model = "stock.picking"
+ res_id = self.move_id.picking_id.id
+ return {
+ "name": "Source",
+ "type": "ir.actions.act_window",
+ "view_type": "form",
+ "view_mode": "form",
+ "res_model": res_model,
+ "res_id": res_id,
+ "target": "new",
+ }
+
def action_validate_linked_picking(self):
unvalidated_contract_ml = self.move_id.contract_id.move_line_ids.filtered(
lambda ml: ml.state == "assigned"
diff --git a/commown_devices/tests/test_stock_move_line.py b/commown_devices/tests/test_stock_move_line.py
index f7b6b9c8..57941069 100644
--- a/commown_devices/tests/test_stock_move_line.py
+++ b/commown_devices/tests/test_stock_move_line.py
@@ -88,3 +88,45 @@ def test_action_validate_linked_picking(self):
# When only obe unvalidated move, the picking is validated directly
self.move_line2.action_validate_linked_picking()
self.assertEqual(self.picking2.state, "done")
+
+ def test_action_open_parent(self):
+ # Check result on picking move line
+ expected_result = {
+ "name": "Source",
+ "type": "ir.actions.act_window",
+ "view_type": "form",
+ "view_mode": "form",
+ "res_model": "stock.picking",
+ "res_id": self.picking1.id,
+ "target": "new",
+ }
+ self.assertEqual(self.move_line1.action_open_parent(), expected_result)
+
+ # Create scrap
+ self.picking2.button_validate()
+ lot = self.move_line2.lot_id
+ scrap_loc = self.env.ref("stock.stock_location_scrapped")
+ scrap = self.env["stock.scrap"].create(
+ {
+ "product_id": lot.product_id.id,
+ "lot_id": lot.id,
+ "location_id": self.picking2.location_dest_id.id,
+ "scrap_location_id": scrap_loc.id,
+ "product_uom_id": lot.product_id.uom_id.id,
+ "date_expected": self.picking2.date_done,
+ }
+ )
+ scrap.action_validate()
+ scrap_move_line = scrap.move_id.move_line_ids
+
+ # Check result on a scrap
+ expected_result = {
+ "name": "Source",
+ "type": "ir.actions.act_window",
+ "view_type": "form",
+ "view_mode": "form",
+ "res_model": "stock.scrap",
+ "res_id": scrap.id,
+ "target": "new",
+ }
+ self.assertEqual(scrap_move_line.action_open_parent(), expected_result)
diff --git a/commown_devices/views/contract.xml b/commown_devices/views/contract.xml
index a6753739..9f038905 100644
--- a/commown_devices/views/contract.xml
+++ b/commown_devices/views/contract.xml
@@ -30,6 +30,7 @@
>
+