From d0987e0b254be303f87a4c56db30ac93eab97a9e Mon Sep 17 00:00:00 2001 From: "Laurent Stukkens (LTU)" Date: Tue, 4 Oct 2022 08:23:38 +0200 Subject: [PATCH] [REF] web: allow overriding Many2OneField activeActions Prior to this commit it was not possible to override `computeActiveActions`, which prevents acting when onWillUpdateProps is triggered as both are private to the setup function. task-3001470 X-original-commit: c785327fedd4fa94884af692c21985663a79c454 --- .../views/fields/many2one/many2one_field.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/views/fields/many2one/many2one_field.js b/addons/web/static/src/views/fields/many2one/many2one_field.js index 3cb54051d29..57406b8a44d 100644 --- a/addons/web/static/src/views/fields/many2one/many2one_field.js +++ b/addons/web/static/src/views/fields/many2one/many2one_field.js @@ -51,18 +51,10 @@ export class Many2OneField extends Component { this.autocompleteContainerRef.el.querySelector("input").focus(); }; - const computeActiveActions = (props) => { - this.state.activeActions = { - create: props.canCreate, - createEdit: props.canCreateEdit, - write: props.canWrite, - }; - }; - this.state = useState({ isFloating: !this.props.value, }); - computeActiveActions(this.props); + this.computeActiveActions(this.props); this.openMany2X = useOpenMany2XRecord({ resModel: this.relation, @@ -102,7 +94,7 @@ export class Many2OneField extends Component { onWillUpdateProps(async (nextProps) => { this.state.isFloating = !nextProps.value; - computeActiveActions(nextProps); + this.computeActiveActions(nextProps); }); } @@ -151,6 +143,13 @@ export class Many2OneField extends Component { autocomplete_container: this.autocompleteContainerRef, }; } + computeActiveActions(props) { + this.state.activeActions = { + create: props.canCreate, + createEdit: props.canCreateEdit, + write: props.canWrite, + }; + } getDomain() { return this.domain.toList(this.context); }