Skip to content
Snippets Groups Projects
Commit 46b93da5 authored by FrancoisGe's avatar FrancoisGe
Browse files

[FIX] *: override save checks that the save is valid


The goal of this commit is to avoid the execution of code depending
on the validity of the save of a Record.

Before this commit, several override save functions in Record execute
code after the record's save without checking if the record's save has
taken place.

Override before:
export class NewRecord extends Record {
    async save() {
        const isSaved = await super.save(...arguments);
        // doAction
        return isSaved;
    }
}

Override after:
export class NewRecord extends Record {
    async save() {
        const isSaved = await super.save(...arguments);
        if (isSaved) {
            // doAction
        }
        return isSaved;
    }
}

How to reproduce the problem:
    Go to a form view with a Record having its save override function.
    Edit a record in such a way to have an invalid field
    Click on the save button

Before this commit:
The doAction is executed

After this commit:
The doAction is not executed

Real use case
- Go to the form view of a lead in CRM
- Change stage
- Clear the name field
- Click on save button

Before this commit:
A call to get_rainbowman_message is made

After this commit:
No call to get_rainbowman_message is made.

closes odoo/odoo#105468

Related: odoo/enterprise#33817
Signed-off-by: default avatarAaron Bohy (aab) <aab@odoo.com>
parent be7a0291
Branches
Tags
No related merge requests found
......@@ -68,11 +68,11 @@ export class CrmFormRecord extends Record {
const newStageId = bm.get(bm.localData[recordID]._changes.stage_id).data.id;
changedStage = oldStageId !== newStageId;
}
const res = await super.save(...arguments);
if (changedStage) {
const isSaved = await super.save(...arguments);
if (changedStage && isSaved) {
await checkRainbowmanMessage(this.model.orm, this.model.effect, this.resId);
}
return res;
return isSaved;
}
}
......
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { formView } from "@web/views/form/form_view"
import { formView } from "@web/views/form/form_view";
import { Record, RelationalModel } from "@web/views/relational_model";
/**
......@@ -14,12 +14,14 @@ import { Record, RelationalModel } from "@web/views/relational_model";
class EventBoothConfiguratorRelationalModel extends RelationalModel {}
class EventBoothConfiguratorRecord extends Record {
//--------------------------------------------------------------------------
// Overrides
//--------------------------------------------------------------------------
async save(options = {}) {
await super.save(options);
async save() {
const isSaved = await super.save(...arguments);
if (!isSaved) {
return false;
}
this.model.action.doAction({type: 'ir.actions.act_window_close', infos: {
eventBoothConfiguration: {
event_id: this.data.event_id,
......@@ -33,6 +35,7 @@ class EventBoothConfiguratorRecord extends Record {
}
}
}});
return true;
}
}
......
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { formView } from "@web/views/form/form_view"
import { formView } from "@web/views/form/form_view";
import { Record, RelationalModel } from "@web/views/relational_model";
/**
......@@ -15,7 +15,6 @@ import { Record, RelationalModel } from "@web/views/relational_model";
class EventConfiguratorRelationalModel extends RelationalModel {}
class EventConfiguratorRecord extends Record {
/**
* We let the regular process take place to allow the validation of the required fields
* to happen.
......@@ -24,14 +23,18 @@ class EventConfiguratorRecord extends Record {
*
* @override
*/
async save(options = {}) {
await super.save(options);
async save() {
const isSaved = await super.save(...arguments);
if (!isSaved) {
return false;
}
this.model.action.doAction({type: 'ir.actions.act_window_close', infos: {
eventConfiguration: {
event_id: this.data.event_id,
event_ticket_id: this.data.event_ticket_id,
}
}});
return true;
}
}
......
......@@ -8,11 +8,11 @@ import { Record, RelationalModel } from "@web/views/basic_relational_model";
export class EmployeeProfileRecord extends Record {
async save() {
const dirtyFields = this.dirtyFields.map((f) => f.name);
const res = await super.save(...arguments);
if (dirtyFields.includes("lang")) {
const isSaved = await super.save(...arguments);
if (isSaved && dirtyFields.includes("lang")) {
this.model.actionService.doAction("reload_context");
}
return res;
return isSaved;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment