[IMP] web,*: make x2ManyCommands naming consistent
*: event_booth_sale, sale_product_configurator Before this commit, the naming convention for x2m commands is not consistent with the python ORM. After this commit, the commands use the same terminology on both side. The JavaScript side has been adapted. closes odoo/odoo#133357 See: https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html?highlight=commands#odoo.fields.Command Related: odoo/enterprise#46418 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -64,7 +64,7 @@ patch(SaleOrderLineProductField.prototype, {
|
||||
this.props.record.update({
|
||||
event_id,
|
||||
event_booth_category_id,
|
||||
event_booth_pending_ids: [x2ManyCommands.replaceWith(event_booth_pending_ids)],
|
||||
event_booth_pending_ids: [x2ManyCommands.set(event_booth_pending_ids)],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ async function applyProduct(record, product) {
|
||||
await record.update({
|
||||
product_id: [product.id, product.display_name],
|
||||
product_uom_qty: product.quantity,
|
||||
product_no_variant_attribute_value_ids: [x2ManyCommands.replaceWith(noVariantPTAVIds)],
|
||||
product_no_variant_attribute_value_ids: [x2ManyCommands.set(noVariantPTAVIds)],
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -42,24 +42,24 @@ export const x2ManyCommands = {
|
||||
return [x2ManyCommands.DELETE, id, false];
|
||||
},
|
||||
// (3, id[, _]) removes relation, but not linked record itself
|
||||
FORGET: 3,
|
||||
forget(id) {
|
||||
return [x2ManyCommands.FORGET, id, false];
|
||||
UNLINK: 3,
|
||||
unlink(id) {
|
||||
return [x2ManyCommands.UNLINK, id, false];
|
||||
},
|
||||
// (4, id[, _])
|
||||
LINK_TO: 4,
|
||||
linkTo(id) {
|
||||
return [x2ManyCommands.LINK_TO, id, false];
|
||||
LINK: 4,
|
||||
link(id) {
|
||||
return [x2ManyCommands.LINK, id, false];
|
||||
},
|
||||
// (5[, _[, _]])
|
||||
DELETE_ALL: 5,
|
||||
deleteAll() {
|
||||
return [x2ManyCommands.DELETE_ALL, false, false];
|
||||
CLEAR: 5,
|
||||
clear() {
|
||||
return [x2ManyCommands.CLEAR, false, false];
|
||||
},
|
||||
// (6, _, ids) replaces all linked records with provided ids
|
||||
REPLACE_WITH: 6,
|
||||
replaceWith(ids) {
|
||||
return [x2ManyCommands.REPLACE_WITH, false, ids];
|
||||
SET: 6,
|
||||
set(ids) {
|
||||
return [x2ManyCommands.SET, false, ids];
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -754,7 +754,7 @@ export class Record extends DataPoint {
|
||||
const list = this.data[fieldName];
|
||||
for (const command of value) {
|
||||
switch (command[0]) {
|
||||
case x2ManyCommands.REPLACE_WITH:
|
||||
case x2ManyCommands.SET:
|
||||
await list._replaceWith(command[2]);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -291,7 +291,7 @@ export class StaticList extends DataPoint {
|
||||
|
||||
forget(record) {
|
||||
return this.model.mutex.exec(async () => {
|
||||
await this._applyCommands([[x2ManyCommands.FORGET, record.resId]]);
|
||||
await this._applyCommands([[x2ManyCommands.UNLINK, record.resId]]);
|
||||
await this._onUpdate();
|
||||
});
|
||||
}
|
||||
@@ -328,7 +328,7 @@ export class StaticList extends DataPoint {
|
||||
|
||||
linkTo(resId, serverData) {
|
||||
return this.model.mutex.exec(async () => {
|
||||
await this._applyCommands([[x2ManyCommands.LINK_TO, resId, serverData]]);
|
||||
await this._applyCommands([[x2ManyCommands.LINK, resId, serverData]]);
|
||||
await this._onUpdate();
|
||||
});
|
||||
}
|
||||
@@ -464,7 +464,7 @@ export class StaticList extends DataPoint {
|
||||
|
||||
_applyCommands(commands) {
|
||||
const isOnLastPage = this.limit + this.offset >= this.count;
|
||||
const { CREATE, UPDATE, DELETE, FORGET, LINK_TO, REPLACE_WITH } = x2ManyCommands;
|
||||
const { CREATE, UPDATE, DELETE, UNLINK, LINK, SET } = x2ManyCommands;
|
||||
for (const command of commands) {
|
||||
switch (command[0]) {
|
||||
case CREATE: {
|
||||
@@ -518,7 +518,7 @@ export class StaticList extends DataPoint {
|
||||
break;
|
||||
}
|
||||
case DELETE:
|
||||
case FORGET: {
|
||||
case UNLINK: {
|
||||
if (command[0] === DELETE) {
|
||||
if (!this._commands.find((c) => c[0] === CREATE && c[1] === command[1])) {
|
||||
this._commands.push([DELETE, command[1]]);
|
||||
@@ -529,7 +529,7 @@ export class StaticList extends DataPoint {
|
||||
} else {
|
||||
// FORGET
|
||||
const replaceWithIndex = this._commands.findIndex(
|
||||
(c) => c[0] === REPLACE_WITH && c[2].includes(command[1])
|
||||
(c) => c[0] === SET && c[2].includes(command[1])
|
||||
);
|
||||
if (replaceWithIndex >= 0) {
|
||||
const ids = this._commands[replaceWithIndex][2];
|
||||
@@ -538,12 +538,12 @@ export class StaticList extends DataPoint {
|
||||
);
|
||||
} else {
|
||||
const linkToIndex = this._commands.findIndex(
|
||||
(c) => c[0] === LINK_TO && c[1] === command[1]
|
||||
(c) => c[0] === LINK && c[1] === command[1]
|
||||
);
|
||||
if (linkToIndex >= 0) {
|
||||
this._commands.splice(linkToIndex, 1);
|
||||
} else {
|
||||
this._commands.push([FORGET, command[1]]);
|
||||
this._commands.push([UNLINK, command[1]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -559,7 +559,7 @@ export class StaticList extends DataPoint {
|
||||
this.count--;
|
||||
break;
|
||||
}
|
||||
case LINK_TO: {
|
||||
case LINK: {
|
||||
const record = this._createRecordDatapoint({ ...command[2], id: command[1] });
|
||||
if (!this.limit || this.records.length < this.limit) {
|
||||
this.records.push(record);
|
||||
@@ -824,7 +824,7 @@ export class StaticList extends DataPoint {
|
||||
const updateCommandsToKeep = this._commands.filter(
|
||||
(c) => c[0] === x2ManyCommands.UPDATE && ids.includes(c[1])
|
||||
);
|
||||
this._commands = [x2ManyCommands.replaceWith(ids)].concat(updateCommandsToKeep);
|
||||
this._commands = [x2ManyCommands.set(ids)].concat(updateCommandsToKeep);
|
||||
this._currentIds = [...ids];
|
||||
this.count = this._currentIds.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user