[FIX] web: add auto save option for state and priority field

Before this commit state selection and priority both
field are saved we change its value even though we
are not saving records and because of that changing
state or priority in sub-task or block-by task
and discarding changes does not set them to their
previous state and it'll create new record without
saving if we change one of those field.

This commit add 'auto_save' option to prevent auto save
on state and priority from sub-task and block-by task
page.

task-3282848

Part-of: odoo/odoo#120925
This commit is contained in:
Kartik Chavda
2023-05-10 11:36:59 +02:00
committed by Prakash Prajapati
parent 31262f27a5
commit d11cee3474
4 changed files with 68 additions and 3 deletions
@@ -12,6 +12,7 @@ export class PriorityField extends Component {
static props = {
...standardFieldProps,
withCommand: { type: Boolean, optional: true },
autosave: { type: Boolean, optional: true },
};
setup() {
@@ -82,7 +83,9 @@ export class PriorityField extends Component {
async updateRecord(value) {
await this.props.record.update({ [this.props.name]: value });
return this.props.record.save();
if (this.props.autosave) {
return this.props.record.save();
}
}
}
@@ -90,10 +93,11 @@ export const priorityField = {
component: PriorityField,
displayName: _lt("Priority"),
supportedTypes: ["selection"],
extractProps({ viewType }, dynamicInfo) {
extractProps({ options, viewType }, dynamicInfo) {
return {
withCommand: viewType === "form",
readonly: dynamicInfo.readonly,
autosave: "autosave" in options ? !!options.autosave : true,
};
},
};
@@ -20,6 +20,7 @@ export class StateSelectionField extends Component {
...standardFieldProps,
showLabel: { type: Boolean, optional: true },
withCommand: { type: Boolean, optional: true },
autosave: { type: Boolean, optional: true },
};
static defaultProps = {
showLabel: true,
@@ -72,7 +73,9 @@ export class StateSelectionField extends Component {
async updateRecord(value) {
await this.props.record.update({ [this.props.name]: value });
return this.props.record.save();
if (this.props.autosave) {
return this.props.record.save();
}
}
}
@@ -85,6 +88,7 @@ export const stateSelectionField = {
showLabel: viewType === "list" && !options.hide_label,
withCommand: viewType === "form",
readonly: dynamicInfo.readonly,
autosave: "autosave" in options ? !!options.autosave : true,
};
},
};
@@ -639,4 +639,32 @@ QUnit.module("Fields", (hooks) => {
await click(stars[stars.length - 1]);
assert.verifySteps(["write"]);
});
QUnit.test("PriorityField - prevent auto save with autosave option", async function (assert) {
await makeView({
type: "form",
resModel: "partner",
resId: 1,
serverData,
arch: `
<form>
<sheet>
<group>
<field name="selection" widget="priority" options="{'autosave': False}"/>
</group>
</sheet>
</form>`,
mockRPC(_route, { method }) {
if (method === "write") {
assert.step("write");
}
},
});
const stars = target.querySelectorAll(
".o_field_widget .o_priority a.o_priority_star.fa-star-o"
);
await click(stars[stars.length - 1]);
assert.verifySteps([]);
});
});
@@ -570,4 +570,33 @@ QUnit.module("Fields", (hooks) => {
assert.verifySteps(["write"]);
}
);
QUnit.test(
"StateSelectionField - prevent auto save with autosave option",
async function (assert) {
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<sheet>
<group>
<field name="selection" widget="state_selection" options="{'autosave': False}"/>
</group>
</sheet>
</form>`,
resId: 1,
mockRPC(_route, { method }) {
if (method === "write") {
assert.step("write");
}
},
});
await click(target, ".o_field_widget.o_field_state_selection .o_status");
await click(target, ".dropdown-menu .dropdown-item:last-child");
assert.verifySteps([]);
}
);
});