diff --git a/commown_devices/models/crm_lead.py b/commown_devices/models/crm_lead.py index 7f16de4b5..7518693f2 100644 --- a/commown_devices/models/crm_lead.py +++ b/commown_devices/models/crm_lead.py @@ -32,15 +32,11 @@ def action_generate_picking(self): "context": {"default_lead_id": self.id}, } - @api.multi - def write(self, values): - res = super().write(values) - stage_id = values.get("stage_id") - if stage_id: - stage = self.env["crm.stage"].browse(stage_id) - if "[stock: check-has-picking]" in stage.name: + @api.constrains("stage_id") + def _check_picking_on_stage_change(self): + if self.stage_id.name: + if "[stock: check-has-picking]" in self.stage_id.name: self.action_check_waiting_picking() - return res def action_check_waiting_picking(self): if self.so_line_id.product_id.product_tmpl_id.storable_product_id: diff --git a/commown_devices/tests/test_crm_lead.py b/commown_devices/tests/test_crm_lead.py index 6ea453b6e..d438737bd 100644 --- a/commown_devices/tests/test_crm_lead.py +++ b/commown_devices/tests/test_crm_lead.py @@ -1,5 +1,5 @@ from odoo import fields -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from .common import DeviceAsAServiceTC @@ -21,9 +21,10 @@ def test_picking_confirmation_on_delivery(self): # Should not be able to put the lead to a "go" column without a picking: stage = self.env["crm.stage"].create({"name": "GO [stock: check-has-picking]"}) - with self.assertRaises(UserError) as err: - lead.stage_id = stage.id - self.assertEqual("Lead has no assigned picking.", err.exception.name) + with self.assertRaises(ValidationError): + with self.assertRaises(UserError) as err: + lead.stage_id = stage.id + self.assertEqual("Lead has no assigned picking.", err.exception.name) picking = lead.contract_id.send_device(quant) self.assertEqual(picking.mapped("move_lines.product_qty"), [1.0]) diff --git a/commown_devices/tests/test_project_task.py b/commown_devices/tests/test_project_task.py index 2661e8cc3..9a0dda7e7 100644 --- a/commown_devices/tests/test_project_task.py +++ b/commown_devices/tests/test_project_task.py @@ -7,16 +7,6 @@ class ProjectTaskPickingTC(DeviceAsAServiceTC): - def _create_xml_id(self, record, name): - return self.env["ir.model.data"].create( - { - "module": "commown_devices", - "name": name, - "model": record._name, - "res_id": record.id, - } - ) - def setUp(self): super().setUp() @@ -58,20 +48,7 @@ def setUp(self): } ) # for checks on stage change tests - self.ongoing_stage = self.env["project.task.type"].create( - {"name": "Test Ongoing Stage"} - ) - self._create_xml_id(self.ongoing_stage, "sup_picking_ongoing_stage") - - # Create stage to assign xml_ids so constrains on stage_id pass - t1, t2 = self.env["project.task.type"].create( - [ - {"name": "t1"}, - {"name": "t2"}, - ] - ) - self._create_xml_id(t1, "diagnostic_stage") - self._create_xml_id(t2, "resiliated_stage") + self.ongoing_stage = self.env.ref("commown_devices.sup_picking_ongoing_stage") # Create a unused product and an unused service self.env["product.template"].create(