Skip to content

Commit

Permalink
Added condition on picking origin to validate stage check
Browse files Browse the repository at this point in the history
Also rewrite to allow mass editing on project task stage_id
  • Loading branch information
louck committed Jun 30, 2023
1 parent 5fd817b commit b90caef
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions commown_devices/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"commown_devices.sup_picking_ongoing_stage",
"commown_devices.picking_sent",
]
STOCK_XML_ID = "stock.stock_location_stock"


class ProjectTask(models.Model):
Expand Down Expand Up @@ -165,25 +166,32 @@ def _check_stage_id_prevent_contract_resiliation_with_device(self):

@api.constrains("stage_id")
def _check_assigned_picking(self):
if self.stage_id and self.contract_id:
check_stage_ids = tuple(
self.env.ref(ref).id for ref in CHECK_PICKING_ASSIGNED_STAGE_XML_IDS
)

if (
self.stage_id.id in check_stage_ids
and not self.contract_id.picking_ids.filtered(
lambda p, task=self: p._assigned()
and p.origin == task.get_id_name()
for record in self:
if record.stage_id and record.contract_id:
check_stage_ids = tuple(
self.env.ref(ref).id for ref in CHECK_PICKING_ASSIGNED_STAGE_XML_IDS
)
):
raise Warning(
_(
"This task can not be moved forward. There are no picking "
"linked to this task."
)
childs_of_stock = self.env["stock.location"].search(
[
("id", "child_of", self.env.ref(STOCK_XML_ID).id),
]
)

if (
record.stage_id.id in check_stage_ids
and not record.contract_id.picking_ids.filtered(
lambda p, task=record: p._assigned()
and p.origin == task.get_id_name()
and p.location_id in childs_of_stock
)
):
raise Warning(
_(
"This task can not be moved forward. There are no picking "
"linked to this task."
)
)

def action_scrap_device(self):
scrap_loc = self.env.ref("stock.stock_location_scrapped")

Expand Down

0 comments on commit b90caef

Please sign in to comment.