diff --git a/addons/crm/static/src/views/crm_form/crm_form.js b/addons/crm/static/src/views/crm_form/crm_form.js index 53838d14136..bb055987295 100644 --- a/addons/crm/static/src/views/crm_form/crm_form.js +++ b/addons/crm/static/src/views/crm_form/crm_form.js @@ -1,9 +1,9 @@ /** @odoo-module **/ import { registry } from "@web/core/registry"; -import { FormController } from "@web/views/form/form_controller"; import { formView } from "@web/views/form/form_view"; -import { useCheckRainbowman } from "@crm/views/check_rainbowman_message"; +import { checkRainbowmanMessage } from "@crm/views/check_rainbowman_message"; +import { Record, RelationalModel } from "@web/views/basic_relational_model"; /** * This Form Controller makes sure we display a rainbowman message @@ -12,13 +12,7 @@ import { useCheckRainbowman } from "@crm/views/check_rainbowman_message"; * if the lead is won and if a message should be displayed to the user * with a rainbowman like when the user click on the button "Mark Won". */ - -export class CrmFormController extends FormController { - async setup() { - super.setup(); - this.checkRainbowmanMessage = useCheckRainbowman(); - } - +export class CrmFormRecord extends Record { /** * Main method used when saving the record hitting the "Save" button. * We check if the stage_id field was altered and if we need to display a rainbowman @@ -36,8 +30,8 @@ export class CrmFormController extends FormController { * * @override */ - async save(params = {}) { - const recordID = this.model.root.__bm_handle__; + async save() { + const recordID = this.__bm_handle__; const localData = this.model.__bm__.localData[recordID]; const changes = localData._changes || {}; @@ -51,7 +45,11 @@ export class CrmFormController extends FormController { ? localData.data.partner_phone_update // original value : changes.partner_phone_update; // new value - if (needsSynchronizationEmail && changes.email_from === undefined && localData.data.email_from) { + if ( + needsSynchronizationEmail && + changes.email_from === undefined && + localData.data.email_from + ) { changes.email_from = localData.data.email_from; } if (needsSynchronizationPhone && changes.phone === undefined && localData.data.phone) { @@ -70,14 +68,24 @@ export class CrmFormController extends FormController { const newStageId = bm.get(bm.localData[recordID]._changes.stage_id).data.id; changedStage = oldStageId !== newStageId; } - await super.save(params); + const res = await super.save(...arguments); if (changedStage) { - await this.checkRainbowmanMessage(this.model.root.resId); + await checkRainbowmanMessage(this.model.orm, this.model.effect, this.resId); } + return res; } } +class CrmFormModel extends RelationalModel { + setup(params, services) { + this.effect = services.effect; + super.setup(...arguments); + } +} +CrmFormModel.Record = CrmFormRecord; +CrmFormModel.services = [...RelationalModel.services, "effect"]; + registry.category("views").add("crm_form", { ...formView, - Controller: CrmFormController, + Model: CrmFormModel, }); diff --git a/addons/crm/static/src/views/fields/crm_statusbar_field.js b/addons/crm/static/src/views/fields/crm_statusbar_field.js index 33092ee9023..79cce50eef0 100644 --- a/addons/crm/static/src/views/fields/crm_statusbar_field.js +++ b/addons/crm/static/src/views/fields/crm_statusbar_field.js @@ -2,14 +2,8 @@ import { registry } from "@web/core/registry"; import { StatusBarField, preloadStatusBar } from "@web/views/fields/statusbar/statusbar_field"; -import { useCheckRainbowman } from "@crm/views/check_rainbowman_message"; export class CrmStatusBarField extends StatusBarField { - setup() { - super.setup(); - this.checkRainbowmanMessage = useCheckRainbowman(); - } - /** * @override * @@ -28,7 +22,6 @@ export class CrmStatusBarField extends StatusBarField { await this.props.update(item.id); break; } - await this.checkRainbowmanMessage(this.props.record.resId); } } diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index 58afdafad45..4408dc4f95b 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -395,7 +395,7 @@ export class FormController extends Component { } } - async save(params = {}) { + async saveButtonClicked(params = {}) { this.disableButtons(); const record = this.model.root; let saved = false; diff --git a/addons/web/static/src/views/form/form_controller.xml b/addons/web/static/src/views/form/form_controller.xml index fcfcdc44ec0..92000828960 100644 --- a/addons/web/static/src/views/form/form_controller.xml +++ b/addons/web/static/src/views/form/form_controller.xml @@ -30,7 +30,7 @@ - + @@ -47,7 +47,7 @@ - + Save diff --git a/addons/web/static/src/views/view_dialogs/form_view_dialog.xml b/addons/web/static/src/views/view_dialogs/form_view_dialog.xml index e1a83a8799a..b7060673cea 100644 --- a/addons/web/static/src/views/view_dialogs/form_view_dialog.xml +++ b/addons/web/static/src/views/view_dialogs/form_view_dialog.xml @@ -17,14 +17,14 @@ - Save & Close - Save & New + Save & Close + Save & New - Save & Close + Save & Close diff --git a/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js b/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js index 17d4ee9106d..829f03f376c 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js +++ b/addons/web/static/src/webclient/settings_form_view/settings_form_controller.js @@ -68,7 +68,7 @@ export class SettingsFormController extends formView.Controller { body: message, confirm: async () => { await this.model.root.save({ stayInEdition: true }); - await this.save(); + await this._save(); // It doesn't make sense to do the action of the button // as the res.config.settings `execute` method will trigger a reload. _continue = false; @@ -102,7 +102,11 @@ export class SettingsFormController extends formView.Controller { //This is needed to avoid writing the id on the url updateURL() {} - async save() { + async saveButtonClicked() { + await this._save(); + } + + async _save() { this.env.onClickViewButton({ clickParams: { name: "execute", diff --git a/addons/website/static/src/js/new_content_form.js b/addons/website/static/src/js/new_content_form.js index e81cb199c6d..2320028600f 100644 --- a/addons/website/static/src/js/new_content_form.js +++ b/addons/website/static/src/js/new_content_form.js @@ -7,8 +7,10 @@ export class NewContentFormController extends formView.Controller { /** * @override */ - async save(params) { - await super.save(Object.assign({ computePath: () => this.computePath() }, params)); + async saveButtonClicked(params) { + await super.saveButtonClicked( + Object.assign({ computePath: () => this.computePath() }, params) + ); } /**