Skip to content

Conversation

@SlWa99
Copy link

@SlWa99 SlWa99 commented Jan 7, 2026

Criminal Record Save Failure Resolution

Purpose and Context

The goal of this PR is to fix a critical issue preventing users from updating their Criminal Record via the MyCompassion portal.

Due to Odoo security constraints and inconsistent document handling, uploads were failing when registrations were in the Attended state. In some cases, this also caused unstable registration statuses and the disappearance of events from the My Events section.

This PR should be reviewed together with a related PR, as both contribute to stabilizing the document upload and event registration workflows.


Applied Changes and Improvements

1. Portal Security and Save Reliability

  • Secure write with sudo
    Document saving in event.registration.form now uses
    form.registration_id.sudo().write(docs_to_save).

  • Result
    Documents are saved with sufficient privileges, preventing access errors, redirection crashes, and unintended status changes. The Attended status is preserved.


2. Document Management Standardization

  • Unified handling
    Passport and Criminal Record are now managed in an identical and consistent way.

  • Technical debt removal
    Complex compute / inverse logic for Passport has been removed.
    Both documents are now standard Binary fields with attachment=True on res.partner.

  • Single source of truth
    Documents are physically attached to the partner (contact).
    Event registrations access them through related fields.

  • XML cleanup
    Backend views were simplified by removing obsolete technical fields (e.g. passport_filename).


3. Validation and Testing

  • Portal upload testing
    Documents were uploaded using a real participant account for the Impact Trip in the Dominican Republic.

  • Technical verification
    Uploaded documents are visible under
    Settings → Technical → Attachments as Passport and Criminal Record.

  • Data integrity
    Each attachment correctly references the related partner in the Attached To field.


Outcome

  • Criminal Record and Passport uploads are stable and reliable.
  • Event registrations remain visible, with the Attended status preserved.
  • The codebase is cleaner, standardized, and easier to maintain.

Related PRs

This set of improvements is complemented by a related PR in the Compassion-modules repository:

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 addresses a critical bug in the MyCompassion portal that prevented users from successfully uploading Criminal Records and Passports, particularly when event registrations were in an 'Attended' state. The changes ensure secure and reliable document uploads by standardizing document management, leveraging appropriate security contexts for write operations, and simplifying the underlying data model. This significantly improves system stability, prevents unintended status changes, and enhances the overall user experience for document submission.

Highlights

  • Secure Document Uploads: A critical issue preventing Criminal Record and Passport uploads, especially for 'Attended' registrations, has been resolved by implementing sudo() for document saving. This ensures documents are saved with sufficient privileges, preventing access errors and unstable registration statuses.
  • Standardized Document Management: Passport and Criminal Record handling are now unified and consistent. Complex compute/inverse logic for the Passport field has been removed, and both documents are now standard Binary fields with attachment=True directly on res.partner, simplifying the data model.
  • Codebase Cleanup and Simplification: Obsolete technical fields like passport_filename and their associated logic, including the _inverse_passport method, have been removed. Backend XML views have also been simplified, leading to a cleaner and more maintainable codebase.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the critical issue of failing criminal record uploads by refactoring the document handling logic. Moving the passport and criminal_record fields to res.partner and using related fields on event.registration is a great simplification that improves data integrity and maintainability. The use of sudo() to ensure documents are saved correctly from the portal is a pragmatic solution to the access rights issue.

My review highlights a potential robustness issue with the implementation in the wizard that could cause the fix to be incomplete, and also points out some leftover code from the refactoring that should be removed to keep the codebase clean. Addressing these points will make the solution more robust and maintainable.

I am having trouble creating individual review comments. Click here to see my feedback.

website_event_compassion/wizards/registration_form.py (38)

high

While this sudo().write() call is the correct way to save with elevated privileges, there's a potential issue with the overall approach. Because the passport and criminal_record fields on this wizard are defined as related fields, the Odoo ORM will attempt to write their values during the super().create() call. This initial write does not use sudo() and is likely to fail with an access error, which might be the root cause of the crashes mentioned in the PR description.

For a more robust fix, I recommend changing the passport and criminal_record fields on the event.registration.form model to be standard fields.Binary() instead of related fields. This would prevent the initial, non-privileged write attempt and ensure this sudo() write is the only one performed.

website_event_compassion/models/event_registration.py (139-141)

medium

This refactoring is a good improvement. As part of this change, the _compute_passport method is now dead code and should be removed to improve maintainability and prevent future confusion. The method also references passport_filename, which no longer exists, and would raise an error if ever called.

@SlWa99
Copy link
Author

SlWa99 commented Jan 7, 2026

Feedback applied. I have removed the related attribute from the passport and criminal_record fields in the wizard. As pointed out, the ORM was attempting a non-privileged write to the partner during super().create(), causing an access error when the registration was in 'Attended' status. By using standard Binary fields, the files are now stored as a buffer in the transient model and then explicitly saved to the partner using sudo().write() in the create method.

Copy link
Member

@ecino ecino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bring the changes from CompassionCH/compassion-modules#2065 inside this module as well.

@SlWa99
Copy link
Author

SlWa99 commented Jan 15, 2026

Ok, it's normally done !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants