@bergetai/odoo-cli 0.12.6 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +20 -1
- package/dist/commands/models.js +58 -0
- package/dist/filter.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ odoo models fields res.partner --filter "^email" --json
|
|
|
46
46
|
odoo models fields crm.lead --custom # only x_* custom fields
|
|
47
47
|
odoo models read res.partner --ids 51,52 --fields name,city
|
|
48
48
|
odoo models read crm.lead --search "microsoft" --json # ilike on name (max 100)
|
|
49
|
+
odoo models search mail.activity --domain '[["user_id","=",39],["date_deadline","<=","2026-09-25"]]' --json
|
|
50
|
+
odoo models search mail.activity --filter user_id=39 --fields res_id,summary,date_deadline --json
|
|
49
51
|
|
|
50
52
|
# List and inspect records
|
|
51
53
|
odoo crm leads list --open --limit 20
|
|
@@ -184,7 +186,7 @@ Note: `odoo --version` prints the CLI's own version; `odoo version` queries the
|
|
|
184
186
|
- Read-only Helpdesk surface (`helpdesk tickets list/show`) — `--open`/`--closed` via stage `fold`, strict team-scoped stage resolution, module-not-installed error (exit 4)
|
|
185
187
|
- Read-only Project surface (`project list/show`) — `--user` (project manager) and `--tag` filters, archived projects excluded by default, module-not-installed error (exit 4)
|
|
186
188
|
- Read-only Project task surface (`project tasks list/show`) — `--project` (required on list, resolved by name or id), project-scoped `--stage`, `--assignee` (many2many `user_ids`), `--tag`, `--priority` (0/Low, 1/High), `--open`/`--closed` via the task's `is_closed` flag, `--domain`/`--filter`, table/JSON output with `search_count` envelope, module-not-installed error (exit 4)
|
|
187
|
-
- Generic model surface (`models fields/read`) — introspect and
|
|
189
|
+
- Generic model surface (`models fields/read/search`) — introspect, read and search any model exposed through `execute_kw`: `fields` lists `fields_get` metadata (type, label, selection, relation, required, store) with `--filter <regex>` (case-insensitive on field name or label) and `--custom` (only `x_*` fields); `read` fetches up to 100 records by `--ids 1,2,3` or a name ilike `--search`, with `--fields a,b,c` (default: name); `search` runs an arbitrary domain via `--domain <json>` (or repeatable `--filter f=v`, mutually exclusive) with `--fields` (default: id[,name]), `--limit`/`--offset`/`--order`, and `--include-archived` (runs with `active_test: false`; eager-fetches rows other list engines hide by default). Unknown models/fields use the standard error taxonomy
|
|
188
190
|
- Documents surface (`documents`) — `tree` (hierarchical folder listing with `--count`/`--depth`/`--folder`), `records list/show` (folders excluded by default, `--type folder|binary|url|all`, `--folder`/`--owner`/`--partner`/`--tag`), `folders list`, `records create` (folder via `--folder-type folder`, link via `--link <url>`), `records update` (move via `--folder`), `records delete`, `upload` (local file → base64 `datas`, MIME guessed from extension, `--dry-run` previews without sending bytes), and `records download <id>` (binary document → local file, `--out <path>`/`--force`, `--out -` streams to stdout). Everywhere a `--folder` is accepted, folders resolve by name, numeric id, or nested `'Parent > Child'` path (segments resolved within their parent, which disambiguates repeated folder names). Folders are `documents.document` rows with `type='folder'`; the hierarchy is `folder_id`. Module-not-installed error (exit 4)
|
|
189
191
|
- Writes (`create`, `update`, `delete`) — single-call atomic batch `write`, client-side no-op diffing, delete convergence with `skipped` ids, post-failure "record may have been created" hint on `create`
|
|
190
192
|
- `--dry-run` for all mutations — full validation, resolution, and before/after diffs without mutating
|
package/dist/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ import { signTemplatesCreateFromDocumentCommand, signTemplatesListCommand, signT
|
|
|
16
16
|
import { invoicesPrecedentCommand, linesAddCommand, linesUpdateCommand, ordersCreateCommand, ordersListCommand, ordersReadCommand, ordersUpdateCommand, pdfCommand, plansListCommand, plansPricingCreateCommand, plansPricingListCommand, plansPricingUpdateCommand, } from "./commands/sales.js";
|
|
17
17
|
import { messagesDeleteCommand, messagesListCommand, messagesScrubCommand, messagesShowCommand, } from "./commands/messages.js";
|
|
18
18
|
import { contactsDeleteCommand, contactsListCommand, contactsShowCommand, listsListCommand, listsShowCommand, tracesDeleteCommand, tracesListCommand, tracesShowCommand, } from "./commands/marketing.js";
|
|
19
|
-
import { modelsFieldsCommand, modelsReadCommand, } from "./commands/models.js";
|
|
19
|
+
import { modelsFieldsCommand, modelsReadCommand, modelsSearchCommand, } from "./commands/models.js";
|
|
20
20
|
import { footprintCommand, } from "./commands/footprint.js";
|
|
21
21
|
import { CliError } from "./errors.js";
|
|
22
22
|
import { applyGlobalOptions, enforceTransportSecurity, DEFAULT_TIMEOUT, } from "./global-options.js";
|
|
@@ -1373,6 +1373,25 @@ Examples:
|
|
|
1373
1373
|
.action(async (model, opts) => {
|
|
1374
1374
|
await run((g) => modelsReadCommand(model, opts, g), program);
|
|
1375
1375
|
});
|
|
1376
|
+
models
|
|
1377
|
+
.command("search")
|
|
1378
|
+
.description("search records by domain (search_read; use --fields, --limit, --order)")
|
|
1379
|
+
.argument("<model>", "model technical name, e.g. mail.activity")
|
|
1380
|
+
.option("--domain <json>", 'Odoo domain as a JSON array, e.g. [["date_deadline","<=","2026-01-31"]]')
|
|
1381
|
+
.option("--filter <field=value>", "equality filter on raw values (repeatable); many2one values must be numeric ids", collect, [])
|
|
1382
|
+
.option("--fields <a,b,c>", "fields to fetch (default: id[,name])")
|
|
1383
|
+
.option("--limit <n>", "max records (default: 50)", "50")
|
|
1384
|
+
.option("--offset <n>", "skip the first n records", "0")
|
|
1385
|
+
.option("--order <order>", 'sort order, e.g. "date_deadline asc"')
|
|
1386
|
+
.option("--include-archived", "match archived records too (runs with active_test: false)")
|
|
1387
|
+
.addHelpText("after", `
|
|
1388
|
+
Examples:
|
|
1389
|
+
$ odoo models search mail.activity --domain '[["user_id","=",39],["date_deadline","<=","2026-09-25"]]' --json
|
|
1390
|
+
$ odoo models search mail.activity --filter user_id=39 --fields res_id,summary,date_deadline --json
|
|
1391
|
+
$ odoo models search crm.lead --domain '[["team_id","=",2]]' --order "create_date desc" --limit 20 --json`)
|
|
1392
|
+
.action(async (model, opts) => {
|
|
1393
|
+
await run((g) => modelsSearchCommand(model, opts, g), program);
|
|
1394
|
+
});
|
|
1376
1395
|
return program;
|
|
1377
1396
|
}
|
|
1378
1397
|
async function run(fn, program) {
|
package/dist/commands/models.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { buildFilterClauses, parseDomain } from "../filter.js";
|
|
1
2
|
import { notFoundError, usageError } from "../errors.js";
|
|
2
3
|
import { fieldsGet, ModelFields } from "../model.js";
|
|
3
4
|
import { colorEnabled, printJson } from "../output.js";
|
|
4
5
|
import { authenticatedClient } from "../resource.js";
|
|
5
6
|
import { formatTable, humanCell } from "../table.js";
|
|
6
7
|
const MAX_READ = 100;
|
|
8
|
+
function parseCount(raw, flag) {
|
|
9
|
+
if (!/^\d+$/.test(raw)) {
|
|
10
|
+
throw usageError(`invalid ${flag} value ${JSON.stringify(raw)}`, "expected a non-negative integer");
|
|
11
|
+
}
|
|
12
|
+
return Number(raw);
|
|
13
|
+
}
|
|
7
14
|
function parseFieldList(raw) {
|
|
8
15
|
const fields = raw
|
|
9
16
|
.split(",")
|
|
@@ -125,3 +132,54 @@ export async function modelsReadCommand(model, opts, globals) {
|
|
|
125
132
|
const rows = records.map((r) => fields.map((f) => humanCell(r[f])));
|
|
126
133
|
process.stdout.write(formatTable(headers, rows, colorEnabled(globals.noColor)) + "\n");
|
|
127
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* `models search <model>` — generic domain search over any model reachable
|
|
137
|
+
* through execute_kw. The read-side counterpart to `models read` when the
|
|
138
|
+
* name-ilike search is not enough: arbitrary domains via JSON --domain, or
|
|
139
|
+
* another model's filter surface via repeatable --filter f=v (id equality on
|
|
140
|
+
* many2one fields). Sqlite-style paging via --limit/--offset; ordering via
|
|
141
|
+
* --order. --include-archived disables active_test so archived rows are
|
|
142
|
+
* matched; on models without an `active` field it is a no-op.
|
|
143
|
+
*/
|
|
144
|
+
export async function modelsSearchCommand(model, opts, globals) {
|
|
145
|
+
if (opts.domain !== undefined && opts.filter && opts.filter.length > 0) {
|
|
146
|
+
throw usageError("--domain and --filter are mutually exclusive", "pick one filtering form");
|
|
147
|
+
}
|
|
148
|
+
const limit = parseCount(opts.limit, "--limit");
|
|
149
|
+
const offset = parseCount(opts.offset, "--offset");
|
|
150
|
+
const client = await authenticatedClient(globals);
|
|
151
|
+
const meta = await ModelFields.load(client, model);
|
|
152
|
+
const domain = [];
|
|
153
|
+
if (opts.domain !== undefined) {
|
|
154
|
+
domain.push(...parseDomain(opts.domain));
|
|
155
|
+
}
|
|
156
|
+
else if (opts.filter && opts.filter.length > 0) {
|
|
157
|
+
domain.push(...buildFilterClauses(opts.filter, meta, {}, `run \`odoo models fields ${model}\` to list available fields`));
|
|
158
|
+
}
|
|
159
|
+
const defaultFields = meta.get("name") ? ["id", "name"] : ["id"];
|
|
160
|
+
const fields = opts.fields !== undefined ? parseFieldList(opts.fields) : defaultFields;
|
|
161
|
+
for (const field of fields) {
|
|
162
|
+
if (field !== "id" && !meta.get(field)) {
|
|
163
|
+
throw usageError(`unknown field ${JSON.stringify(field)} on ${model}`, "run `odoo models fields <model>` to list available fields");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const context = opts.includeArchived
|
|
167
|
+
? { active_test: false }
|
|
168
|
+
: undefined;
|
|
169
|
+
const kwargs = { fields, limit, offset, order: opts.order ?? "id asc" };
|
|
170
|
+
if (context)
|
|
171
|
+
kwargs.context = context;
|
|
172
|
+
const [records, count] = await Promise.all([
|
|
173
|
+
client.executeKw(model, "search_read", [domain], kwargs),
|
|
174
|
+
client.executeKw(model, "search_count", [domain], {
|
|
175
|
+
...(context ? { context } : {}),
|
|
176
|
+
}),
|
|
177
|
+
]);
|
|
178
|
+
if (globals.json) {
|
|
179
|
+
printJson({ model, records, count, limit, offset });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const headers = fields.map((f) => meta.get(f)?.string ?? f);
|
|
183
|
+
const rows = records.map((r) => fields.map((f) => humanCell(r[f])));
|
|
184
|
+
process.stdout.write(formatTable(headers, rows, colorEnabled(globals.noColor)) + "\n");
|
|
185
|
+
}
|
package/dist/filter.js
CHANGED
|
@@ -33,7 +33,7 @@ export function parseFilterScalar(raw) {
|
|
|
33
33
|
* many2one fields only accept numeric ids — a non-numeric value is a usage
|
|
34
34
|
* error pointing at the resolution flags, never a silently empty result.
|
|
35
35
|
*/
|
|
36
|
-
export function buildFilterClauses(filters, fields, resolutionHints) {
|
|
36
|
+
export function buildFilterClauses(filters, fields, resolutionHints, unknownFieldHint) {
|
|
37
37
|
const clauses = [];
|
|
38
38
|
for (const filter of filters) {
|
|
39
39
|
const eq = filter.indexOf("=");
|
|
@@ -44,7 +44,8 @@ export function buildFilterClauses(filters, fields, resolutionHints) {
|
|
|
44
44
|
const rawValue = filter.slice(eq + 1);
|
|
45
45
|
const meta = fields.get(field);
|
|
46
46
|
if (!meta) {
|
|
47
|
-
throw usageError(`unknown field ${JSON.stringify(field)} in --filter`,
|
|
47
|
+
throw usageError(`unknown field ${JSON.stringify(field)} in --filter`, unknownFieldHint ??
|
|
48
|
+
"check the field name with `odoo crm leads show <id> --all-fields`");
|
|
48
49
|
}
|
|
49
50
|
const value = parseFilterScalar(rawValue);
|
|
50
51
|
if (meta.type === "many2one" &&
|