[FIX] web, crm: override of form controller save function
Before this commit, some functions overrode the save function of the form controller. The issue is that this function is only called when the button save is clicked, and not when we save differently (for example, when clicking on the breadcrumb). To avoid this mistake the save function on the form controller was renamed to: `saveButtonClicked`, and the code that overrode the function now override the save function of the Record, that it's called at each time a save is perform. X-original-commit: b6e3d833e6131562084eb13b2955c22f50ad1e79 Part-of: odoo/odoo#102992
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</t>
|
||||
<t t-set-slot="control-panel-status-indicator">
|
||||
<t t-if="canEdit">
|
||||
<FormStatusIndicator model="model" discard.bind="discard" save.bind="save" isDisabled="state.isDisabled" />
|
||||
<FormStatusIndicator model="model" discard.bind="discard" save.bind="saveButtonClicked" isDisabled="state.isDisabled" />
|
||||
</t>
|
||||
</t>
|
||||
<t t-set-slot="control-panel-create-button">
|
||||
@@ -47,7 +47,7 @@
|
||||
<t t-name="web.FormView.Buttons" owl="1">
|
||||
<div class="o_cp_buttons" role="toolbar" aria-label="Main actions" t-ref="cpButtons">
|
||||
<div t-if="model.root.isInEdition" class="o_form_buttons_edit">
|
||||
<button type="button" class="btn btn-primary o_form_button_save" data-hotkey="s" t-on-click.stop="() => this.save({closable: true})">
|
||||
<button type="button" class="btn btn-primary o_form_button_save" data-hotkey="s" t-on-click.stop="() => this.saveButtonClicked({closable: true})">
|
||||
Save
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary o_form_button_cancel" data-hotkey="j" t-on-click.stop="discard">
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
|
||||
<t t-name="web.FormViewDialog.ToMany.buttons" t-inherit="web.FormView.Buttons" owl="1">
|
||||
<xpath expr="//button[contains(@class, 'o_form_button_save')]" position="replace">
|
||||
<button class="btn btn-primary o_form_button_save" t-on-click="save" data-hotkey="c">Save & Close</button>
|
||||
<button class="btn btn-primary o_form_button_save_new" t-on-click="() => this.save({saveAndNew: true})" data-hotkey="n">Save & New</button>
|
||||
<button class="btn btn-primary o_form_button_save" t-on-click="saveButtonClicked" data-hotkey="c">Save & Close</button>
|
||||
<button class="btn btn-primary o_form_button_save_new" t-on-click="() => this.saveButtonClicked({saveAndNew: true})" data-hotkey="n">Save & New</button>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
<t t-name="web.FormViewDialog.ToOne.buttons" t-inherit="web.FormView.Buttons" owl="1">
|
||||
<xpath expr="//button[contains(@class, 'o_form_button_save')]" position="replace">
|
||||
<button class="btn btn-primary o_form_button_save" t-on-click="save" data-hotkey="c">Save & Close</button>
|
||||
<button class="btn btn-primary o_form_button_save" t-on-click="saveButtonClicked" data-hotkey="c">Save & Close</button>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user