From 4fc55eee810988e57355683e2df606dd7a565f6b Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Thu, 7 Nov 2024 11:41:08 -0500 Subject: [PATCH] [FIX] purchase_request: use module specific subtypes. Currently changes on status is using the Notes subtype instead the specific defined ones in this module --- purchase_request/models/purchase_request.py | 13 +++++++++++++ purchase_request/tests/test_purchase_request.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/purchase_request/models/purchase_request.py b/purchase_request/models/purchase_request.py index 9d028d9ae78..65687b212e1 100644 --- a/purchase_request/models/purchase_request.py +++ b/purchase_request/models/purchase_request.py @@ -157,6 +157,19 @@ def _compute_is_editable(self): store=True, ) + def _track_subtype(self, init_values): + if self: + record = self[0] + if "state" in init_values and record.state == "to_approve": + return self.env.ref("purchase_request.mt_request_to_approve") + elif "state" in init_values and record.state == "approved": + return self.env.ref("purchase_request.mt_request_approved") + elif "state" in init_values and record.state == "rejected": + return self.env.ref("purchase_request.mt_request_rejected") + elif "state" in init_values and record.state == "done": + return self.env.ref("purchase_request.mt_request_done") + return super()._track_subtype(init_values) + @api.depends("line_ids", "line_ids.estimated_cost") def _compute_estimated_cost(self): for rec in self: diff --git a/purchase_request/tests/test_purchase_request.py b/purchase_request/tests/test_purchase_request.py index 5935beddaf7..6ae63c50b90 100644 --- a/purchase_request/tests/test_purchase_request.py +++ b/purchase_request/tests/test_purchase_request.py @@ -242,3 +242,15 @@ def test_purchase_request_unlink(self): pr.button_draft() self.assertEqual(pr.state, "draft", "Should be in state draft") pr_lines.unlink() + + def test_tracking(self): + """Tests Purchase Request tracking. + changes on status should use the proper mail subtypes""" + purchase_request = self.purchase_request + purchase_request.message_subscribe( + partner_ids=[self.env.ref("base.user_demo").partner_id.id] + ) + purchase_request.button_to_approve() + subtype = purchase_request._track_subtype({"state": "to_approve"}) + to_approve_subtype = self.env.ref("purchase_request.mt_request_to_approve") + self.assertEqual(subtype, to_approve_subtype)