Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] purchase_request: use module specific subtypes #2450

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions purchase_request/models/purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@
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")

Check warning on line 168 in purchase_request/models/purchase_request.py

View check run for this annotation

Codecov / codecov/patch

purchase_request/models/purchase_request.py#L168

Added line #L168 was not covered by tests
elif "state" in init_values and record.state == "done":
return self.env.ref("purchase_request.mt_request_done")
return super()._track_subtype(init_values)

Check warning on line 171 in purchase_request/models/purchase_request.py

View check run for this annotation

Codecov / codecov/patch

purchase_request/models/purchase_request.py#L171

Added line #L171 was not covered by tests

@api.depends("line_ids", "line_ids.estimated_cost")
def _compute_estimated_cost(self):
for rec in self:
Expand Down
12 changes: 12 additions & 0 deletions purchase_request/tests/test_purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading