Skip to content

Conversation

@vvrossem
Copy link

@vvrossem vvrossem commented Nov 5, 2025

Introduce an allow_quick_create context flag to bypass the restriction applied by models with avoid_quick_create enabled. This allows controlled quick creation of records in specific, legitimate cases.

For example, the method mail.thread::_mail_find_partner_from_emails(emails, records=None, force_create=False, extra_domain=False), with force_create set to True, creates a new partner (if not found) by using name_create:

partner = self.env['res.partner'].browse(self.env['res.partner'].name_create(contact)[0])

cf. https://github.com/odoo/odoo/blob/35ed88e2e6f66147c4c1582761df1e53011b3643/addons/mail/models/mail_thread.py#L1971-L2039

When avoid_quick_create is enabled on the res.partner model, an unwanted UserError is raised.

With the new allow_quick_create context flag, such internal operations can safely bypass the restriction while keeping it enforced for regular user actions.
This requires to extend core methods in order to inject that context flag.

@vvrossem vvrossem changed the title [IMP] base_optional_quick_create: allow_quick_create context flag [17.0][IMP] base_optional_quick_create: allow_quick_create context flag Nov 5, 2025
@vvrossem vvrossem force-pushed the 17.0-imp-base_optional_quick_create-allow_quick_create branch 2 times, most recently from a0e16f7 to 4fae393 Compare November 5, 2025 14:34
Comment on lines +66 to +67
if self.env.context.get("allow_quick_create"):
return wrapper.origin(self, name)
Copy link
Contributor

@sebalix sebalix Nov 6, 2025

Choose a reason for hiding this comment

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

It doesn't hurt but not sure it's the right approach neither.

If this module is breaking std behavior when installed, the fix should not be proposing a workaround, forcing the creation of new module like mail_optional_quick_create to fix the std feature of mail.

If the goal is to prevent users to create duplicated records by disabling "Quick create" feature, then it should belong to web stack (by using web_m2x_options for instance), so all internal calls to name_create will still work as expected.

I would deprecate this module instead 🤷‍♂️

Introduce an `allow_quick_create` context flag to bypass the restriction applied by models with `avoid_quick_create` enabled.
This allows controlled quick creation of records in specific, legitimate cases.

For example, the method `mail.thread::_mail_find_partner_from_emails(emails, records=None, force_create=False, extra_domain=False)`,
with `force_create` set to `True`, creates a new partner (if not found) by using `name_create`:
```
partner = self.env['res.partner'].browse(self.env['res.partner'].name_create(contact)[0])
```
cf. https://github.com/odoo/odoo/blob/35ed88e2e6f66147c4c1582761df1e53011b3643/addons/mail/models/mail_thread.py#L1971-L2039

When `avoid_quick_create` is enabled on the `res.partner` model, an unwanted `UserError` is raised.

With the new `allow_quick_create` context flag, such internal operations can safely bypass the restriction while keeping it enforced for regular user actions.
This requires to extend core methods in order to inject that context flag.
@vvrossem vvrossem force-pushed the 17.0-imp-base_optional_quick_create-allow_quick_create branch from 4fae393 to f1e5fa4 Compare November 6, 2025 13:52
@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants