bemade-addons/confirm_many2one_create/static/src/js/many2one_field.esm.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

/** @odoo-module **/
2025-05-16 11:01:56 -04:00
import {Many2OneField, m2oTupleFromData} from "@web/views/fields/many2one/many2one_field";
import {patch} from "@web/core/utils/patch";
patch(Many2OneField.prototype, {
2025-05-16 11:01:56 -04:00
/**
* The original Many2OneField already has a quickCreate method and an openConfirmationDialog method.
* The quickCreate method directly updates the record, while openConfirmationDialog shows a dialog
* before calling quickCreate.
*
* We just need to modify the Many2XAutocompleteProps getter to use openConfirmationDialog
* instead of quickCreate for the quickCreate property.
*/
get Many2XAutocompleteProps() {
const props = super.Many2XAutocompleteProps;
2025-05-16 10:57:10 -04:00
2025-05-16 11:01:56 -04:00
// If quickCreate is defined, replace it with openConfirmationDialog
if (props.quickCreate && this.openConfirmationDialog) {
// Store the original quickCreate function
const originalQuickCreate = props.quickCreate;
2025-05-16 10:57:10 -04:00
2025-05-16 11:01:56 -04:00
// Replace with openConfirmationDialog
props.quickCreate = (name) => this.openConfirmationDialog(name);
2025-05-16 10:57:10 -04:00
}
2025-05-16 11:01:56 -04:00
return props;
2025-05-16 10:57:10 -04:00
},
});