Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions repair_order_group/models/repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def _compute_grouped_repair_ids(self):
continue
repair.grouped_repair_ids = repair.group_id.repair_ids - repair

def copy(self, default=None):
"""Keep the group only for draft repairs when duplicating.

Duplicating a grouped repair order:
- if original is in Draft -> duplicated repair stays in the same group
- otherwise -> duplicated repair is not assigned to any group
"""
self.ensure_one()
default = dict(default or {})
if self.group_id and self.state != "draft":
default["group_id"] = False
return super().copy(default)

def action_add_another_repair(self):
"""Create a new empty repair linked to the same group.

Expand Down
57 changes: 57 additions & 0 deletions repair_order_group/tests/test_repair_order_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,60 @@ def test_21_cascade_empty_group_repairs(self):

repair.action_repair_cancel()
self.assertEqual(repair.state, "cancel")

def test_22_duplicate_grouped_repair_keeps_group_in_draft(self):
"""Draft repair duplication keeps the same group."""
group = self.env["repair.order.group"].create({"partner_id": self.partner.id})
repair = self.env["repair.order"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_type.id,
"product_id": self.product.id,
"group_id": group.id,
}
)

self.env["repair.service"].create(
{
"repair_id": repair.id,
"product_id": self.product.id,
}
)

duplicated = repair.copy()

self.assertEqual(
duplicated.group_id,
repair.group_id,
"Draft grouped repair should remain in the same group when duplicated.",
)

def test_23_duplicate_grouped_repair_drops_group_outside_draft(self):
"""Non-draft repair duplication must not keep the group."""
group = self.env["repair.order.group"].create({"partner_id": self.partner.id})
repair = self.env["repair.order"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_type.id,
"product_id": self.product.id,
"group_id": group.id,
}
)

self.env["repair.service"].create(
{
"repair_id": repair.id,
"product_id": self.product.id,
}
)

repair.action_validate()
repair._action_repair_confirm()

duplicated = repair.copy()

self.assertFalse(
duplicated.group_id,
"Non-draft grouped repair should not be assigned "
"to a group when duplicated.",
)