Yes, it is possible to set up a confirmation dialog in Odoo when a user attempts to create a new record by typing a new name in a one2many field and pressing enter. However, this functionality is not available out-of-the-box and requires custom development.
To achieve this, you would need to:
-
Extend the JavaScript Widget: Override the existing widget for the one2many or many2one field. In Odoo, these fields are handled by specific JavaScript widgets that manage their interaction and behavior.
-
Intercept the Creation Event: Modify the widget's behavior to intercept the event when a new value is entered that doesn't match existing records. This involves listening to the appropriate event in the widget's code.
-
Display a Confirmation Dialog: Before allowing the creation of the new record, display a confirmation dialog to the user. You can use Odoo's built-in dialog widget (Dialog) to create a modal popup that asks the user to confirm their action.
-
Proceed Based on User Response: If the user confirms the creation, allow the process to continue and create the new record as usual. If the user cancels, prevent the creation and clear the input if necessary.
Here's a high-level outline of what the custom code might involve:
Example:
odoo.define('your_module.FieldMany2OneConfirm', function (require) {
"use strict";
var core = require('web.core');
var FieldMany2One = require('web.relational_fields').FieldMany2One;
var Dialog = require('web.Dialog');
var FieldMany2OneConfirm = FieldMany2One.include({
_quickCreate: function (searchVal) {
var self = this;
return new Promise(function (resolve, reject) {
Dialog.confirm(self, "Do you want to create a new record?", {
confirm_callback: function () {
resolve(self._super(searchVal));
},
cancel_callback: function () {
reject();
}
});
});
},
});
return FieldMany2OneConfirm;
});
Please note that this is a simplified example and may require adjustments to work correctly in your specific Odoo version and with your customizations.
Considerations:
- Testing: Ensure thorough testing across different scenarios to prevent disruptions to the user experience.
- User Experience: While adding a confirmation dialog enhances control, it can also slow down data entry. Consider whether this is necessary for all users or records.
- Maintenance: Custom code needs to be maintained across Odoo updates. Ensure compatibility with future versions.
Alternative Approaches:
- Access Rights: If the goal is to prevent unauthorized creation of records, consider adjusting user permissions.
- Record Rules: Implement record rules to restrict creation based on certain conditions.
- Server-Side Validation: Use constraints or overrides in the model to prevent unwanted record creation.
In summary, while Odoo doesn't provide this feature by default, you can implement it through custom development by extending the client-side widgets to include a confirmation dialog when creating new records from a one2many field.
References:
Note: Replace your_module with the actual name of your custom module, and adjust the code as needed for your version of Odoo.