-
-
Notifications
You must be signed in to change notification settings - Fork 631
[17.0][IMP] base_optional_quick_create: allow_quick_create context flag #1180
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: 17.0
Are you sure you want to change the base?
[17.0][IMP] base_optional_quick_create: allow_quick_create context flag #1180
Conversation
a0e16f7 to
4fae393
Compare
| if self.env.context.get("allow_quick_create"): | ||
| return wrapper.origin(self, name) |
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.
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.
4fae393 to
f1e5fa4
Compare
|
This PR has the |
Introduce an
allow_quick_createcontext flag to bypass the restriction applied by models withavoid_quick_createenabled. 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), withforce_createset toTrue, creates a new partner (if not found) by usingname_create:cf. https://github.com/odoo/odoo/blob/35ed88e2e6f66147c4c1582761df1e53011b3643/addons/mail/models/mail_thread.py#L1971-L2039
When
avoid_quick_createis enabled on theres.partnermodel, an unwantedUserErroris raised.With the new
allow_quick_createcontext 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.