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

add a play_onchange on partner_id to be coherent with the UI #3

Merged
merged 3 commits into from
Aug 31, 2023
Merged
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
1 change: 1 addition & 0 deletions helpdesk_mgmt_rest_api/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"helpdesk_mgmt",
"base_rest",
"base_rest_attachment",
"onchange_helper",
],
"external_dependencies": {
"python": [
Expand Down
10 changes: 10 additions & 0 deletions helpdesk_mgmt_rest_api/services/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def search(self):
def create(self, ticket: HelpdeskTicketRequest) -> HelpdeskTicketInfo:
vals = self._prepare_params(ticket.dict(), mode="create")
record = self.env[self._expose_model].create(vals)
if "partner_id" in vals:
vals.update(
record.play_onchanges(
vals,
[
"partner_id",
],
)
)
record.write(vals)
return HelpdeskTicketInfo.from_orm(record)

@restapi.method(
Expand Down
12 changes: 12 additions & 0 deletions helpdesk_mgmt_rest_api/tests/test_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@ def test_ticket_message(self):
message_data = {"body": "Also here is a picture"}
self.service.dispatch("message_post", ticket.id, params=message_data)
self.assertEqual(len(ticket.message_ids), 2) # There is a technical message

def test_partner_infos(self):
data = self.generate_ticket_data()
res = self.service.dispatch("create", params=data)
ticket = self.env["helpdesk.ticket"].search([("id", "=", res["id"])])
self.assert_ticket_ok(ticket)
authenticated_partner_id = self.env["res.partner"].browse(
self.services_env.collection.env.context["authenticated_partner_id"]
)
self.assertEqual(ticket.partner_id, authenticated_partner_id)
self.assertEqual(ticket.partner_email, authenticated_partner_id.email)
self.assertEqual(ticket.partner_name, authenticated_partner_id.name)
Loading