Skip to content

Commit

Permalink
Added control on picking sent stage
Browse files Browse the repository at this point in the history
  • Loading branch information
louck committed Apr 6, 2023
1 parent 2e734f9 commit 8bdecff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions commown_devices/data/project_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<field name="name">Diagnostic stage</field>
</record>

<record id="picking_sent" model="project.task.type">
<field name="name">Picking sent stage</field>
</record>

<record id="sup_picking_ongoing_stage" model="project.task.type">
<field name="name">Picking ongoing stage</field>
</record>
Expand Down
12 changes: 9 additions & 3 deletions commown_devices/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"commown_devices.resiliated_stage",
]

CHECK_PICKING_ASSIGNED_STAGE_XML_IDS = "commown_devices.sup_picking_ongoing_stage"
CHECK_PICKING_ASSIGNED_STAGE_XML_IDS = [
"commown_devices.sup_picking_ongoing_stage",
"commown_devices.picking_sent",
]


class ProjectTask(models.Model):
Expand Down Expand Up @@ -163,9 +166,12 @@ 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:
picking_ongoing_stage = self.env.ref(CHECK_PICKING_ASSIGNED_STAGE_XML_IDS)
check_stage_ids = tuple(
self.env.ref(ref).id for ref in CHECK_PICKING_ASSIGNED_STAGE_XML_IDS
)

if (
self.stage_id.id == picking_ongoing_stage.id
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()
Expand Down
12 changes: 12 additions & 0 deletions commown_devices/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def setUp(self):
) # for checks on stage change tests

self.ongoing_stage = self.env.ref("commown_devices.sup_picking_ongoing_stage")
self.picking_sent_stage = self.env.ref("commown_devices.picking_sent")

# Create a unused product and an unused service
self.env["product.template"].create(
Expand Down Expand Up @@ -454,6 +455,12 @@ def test_change_task_check(self):
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
err2.exception.name,
)
with self.assertRaises(ValidationError) as err3:
self.task_test_checks.stage_id = self.picking_sent_stage
self.assertEqual(
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
err3.exception.name,
)

module = self.nontracked_product.product_variant_id
lot = self.storable_product.product_variant_id
Expand All @@ -471,9 +478,14 @@ def test_change_task_check(self):
origin=self.task_test_checks.get_id_name(),
)
self.task_test_checks.stage_id = self.ongoing_stage
self.assertTrue(self.task_test_checks.stage_id == self.ongoing_stage)

self.task_test_checks2.contract_id.send_device(
quant,
origin=self.task_test_checks2.get_id_name(),
)
self.task_test_checks2.stage_id = self.ongoing_stage
self.assertTrue(self.task_test_checks2.stage_id == self.ongoing_stage)

self.task_test_checks.stage_id = self.picking_sent_stage
self.assertTrue(self.task_test_checks.stage_id == self.picking_sent_stage)

0 comments on commit 8bdecff

Please sign in to comment.