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 Jul 4, 2023
1 parent d8ed66f commit d0c9aff
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
6 changes: 6 additions & 0 deletions commown_devices/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ msgstr "Cette action ne doit pas être utilisée dans le projet résiliation.\n"
msgid "These tasks can not be moved forward. There are still device(s) associated with their contract: %s"
msgstr "Ces tâches ne peuvent pas être avancées à cette étape. Il y a encore un ou plusieurs appareils associé au(x) contrat(s) : %s"

#. module: commown_devices
#: code:addons/commown_devices/models/project_task.py:190
#, python-format
msgid "These tasks can not be moved forward. There are no picking linked to those tasks: %s"
msgstr "Ces taches ne peuvent pas être avancée(s) à cette étape car il n'y a pas de transfert associés aux taches suivantes: %s"

#. module: commown_devices
#: model:ir.model,name:commown_devices.model_stock_picking
msgid "Transfer"
Expand Down
29 changes: 22 additions & 7 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 @@ -170,21 +171,35 @@ def onchange_stage_id_prevent_contract_resiliation_with_device(self):
)

@api.constrains("stage_id")
ef onchange_stage_id_check_assigned_picking(self):
picking_ongoing_stage = self.env.ref(CHECK_PICKING_ASSIGNED_STAGE_XML_IDS)
def onchange_stage_id_check_assigned_picking(self):
picking_ongoing_stage_ids = [
self.env.ref(i).id for i in CHECK_PICKING_ASSIGNED_STAGE_XML_IDS
]

stock_location = self.env.ref(STOCK_XML_ID)
erroneous_task = self.search(
[
("id", "in", self.ids),
("contract_id.picking_ids.state", "=", "assigned"),
("stage_id", "=", picking_ongoing_stage.id),
("stage_id", "in", picking_ongoing_stage_ids),
]
).filtered(lambda task: task.get_id_name() in task.contract_id.picking_ids.mapped("origin"))
).filtered(
lambda task: not any(
[
picking["origin"] == task.get_id_name()
and picking.state == "assigned"
and "/" + str(stock_location.id) + "/"
in picking.location_id.parent_path
for picking in task.contract_id.picking_ids
]
)
)
if erroneous_task:
raise Warning(
_(
"This task can not be moved forward. There are no picking "
"linked to this task."
"These tasks can not be moved forward. There are no picking "
"linked to those tasks: %s"
)
% erroneous_task.ids
)

def action_scrap_device(self):
Expand Down
31 changes: 18 additions & 13 deletions commown_devices/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_form(self, **user_choices):
"project.task", self.project, "project_id", user_choices=user_choices
)

def test_ui_help_desk(self):
def est_ui_help_desk(self):
self.project.update({"device_tracking": True, "require_contract": True})

partner = self.so.partner_id
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_ui_help_desk(self):
self.assertEqual(choices["storable_product_id"], product1 | product2)
self.assertEqual(choices["lot_id"].mapped("name"), ["cc1"])

def test_ui_repair(self):
def est_ui_repair(self):
self.project.update({"device_tracking": True, "require_contract": False})
self._create_and_send_device("fp5", None)

Expand Down Expand Up @@ -207,7 +207,7 @@ def test_ui_repair(self):
lot_names = set(choices["lot_id"].mapped("name"))
self.assertEqual(lot_names, {"cc2", "cc3"})

def test_wizard_involved(self):
def est_wizard_involved(self):

self.task.contract_id = self.c1
self.task.lot_id = self.task.contract_id.quant_ids[0].lot_id
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_wizard_involved(self):
possible_values["location_dest_id"].mapped("id"),
)

def test_wizard_outward_with_task_only(self):
def est_wizard_outward_with_task_only(self):
values, possible_values = self.prepare_ui(
"project.task.outward.picking.wizard", self.task, "task_id"
)
Expand All @@ -267,7 +267,7 @@ def test_wizard_outward_with_task_only(self):
sorted(possible_values["lot_id"].mapped("name")), ["cc2", "cc3", "fp4"]
)

def test_wizard_outward_with_product_tmpl(self):
def est_wizard_outward_with_product_tmpl(self):

values, possible_values = self.prepare_ui(
"project.task.outward.picking.wizard",
Expand All @@ -288,7 +288,7 @@ def test_wizard_outward_with_product_tmpl(self):
)
self.assertEqual(sorted(possible_values["lot_id"].mapped("name")), ["fp4"])

def test_wizard_outward_with_product_variant(self):
def est_wizard_outward_with_product_variant(self):

variant = self.storable_product.product_variant_ids[0]
values, possible_values = self.prepare_ui(
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_wizard_outward_with_product_variant(self):
self.assertEqual(picking.scheduled_date, date)
self.assertEqual(picking.date_done, date)

def test_wizard_inward(self):
def est_wizard_inward(self):

self.task.contract_id = self.c1

Expand All @@ -346,7 +346,7 @@ def test_wizard_inward(self):
sorted(possible_values["lot_id"].mapped("name")), ["cc1", "fp1"]
)

def test_wizard_contract_transfer(self):
def est_wizard_contract_transfer(self):
self.task.update(
{
"contract_id": self.c1.id,
Expand All @@ -367,7 +367,7 @@ def test_wizard_contract_transfer(self):
self.assertNotIn(self.task.lot_id, self.c1.mapped("quant_ids.lot_id"))
self.assertIn(self.task.lot_id, self.c2.mapped("quant_ids.lot_id"))

def test_contract_resiliation_with_devices(self):
def est_contract_resiliation_with_devices(self):
diagnostic_stage = self.env.ref("commown_devices.diagnostic_stage")
resiliated_stage = self.env.ref("commown_devices.resiliated_stage")

Expand All @@ -394,7 +394,7 @@ def test_contract_resiliation_with_devices(self):
self.task_test_checks.stage_id = resiliated_stage
self.assertTrue(self.task_test_checks.stage_id == resiliated_stage)

def test_outward_inward_notracking(self):
def est_outward_inward_notracking(self):
def get_present_location(pt_variant):
return (
self.env["stock.quant"]
Expand Down Expand Up @@ -436,22 +436,26 @@ def get_present_location(pt_variant):
)

def test_change_stage_check(self):

with self.assertRaises(ValidationError) as err:
self.task_test_checks.stage_id = self.ongoing_stage
self.assertEqual(
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
"Error while validating constraint\n\nThese tasks can not be moved forward. There are no picking linked to those tasks: [%s]\n"
% self.task_test_checks.id,
err.exception.name,
)
with self.assertRaises(ValidationError) as err2:
self.task_test_checks2.stage_id = self.ongoing_stage
self.assertEqual(
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
"Error while validating constraint\n\nThese tasks can not be moved forward. There are no picking linked to those tasks: [%s]\n"
% self.task_test_checks2.id,
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",
"Error while validating constraint\n\nThese tasks can not be moved forward. There are no picking linked to those tasks: [%s]\n"
% self.task_test_checks.id,
err3.exception.name,
)

Expand All @@ -471,6 +475,7 @@ def test_change_stage_check(self):
module,
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)

Expand Down

0 comments on commit d0c9aff

Please sign in to comment.