Skip to content

Commit

Permalink
Add a button to display the parent of a move
Browse files Browse the repository at this point in the history
  • Loading branch information
louck committed Sep 24, 2024
1 parent 561db95 commit 8f00176
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions commown_devices/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 42 additions & 0 deletions commown_devices/tests/test_stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions commown_devices/views/contract.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
>
<field name="is_contract_in" invisible="1"/>
<field name="show_validate_picking" invisible="1"/>
<button string="Source" class="oe_highlight" type="object" name="action_open_parent"/>
<field name="product_id"/>
<field name="lot_id"/>
<field name="location_id"/>
Expand Down

0 comments on commit 8f00176

Please sign in to comment.