[T2910] [MIG] - Migrate website_child_protection (Work In Progress, don't merge it)#272
[T2910] [MIG] - Migrate website_child_protection (Work In Progress, don't merge it)#272
Conversation
Summary of ChangesHello @SlWa99, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a comprehensive technical migration of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the website_child_protection module to Odoo 18.0, refactoring it to remove the dependency on website_form and adopting a modern controller-based approach. The code is much cleaner and follows current Odoo standards.
I've identified a few areas for improvement:
- There's a functional regression where a
redirectparameter is lost in one of the controller methods. - The form's error handling for the required checkbox is incomplete, as no message is displayed to the user upon validation failure.
- A minor point on using CSS utility classes instead of inline styles in the template for better maintainability.
Overall, this is a solid migration. Addressing these points will make it even better.
| if date_signed and (datetime.datetime.now() - date_signed).days < 365: | ||
| return request.redirect("/partner/child-protection-charter-agreed") |
There was a problem hiding this comment.
The redirect to the confirmation page loses the original redirect query parameter. This can lead to incorrect navigation for users who have already agreed to the charter. The redirect parameter should be preserved, similar to how it's handled in the child_protection_charter_submit method.
if date_signed and (datetime.datetime.now() - date_signed).days < 365:
target = "/partner/child-protection-charter-agreed"
redirect_url = kwargs.get("redirect")
if redirect_url:
target += "?redirect=" + redirect_url
return request.redirect(target)| if not agreed: | ||
| return request.redirect(request.httprequest.referrer + "?error=required") |
There was a problem hiding this comment.
When the form is submitted without the 'agreed' checkbox checked, you redirect the user back to the form with ?error=required. However, the template child_protection_charter.xml does not handle this query parameter to display an error message to the user. This results in a poor user experience as they are not informed why the submission failed.
You should add logic to the template to display an error message. For example:
<t t-if="request.params.get('error') == 'required'">
<div class="alert alert-danger" role="alert">
You must agree to the charter to continue.
</div>
</t>| <input | ||
| class="form-check-input" | ||
| type="checkbox" | ||
| name="agreed" | ||
| id="agreed" | ||
| required="required" | ||
| style="margin-top:0;" | ||
| /> |
There was a problem hiding this comment.
Using inline styles (style="margin-top:0;") is generally discouraged for maintainability. It's better to use CSS classes. Since you are using Bootstrap, you can use a margin utility class like mt-0 to achieve the same result while keeping the markup cleaner.
| <input | |
| class="form-check-input" | |
| type="checkbox" | |
| name="agreed" | |
| id="agreed" | |
| required="required" | |
| style="margin-top:0;" | |
| /> | |
| <input | |
| class="form-check-input mt-0" | |
| type="checkbox" | |
| name="agreed" | |
| id="agreed" | |
| required="required" | |
| /> |
[MIG][18.0][WIP] website_child_protection: Technical Migration & V14 Work Integration
Description
This PR performs the technical migration of the
website_child_protectionmodule from Odoo 14.0 to Odoo 18.0.Context & Parallel Work
Important note: in parallel with this technical migration, visual and structural changes were made to this page in Odoo 14 by Daniel (see PR: T2957 code of conduct).
It is mandatory to review this V14 PR to ensure that the final Odoo 18 result is functionally equivalent and visually identical to the latest validated V14 version.
Major Technical Changes
The architecture has been reworked to comply with Odoo 18 standards and to remove the dependency on the
website_formmodule.1. Backend Implementation (controllers/main.py)
The logic was moved from a transient model wizard (V14 approach) to a direct HTTP controller (V18 approach).
Route Definition
Created a new route
/partner/child-protection-charter/submitrestricted to POST methods.Security
csrf=Trueto enforce token validation..sudo()explicitly (scoped to this controlled write operation) to search for and update theres.partnerrecord.This allows anonymous (public) users to write without introducing complex ACL rules in
ir.model.access.csv.Logic
partner_uuidand agreement status from request arguments (kwargs).datetime.now()to thedate_agreed_child_protection_charterfield.request.redirect().PS : The logic of the controller can be improved.
2. Frontend Implementation (child_protection_charter.xml)
The XML template was refactored to remove all dependencies on the legacy
s_website_formsnippet system.HTML Structure
Replaced the snippet-based container with a standard HTML5
<form>pointing to the new controller route.CSRF Injection
Added the mandatory hidden input:
Removed Files
The following files were removed as they are obsolete with the new architecture:
static/src/js/website_child_protection.jsLegacy JavaScript is no longer required with a native HTML form.
wizards/agreement_child_protection_charter_form.pyWizard logic has been migrated to the controller.
security/ir.model.access.csvAccess rights related to the removed wizard are no longer needed.
data/form_data.xmlWhitelist configuration for
website_formis no longer applicable.templates/assets.xmlAsset declaration is now handled in
__manifest__.py.Remaining Work: Styling & Visual Adjustments
The functional code is complete. CSS integration still needs to be finalized to match the design validated in Daniel’s V14 PR.
Required adjustments (CSS/SCSS):
Test Procedure
Access the page:
http://localhost:8069/partner/child-protection-charterCompare the visual rendering with the V14 PR (link: T2957 code of conduct).
Submit the form.
Verify: