[IMP] web,account: orm service: allow to create in batch
This commit changes the API of the "create" function of the orm service to better reflect the API of the corresponding method in models.py, which takes a list of record values in argument. Before this commit, a call to "create" only allowed to create a single record. Part-of: odoo/odoo#99018
This commit is contained in:
@@ -26,7 +26,7 @@ export class AccountFileUploader extends Component {
|
||||
mimetype: file.type,
|
||||
datas: file.data,
|
||||
};
|
||||
const att_id = await this.orm.create("ir.attachment", att_data, {
|
||||
const att_id = await this.orm.create("ir.attachment", [att_data], {
|
||||
...this.props.extraContext, ...this.env.searchModel.context,
|
||||
});
|
||||
this.attachmentIdsToProcess.push(att_id);
|
||||
|
||||
@@ -109,9 +109,12 @@ export class ORM {
|
||||
return this.rpc(url, params, { silent: this._silent });
|
||||
}
|
||||
|
||||
create(model, state, context) {
|
||||
validateObject("state", state);
|
||||
return this.call(model, "create", [state], { context });
|
||||
create(model, records, context) {
|
||||
validateArray("records", records);
|
||||
for (const record of records) {
|
||||
validateObject("record", record);
|
||||
}
|
||||
return this.call(model, "create", records, { context });
|
||||
}
|
||||
|
||||
nameGet(model, ids, context) {
|
||||
|
||||
@@ -1270,7 +1270,7 @@ export class Record extends DataPoint {
|
||||
);
|
||||
this.resId = resId;
|
||||
} else {
|
||||
this.resId = await this.model.orm.create(this.resModel, changes, this.context);
|
||||
this.resId = await this.model.orm.create(this.resModel, [changes], this.context);
|
||||
}
|
||||
delete this.virtualId;
|
||||
this.data.id = this.resId;
|
||||
|
||||
@@ -266,17 +266,19 @@ export class ExportDataDialog extends Component {
|
||||
}
|
||||
const id = await this.orm.create(
|
||||
"ir.exports",
|
||||
{
|
||||
name,
|
||||
export_fields: this.state.exportList.map((field) => [
|
||||
0,
|
||||
0,
|
||||
{
|
||||
name: field.name,
|
||||
},
|
||||
]),
|
||||
resource: this.props.root.resModel,
|
||||
},
|
||||
[
|
||||
{
|
||||
name,
|
||||
export_fields: this.state.exportList.map((field) => [
|
||||
0,
|
||||
0,
|
||||
{
|
||||
name: field.name,
|
||||
},
|
||||
]),
|
||||
resource: this.props.root.resModel,
|
||||
},
|
||||
],
|
||||
this.props.context
|
||||
);
|
||||
this.state.isEditingTemplate = false;
|
||||
|
||||
@@ -94,7 +94,7 @@ QUnit.test("create method", async (assert) => {
|
||||
const [query, rpc] = makeFakeRPC();
|
||||
serviceRegistry.add("rpc", rpc);
|
||||
const env = await makeTestEnv();
|
||||
await env.services.orm.create("partner", { color: "red" });
|
||||
await env.services.orm.create("partner", [{ color: "red" }]);
|
||||
assert.strictEqual(query.route, "/web/dataset/call_kw/partner/create");
|
||||
assert.deepEqual(query.params, {
|
||||
args: [
|
||||
|
||||
Reference in New Issue
Block a user