-
Notifications
You must be signed in to change notification settings - Fork 0
fix(spp_api_v2_change_request): fix 3 bugs and promote to Beta #13
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
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,8 @@ class ChangeRequestService: | |
| """Service for Change Request resource CRUD and mapping.""" | ||
|
|
||
| def __init__(self, env: Environment): | ||
| self.env = env | ||
| ctx = dict(env.context, mail_create_nolog=True, tracking_disable=True) | ||
| self.env = env(context=ctx) | ||
|
|
||
| def find_by_reference(self, reference: str): | ||
| """ | ||
|
|
@@ -161,7 +162,7 @@ def _serialize_detail(self, detail) -> dict[str, Any]: | |
| # Get fields from the model | ||
| model_fields = detail._fields | ||
|
|
||
| # Skip internal and computed fields | ||
| # Skip internal, computed, and mail.thread fields | ||
| skip_fields = { | ||
| "id", | ||
| "create_uid", | ||
|
|
@@ -175,6 +176,20 @@ def _serialize_detail(self, detail) -> dict[str, Any]: | |
| "registrant_id", | ||
| "approval_state", | ||
| "is_applied", | ||
| # mail.thread fields | ||
| "message_ids", | ||
| "message_follower_ids", | ||
| "message_partner_ids", | ||
| "message_is_follower", | ||
| "has_message", | ||
| "message_needaction", | ||
| "message_needaction_counter", | ||
| "message_has_error", | ||
| "message_has_error_counter", | ||
| "message_attachment_count", | ||
| "message_has_sms_error", | ||
| "message_main_attachment_id", | ||
| "website_message_ids", | ||
| } | ||
|
Comment on lines
+179
to
193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the list of A more robust and maintainable approach is to programmatically retrieve the fields from the Consider this alternative approach: # In _serialize_detail method
# Get fields from the model
model_fields = detail._fields
# Base fields to skip
skip_fields = {
"id",
"create_uid",
"create_date",
"write_uid",
"write_date",
"__last_update",
"display_name",
"change_request_id",
"registrant_id",
"approval_state",
"is_applied",
}
# Programmatically add all mail.thread fields
mail_thread_fields = self.env["mail.thread"]._fields.keys()
skip_fields.update(mail_thread_fields)
for field_name, field in model_fields.items():
# ... rest of the methodThis makes the code more resilient to changes in the underlying Odoo framework. |
||
|
|
||
| for field_name, field in model_fields.items(): | ||
|
|
@@ -451,5 +466,5 @@ def apply(self, cr): | |
| def reset_to_draft(self, cr): | ||
| """Reset rejected/revision CR to draft.""" | ||
| if cr.approval_state not in ("rejected", "revision"): | ||
| raise UserError("Only rejected or revision-requested change requests " "can be reset to draft") | ||
| raise UserError("Only rejected or revision-requested change requests can be reset to draft") | ||
| cr.action_reset_to_draft() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper function is a good first step, but its repeated use in each of the 8 updated endpoints leads to significant code duplication. A more idiomatic and maintainable approach in FastAPI is to use a dependency.
You can convert this logic into a dependency that extracts the path parameters and provides the reconstructed
referencestring directly to the endpoint functions. This will centralize the path-parsing logic and make the endpoint signatures much cleaner.Here's how you could refactor this:
Define the dependency function (you can rename
_build_reference):Use the dependency in your endpoints:
Applying this pattern to all affected endpoints will greatly improve the code's readability and reduce redundancy.