server-ux
server-ux copied to clipboard
[17.0][IMP] base_optional_quick_create: allow_quick_create context flag
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.