@bergetai/odoo-cli 0.3.2 → 0.3.3

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/dist/cli.js CHANGED
@@ -4,6 +4,7 @@ import { authLoginCommand, authStatusCommand } from "./commands/auth.js";
4
4
  import { leadsCreateCommand, leadsDeleteCommand, leadsListCommand, leadsShowCommand, leadsUpdateCommand, crmLeads, } from "./commands/crm.js";
5
5
  import { ticketsCreateCommand, ticketsDeleteCommand, ticketsListCommand, ticketsShowCommand, ticketsUpdateCommand, helpdeskTickets, } from "./commands/helpdesk.js";
6
6
  import { addNoteCommand, listMessagesCommand, } from "./commands/notes.js";
7
+ import { activitiesListCommand, activityDoneCommand, scheduleCommand, } from "./commands/activities.js";
7
8
  import { createTaskCommand, projectListCommand, projectShowCommand, tasksListCommand, tasksShowCommand, } from "./commands/project.js";
8
9
  import { documentsDocuments, documentsListCommand, foldersListCommand, documentsShowCommand, documentsCreateCommand, documentsUpdateCommand, documentsDeleteCommand, treeCommand, uploadCommand, } from "./commands/documents.js";
9
10
  import { versionCommand } from "./commands/version.js";
@@ -130,6 +131,100 @@ Examples:
130
131
  .action(async (ids) => {
131
132
  await run((g) => leadsDeleteCommand(ids, g), program);
132
133
  });
134
+ leads
135
+ .command("add-note")
136
+ .description("add an internal Log Note to a lead/opportunity (NEVER sends email)")
137
+ .argument("<id>", "record id")
138
+ .option("--body <text>", "note body (HTML allowed)")
139
+ .option("--body-file <path>", "read note body from file ('-' for stdin)")
140
+ .addHelpText("after", `
141
+ IMPORTANT: This command creates INTERNAL notes only. These notes:
142
+ • Are NEVER sent to the customer via email
143
+ • Are only visible to internal users in Odoo
144
+ • Use subtype_id=2 (Note) and message_type=comment
145
+ • Cannot be used for customer-facing communication
146
+
147
+ This is by design to prevent accidental customer emails.
148
+
149
+ Examples:
150
+ $ odoo crm records add-note 338 --body "Internal note text"
151
+ $ odoo crm records add-note 338 --body-file note.md
152
+ $ cat note.md | odoo crm records add-note 338 --body-file -`)
153
+ .action(async (id, opts) => {
154
+ await run((g) => addNoteCommand(id, opts, g, "crm.lead"), program);
155
+ });
156
+ leads
157
+ .command("messages")
158
+ .description("list all messages for a record (emails, comments, notes)")
159
+ .argument("<id>", "record id")
160
+ .option("--limit <n>", "max messages to fetch", "50")
161
+ .option("--message-type <type>", "filter by message type (email, comment, notification)")
162
+ .option("--subtype <id>", "filter by subtype ID")
163
+ .option("--author <id>", "filter by author ID")
164
+ .option("--since <date>", "only messages after this date (YYYY-MM-DD HH:MM:SS)")
165
+ .addHelpText("after", `
166
+ Examples:
167
+ # List all messages for lead 338
168
+ $ odoo crm records messages 338
169
+
170
+ # List only internal notes
171
+ $ odoo crm records messages 338 --subtype 2
172
+
173
+ # JSON output for scripting
174
+ $ odoo crm records messages 338 --json`)
175
+ .action(async (id, opts) => {
176
+ await run((g) => listMessagesCommand(id, opts, g, "crm.lead"), program);
177
+ });
178
+ leads
179
+ .command("schedule")
180
+ .description("schedule a new activity on a record (preview with --dry-run)")
181
+ .argument("<id>", "record id")
182
+ .requiredOption("--type <name|id>", "activity type (e.g. To-Do, Call, Meeting)")
183
+ .requiredOption("--deadline <yyyy-mm-dd>", "activity deadline")
184
+ .requiredOption("--summary <text>", "short summary (max 1 sentence)")
185
+ .option("--note <text>", "optional note (1-2 lines, point to the log)")
186
+ .option("--assignee <name|id>", "assignee (login, email, or name; default: you)")
187
+ .addHelpText("after", `
188
+ A scheduled activity is the source of truth for a record's next step.
189
+ An opportunity without a scheduled activity is a red flag.
190
+
191
+ Examples:
192
+ $ odoo crm records schedule 338 --type "To-Do" --deadline 2026-08-25 \\
193
+ --summary "Send quote to Fredrik"
194
+ $ odoo crm records schedule 338 --type Meeting --deadline 2026-09-01 \\
195
+ --summary "Kickoff call" --assignee erik@berget.ai
196
+ $ odoo crm records schedule 338 --type "To-Do" --deadline 2026-08-25 \\
197
+ --summary "Send quote" --dry-run`)
198
+ .action(async (id, opts) => {
199
+ await run((g) => scheduleCommand(id, opts, g), program);
200
+ });
201
+ leads
202
+ .command("activities")
203
+ .description("list activities for a record")
204
+ .argument("<id>", "record id")
205
+ .option("--open", "only open (pending/planned) activities")
206
+ .option("--limit <n>", "max activities to fetch", "50")
207
+ .addHelpText("after", `
208
+ Examples:
209
+ $ odoo crm records activities 338
210
+ $ odoo crm records activities 338 --open --json`)
211
+ .action(async (id, opts) => {
212
+ await run((g) => activitiesListCommand(id, opts, g), program);
213
+ });
214
+ leads
215
+ .command("activity-done")
216
+ .description("mark activities as done via action_done (preview with --dry-run)")
217
+ .argument("<id...>", "activity ids")
218
+ .addHelpText("after", `
219
+ Uses action_done — the only reliable way to close an activity in Odoo
220
+ (writing state='done' directly does not work).
221
+
222
+ Examples:
223
+ $ odoo crm records activity-done 714
224
+ $ odoo crm records activity-done 714 721 --dry-run`)
225
+ .action(async (ids) => {
226
+ await run((g) => activityDoneCommand(ids, g), program);
227
+ });
133
228
  const helpdesk = program
134
229
  .command("helpdesk")
135
230
  .description("Helpdesk app (helpdesk.ticket, Enterprise)");
@@ -207,7 +302,7 @@ Examples:
207
302
  $ odoo helpdesk tickets add-note 398 --body-file note.md
208
303
  $ cat note.md | odoo helpdesk tickets add-note 398 --body-file -`)
209
304
  .action(async (id, opts) => {
210
- await run((g) => addNoteCommand(id, opts, g), program);
305
+ await run((g) => addNoteCommand(id, opts, g, "helpdesk.ticket"), program);
211
306
  });
212
307
  tickets
213
308
  .command("messages")
@@ -235,7 +330,7 @@ Examples:
235
330
  # JSON output for scripting
236
331
  $ odoo helpdesk tickets messages 398 --json`)
237
332
  .action(async (id, opts) => {
238
- await run((g) => listMessagesCommand(id, opts, g), program);
333
+ await run((g) => listMessagesCommand(id, opts, g, "helpdesk.ticket"), program);
239
334
  });
240
335
  const project = program
241
336
  .command("project")
@@ -0,0 +1,239 @@
1
+ import { OdooClient } from "../client.js";
2
+ import { resolveConfig } from "../config.js";
3
+ import { notFoundError, usageError } from "../errors.js";
4
+ import { parseDate } from "../mutation.js";
5
+ import { resolveReference } from "../model.js";
6
+ import { printJson, verbose as logVerbose } from "../output.js";
7
+ import { formatTable } from "../table.js";
8
+ /**
9
+ * Scheduled activities (mail.activity) for crm.lead records.
10
+ *
11
+ * A `mail.activity` is the source of truth for a lead's next step. It carries
12
+ * a type (To-Do, Call, Meeting, Email, ...), a deadline, an assignee, and a
13
+ * short note. `action_done` marks it complete (the only reliable way to close
14
+ * an activity — writing state='done' directly does not work in Odoo).
15
+ */
16
+ const CRM_LEAD_MODEL = "crm.lead";
17
+ async function buildClient(globals) {
18
+ const config = await resolveConfig(globals);
19
+ if (!config.url || !config.db || !config.username || !config.apiKey) {
20
+ throw usageError("missing configuration", "run 'odoo auth login' or set ODOO_URL, ODOO_DB, ODOO_USERNAME, ODOO_API_KEY");
21
+ }
22
+ const { parseDurationMs } = await import("../duration.js");
23
+ const timeoutMs = parseDurationMs(globals.timeout);
24
+ return new OdooClient(config.url, config.db, config.username, config.apiKey, { timeoutMs, verbose: globals.verbose });
25
+ }
26
+ /** Resolve the ir.model id for a technical model name (e.g. "crm.lead"). */
27
+ async function resolveResModelId(client, technicalName) {
28
+ const rows = (await client.executeKw("ir.model", "search_read", [[["model", "=", technicalName]]], { fields: ["id"], limit: 1 }));
29
+ if (rows.length === 0) {
30
+ throw notFoundError("model_not_found", `no ir.model for ${JSON.stringify(technicalName)}`);
31
+ }
32
+ return rows[0].id;
33
+ }
34
+ /**
35
+ * Schedule a new activity on a crm.lead record.
36
+ */
37
+ export async function scheduleCommand(recordId, opts, globals) {
38
+ const id = Number.parseInt(recordId, 10);
39
+ if (Number.isNaN(id) || id <= 0) {
40
+ throw usageError(`invalid lead id: ${recordId}`, "provide a positive integer");
41
+ }
42
+ const client = await buildClient(globals);
43
+ // Verify the lead exists
44
+ const leads = (await client.executeKw(CRM_LEAD_MODEL, "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
45
+ if (!leads || leads.length === 0) {
46
+ throw notFoundError("record_not_found", `crm.lead #${id} does not exist`, "check the lead id");
47
+ }
48
+ // Resolve the activity type by name or id
49
+ const activityType = await resolveReference(client, "mail.activity.type", opts.type, {
50
+ label: "activity type",
51
+ });
52
+ // Resolve the assignee (defaults to the authenticated user)
53
+ let assigneeId;
54
+ let assigneeName;
55
+ if (opts.assignee) {
56
+ const user = await resolveReference(client, "res.users", opts.assignee, {
57
+ label: "user",
58
+ searchFields: ["login", "email", "name"],
59
+ });
60
+ assigneeId = user.id;
61
+ assigneeName = user.name;
62
+ }
63
+ else {
64
+ // The authenticated user's own id is not directly exposed; resolve the
65
+ // current user via the uid returned by authenticate.
66
+ const uid = await client.authenticate();
67
+ const me = (await client.executeKw("res.users", "search_read", [[["id", "=", uid]]], { fields: ["id", "name"], limit: 1 }));
68
+ assigneeId = me[0]?.id ?? uid;
69
+ assigneeName = me[0]?.name ?? String(uid);
70
+ }
71
+ const resModelId = await resolveResModelId(client, CRM_LEAD_MODEL);
72
+ const deadline = parseDate(opts.deadline, "--deadline");
73
+ const values = {
74
+ res_model_id: resModelId,
75
+ res_id: id,
76
+ activity_type_id: activityType.id,
77
+ user_id: assigneeId,
78
+ date_deadline: deadline,
79
+ summary: opts.summary,
80
+ ...(opts.note ? { note: opts.note } : {}),
81
+ };
82
+ if (globals.verbose) {
83
+ logVerbose(`Scheduling activity on crm.lead #${id} (${leads[0].name})`, globals.verbose);
84
+ logVerbose(`Activity values: ${JSON.stringify(values, null, 2)}`, globals.verbose);
85
+ }
86
+ if (globals.dryRun) {
87
+ if (globals.json) {
88
+ printJson({
89
+ model: "mail.activity",
90
+ action: "create",
91
+ dry_run: true,
92
+ record: { model: CRM_LEAD_MODEL, id, name: leads[0].name },
93
+ values,
94
+ resolved: {
95
+ activity_type_id: [activityType.id, activityType.name],
96
+ user_id: [assigneeId, assigneeName],
97
+ },
98
+ });
99
+ }
100
+ else {
101
+ console.log(`[DRY RUN] Would schedule activity on crm.lead #${id} — ${leads[0].name}:`);
102
+ console.log(` Type: ${activityType.name} (${activityType.id})`);
103
+ console.log(` Assignee: ${assigneeName} (${assigneeId})`);
104
+ console.log(` Deadline: ${deadline}`);
105
+ console.log(` Summary: ${opts.summary}`);
106
+ if (opts.note)
107
+ console.log(` Note: ${opts.note}`);
108
+ }
109
+ return;
110
+ }
111
+ const activityId = (await client.executeKw("mail.activity", "create", [
112
+ values,
113
+ ]));
114
+ if (globals.json) {
115
+ printJson({
116
+ model: "mail.activity",
117
+ action: "create",
118
+ dry_run: false,
119
+ id: activityId,
120
+ record: { model: CRM_LEAD_MODEL, id, name: leads[0].name },
121
+ resolved: {
122
+ activity_type_id: [activityType.id, activityType.name],
123
+ user_id: [assigneeId, assigneeName],
124
+ },
125
+ });
126
+ }
127
+ else {
128
+ console.log(`✓ Activity scheduled (ID: ${activityId})`);
129
+ console.log(` Lead: crm.lead #${id} — ${leads[0].name}`);
130
+ console.log(` Type: ${activityType.name} · Deadline: ${deadline} · Assignee: ${assigneeName}`);
131
+ }
132
+ }
133
+ /**
134
+ * Mark one or more activities as done via `action_done`.
135
+ */
136
+ export async function activityDoneCommand(activityIds, globals) {
137
+ const ids = activityIds.map((raw) => {
138
+ const n = Number.parseInt(raw, 10);
139
+ if (Number.isNaN(n) || n <= 0) {
140
+ throw usageError(`invalid activity id: ${raw}`, "provide a positive integer");
141
+ }
142
+ return n;
143
+ });
144
+ const client = await buildClient(globals);
145
+ // Verify the activities exist
146
+ const rows = (await client.executeKw("mail.activity", "search_read", [[["id", "in", ids]]], { fields: ["id", "summary", "state"], limit: ids.length }));
147
+ const byId = new Map(rows.map((r) => [r.id, r]));
148
+ const missing = ids.filter((id) => !byId.has(id));
149
+ if (missing.length > 0) {
150
+ throw notFoundError("record_not_found", `no mail.activity record(s) with id(s): ${missing.join(", ")}`, "no activities were modified — aborts the whole batch when any id is missing");
151
+ }
152
+ if (globals.dryRun) {
153
+ if (globals.json) {
154
+ printJson({
155
+ model: "mail.activity",
156
+ action: "action_done",
157
+ dry_run: true,
158
+ ids,
159
+ activities: rows.map((r) => ({ id: r.id, summary: r.summary, state: r.state })),
160
+ });
161
+ }
162
+ else {
163
+ console.log(`[DRY RUN] Would mark ${ids.length} activity(ies) as done:`);
164
+ for (const r of rows) {
165
+ console.log(` #${r.id} — ${r.summary} (${r.state})`);
166
+ }
167
+ }
168
+ return;
169
+ }
170
+ await client.executeKw("mail.activity", "action_done", [ids]);
171
+ if (globals.json) {
172
+ printJson({
173
+ model: "mail.activity",
174
+ action: "action_done",
175
+ dry_run: false,
176
+ done: ids,
177
+ });
178
+ }
179
+ else {
180
+ console.log(`✓ Marked ${ids.length} activity(ies) as done: ${ids.join(", ")}`);
181
+ }
182
+ }
183
+ /**
184
+ * List activities for a crm.lead record.
185
+ */
186
+ export async function activitiesListCommand(recordId, opts, globals) {
187
+ const id = Number.parseInt(recordId, 10);
188
+ if (Number.isNaN(id) || id <= 0) {
189
+ throw usageError(`invalid lead id: ${recordId}`, "provide a positive integer");
190
+ }
191
+ const client = await buildClient(globals);
192
+ // Verify the lead exists
193
+ const leads = (await client.executeKw(CRM_LEAD_MODEL, "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
194
+ if (!leads || leads.length === 0) {
195
+ throw notFoundError("record_not_found", `crm.lead #${id} does not exist`, "check the lead id");
196
+ }
197
+ const resModelId = await resolveResModelId(client, CRM_LEAD_MODEL);
198
+ const domain = [
199
+ ["res_model_id", "=", resModelId],
200
+ ["res_id", "=", id],
201
+ ];
202
+ if (opts.open) {
203
+ domain.push(["state", "in", ["pending", "planned", "a_review"]]);
204
+ }
205
+ const limit = opts.limit ? Number.parseInt(opts.limit, 10) : 50;
206
+ const activities = (await client.executeKw("mail.activity", "search_read", [domain], {
207
+ fields: [
208
+ "id",
209
+ "activity_type_id",
210
+ "date_deadline",
211
+ "summary",
212
+ "note",
213
+ "state",
214
+ "user_id",
215
+ ],
216
+ limit,
217
+ order: "date_deadline asc",
218
+ }));
219
+ if (globals.json) {
220
+ printJson({
221
+ model: "mail.activity",
222
+ record: { model: CRM_LEAD_MODEL, id, name: leads[0].name },
223
+ count: activities.length,
224
+ activities,
225
+ });
226
+ return;
227
+ }
228
+ console.log(`Activities for crm.lead #${id}: ${leads[0].name}`);
229
+ console.log(`Found ${activities.length} activities\n`);
230
+ const rows = activities.map((a) => [
231
+ a.id.toString(),
232
+ a.state,
233
+ a.activity_type_id ? a.activity_type_id[1] : "",
234
+ a.date_deadline ? String(a.date_deadline) : "",
235
+ a.user_id ? a.user_id[1] : "",
236
+ a.summary,
237
+ ]);
238
+ console.log(formatTable(["ID", "State", "Type", "Deadline", "Assignee", "Summary"], rows, !globals.noColor));
239
+ }
@@ -3,12 +3,27 @@ import { resolveConfig } from "../config.js";
3
3
  import { notFoundError, usageError } from "../errors.js";
4
4
  import { printJson, verbose as logVerbose } from "../output.js";
5
5
  import { formatTable } from "../table.js";
6
- export async function addNoteCommand(ticketId, opts, globals) {
7
- const id = Number.parseInt(ticketId, 10);
8
- if (Number.isNaN(id) || id <= 0) {
9
- throw usageError(`invalid ticket id: ${ticketId}`, "provide a positive integer");
6
+ const THREAD_MODELS = {
7
+ "helpdesk.ticket": { model: "helpdesk.ticket", label: "ticket" },
8
+ "crm.lead": { model: "crm.lead", label: "lead" },
9
+ };
10
+ function threadModel(model) {
11
+ const spec = THREAD_MODELS[model];
12
+ if (!spec) {
13
+ throw usageError(`unsupported thread model ${JSON.stringify(model)}`, `expected one of: ${Object.keys(THREAD_MODELS).join(", ")}`);
14
+ }
15
+ return spec;
16
+ }
17
+ async function buildClient(globals) {
18
+ const config = await resolveConfig(globals);
19
+ if (!config.url || !config.db || !config.username || !config.apiKey) {
20
+ throw usageError("missing configuration", "run 'odoo auth login' or set ODOO_URL, ODOO_DB, ODOO_USERNAME, ODOO_API_KEY");
10
21
  }
11
- // Read body from file if specified
22
+ const { parseDurationMs } = await import("../duration.js");
23
+ const timeoutMs = parseDurationMs(globals.timeout);
24
+ return new OdooClient(config.url, config.db, config.username, config.apiKey, { timeoutMs, verbose: globals.verbose });
25
+ }
26
+ async function readBody(opts) {
12
27
  let body = opts.body;
13
28
  if (opts.bodyFile) {
14
29
  const fs = await import("node:fs/promises");
@@ -22,39 +37,45 @@ export async function addNoteCommand(ticketId, opts, globals) {
22
37
  if (!body || body.trim().length === 0) {
23
38
  throw usageError("note body cannot be empty", "provide --body or --body-file");
24
39
  }
25
- const config = await resolveConfig(globals);
26
- if (!config.url || !config.db || !config.username || !config.apiKey) {
27
- throw usageError("missing configuration", "run 'odoo auth login' or set ODOO_URL, ODOO_DB, ODOO_USERNAME, ODOO_API_KEY");
40
+ return body;
41
+ }
42
+ /**
43
+ * Add an internal Log Note to a mail-thread record (ticket or lead).
44
+ */
45
+ export async function addNoteCommand(recordId, opts, globals, model) {
46
+ const spec = threadModel(model);
47
+ const id = Number.parseInt(recordId, 10);
48
+ if (Number.isNaN(id) || id <= 0) {
49
+ throw usageError(`invalid ${spec.label} id: ${recordId}`, "provide a positive integer");
28
50
  }
29
- const { parseDurationMs } = await import("../duration.js");
30
- const timeoutMs = parseDurationMs(globals.timeout);
31
- const client = new OdooClient(config.url, config.db, config.username, config.apiKey, { timeoutMs, verbose: globals.verbose });
32
- // Verify ticket exists
33
- const tickets = (await client.executeKw("helpdesk.ticket", "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
34
- if (!tickets || tickets.length === 0) {
35
- throw notFoundError("ticket_not_found", `helpdesk ticket #${id} does not exist`, "check the ticket id");
51
+ const body = await readBody(opts);
52
+ const client = await buildClient(globals);
53
+ // Verify the record exists
54
+ const rows = (await client.executeKw(spec.model, "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
55
+ if (!rows || rows.length === 0) {
56
+ throw notFoundError("record_not_found", `${spec.model} #${id} does not exist`, `check the ${spec.label} id`);
36
57
  }
37
58
  // Create internal Log Note
38
59
  // CRITICAL: These parameters ensure the note is INTERNAL ONLY
39
60
  // - subtype_id=2: "Note" subtype (internal, not sent to customer)
40
61
  // - message_type="comment": Internal comment (not email)
41
- // - author_id: Use the authenticated user's partner_id
42
62
  const noteParams = {
43
- model: "helpdesk.ticket",
63
+ model: spec.model,
44
64
  res_id: id,
45
65
  body: body,
46
66
  message_type: "comment",
47
67
  subtype_id: 2, // Note subtype = internal only, NEVER sends email
48
68
  };
49
69
  if (globals.verbose) {
50
- logVerbose(`Creating internal note for ticket #${id} (${tickets[0].name})`, globals.verbose);
70
+ logVerbose(`Creating internal note for ${spec.model} #${id} (${rows[0].name})`, globals.verbose);
51
71
  logVerbose(`Note parameters: ${JSON.stringify(noteParams, null, 2)}`, globals.verbose);
52
72
  }
53
73
  if (globals.dryRun) {
54
74
  const result = {
55
75
  dry_run: true,
56
- ticket_id: id,
57
- ticket_name: tickets[0].name,
76
+ model: spec.model,
77
+ record_id: id,
78
+ record_name: rows[0].name,
58
79
  note_type: "internal_log_note",
59
80
  will_send_email: false,
60
81
  body_preview: body.substring(0, 100) + (body.length > 100 ? "..." : ""),
@@ -65,7 +86,7 @@ export async function addNoteCommand(ticketId, opts, globals) {
65
86
  }
66
87
  else {
67
88
  console.log(`[DRY RUN] Would create internal Log Note:`);
68
- console.log(` Ticket: #${id} — ${tickets[0].name}`);
89
+ console.log(` Record: ${spec.model} #${id} — ${rows[0].name}`);
69
90
  console.log(` Type: Internal note (never sent to customer)`);
70
91
  console.log(` Body length: ${body.length} characters`);
71
92
  console.log(` Body preview: ${result.body_preview}`);
@@ -77,8 +98,9 @@ export async function addNoteCommand(ticketId, opts, globals) {
77
98
  ]));
78
99
  const result = {
79
100
  note_id: noteId,
80
- ticket_id: id,
81
- ticket_name: tickets[0].name,
101
+ model: spec.model,
102
+ record_id: id,
103
+ record_name: rows[0].name,
82
104
  note_type: "internal_log_note",
83
105
  email_sent: false,
84
106
  };
@@ -87,37 +109,31 @@ export async function addNoteCommand(ticketId, opts, globals) {
87
109
  }
88
110
  else {
89
111
  console.log(`✓ Internal Log Note created (ID: ${noteId})`);
90
- console.log(` Ticket: #${id} — ${tickets[0].name}`);
112
+ console.log(` Record: ${spec.model} #${id} — ${rows[0].name}`);
91
113
  console.log(` Type: Internal note (not sent to customer)`);
92
114
  }
93
115
  }
94
116
  /**
95
- * List messages for a helpdesk ticket.
117
+ * List messages for a mail-thread record (emails, comments, notes).
96
118
  *
97
- * Fetches all messages (emails, comments, notes) associated with a ticket.
98
- * Useful for analyzing ticket history and determining if customer is waiting
99
- * for a response.
119
+ * Fetches all messages associated with the record. Useful for analyzing
120
+ * history and determining if the customer is waiting for a response.
100
121
  */
101
- export async function listMessagesCommand(ticketId, opts, globals) {
102
- const id = Number.parseInt(ticketId, 10);
122
+ export async function listMessagesCommand(recordId, opts, globals, model) {
123
+ const spec = threadModel(model);
124
+ const id = Number.parseInt(recordId, 10);
103
125
  if (Number.isNaN(id) || id <= 0) {
104
- throw usageError(`invalid ticket id: ${ticketId}`, "provide a positive integer");
126
+ throw usageError(`invalid ${spec.label} id: ${recordId}`, "provide a positive integer");
105
127
  }
106
- const config = await resolveConfig(globals);
107
- if (!config.url || !config.db || !config.username || !config.apiKey) {
108
- throw usageError("missing configuration", "run 'odoo auth login' or set ODOO_URL, ODOO_DB, ODOO_USERNAME, ODOO_API_KEY");
109
- }
110
- const { parseDurationMs } = await import("../duration.js");
111
- const timeoutMs = parseDurationMs(globals.timeout);
112
- const client = new OdooClient(config.url, config.db, config.username, config.apiKey, { timeoutMs, verbose: globals.verbose });
113
- // Verify ticket exists
114
- const tickets = (await client.executeKw("helpdesk.ticket", "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
115
- if (!tickets || tickets.length === 0) {
116
- throw notFoundError("ticket_not_found", `helpdesk ticket #${id} does not exist`, "check the ticket id");
128
+ const client = await buildClient(globals);
129
+ // Verify the record exists
130
+ const rows = (await client.executeKw(spec.model, "search_read", [[["id", "=", id]]], { fields: ["id", "name"], limit: 1 }));
131
+ if (!rows || rows.length === 0) {
132
+ throw notFoundError("record_not_found", `${spec.model} #${id} does not exist`, `check the ${spec.label} id`);
117
133
  }
118
134
  // Build domain for messages
119
135
  const domain = [
120
- ["model", "=", "helpdesk.ticket"],
136
+ ["model", "=", spec.model],
121
137
  ["res_id", "=", id],
122
138
  ];
123
139
  // Add optional filters
@@ -141,7 +157,7 @@ export async function listMessagesCommand(ticketId, opts, globals) {
141
157
  }
142
158
  const limit = opts.limit ? Number.parseInt(opts.limit, 10) : 50;
143
159
  if (globals.verbose) {
144
- logVerbose(`Fetching messages for ticket #${id}`, globals.verbose);
160
+ logVerbose(`Fetching messages for ${spec.model} #${id}`, globals.verbose);
145
161
  logVerbose(`Domain: ${JSON.stringify(domain)}`, globals.verbose);
146
162
  }
147
163
  const messages = (await client.executeKw("mail.message", "search_read", [domain], {
@@ -160,16 +176,17 @@ export async function listMessagesCommand(ticketId, opts, globals) {
160
176
  }));
161
177
  if (globals.json) {
162
178
  printJson({
163
- ticket_id: id,
164
- ticket_name: tickets[0].name,
179
+ model: spec.model,
180
+ record_id: id,
181
+ record_name: rows[0].name,
165
182
  message_count: messages.length,
166
183
  messages,
167
184
  });
168
185
  }
169
186
  else {
170
- console.log(`Messages for ticket #${id}: ${tickets[0].name}`);
187
+ console.log(`Messages for ${spec.model} #${id}: ${rows[0].name}`);
171
188
  console.log(`Found ${messages.length} messages\n`);
172
- const rows = messages.map((msg) => {
189
+ const rowsOut = messages.map((msg) => {
173
190
  const author = msg.author_id ? msg.author_id[1] : msg.email_from || "System";
174
191
  const subtype = msg.subtype_id ? msg.subtype_id[1] : "";
175
192
  const bodyPreview = msg.body
@@ -186,6 +203,6 @@ export async function listMessagesCommand(ticketId, opts, globals) {
186
203
  bodyPreview + (msg.body.length > 60 ? "..." : ""),
187
204
  ];
188
205
  });
189
- console.log(formatTable(["ID", "Date", "Type", "Subtype", "Author", "Preview"], rows, !globals.noColor));
206
+ console.log(formatTable(["ID", "Date", "Type", "Subtype", "Author", "Preview"], rowsOut, !globals.noColor));
190
207
  }
191
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bergetai/odoo-cli",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Agent-first CLI for the Odoo External API",
5
5
  "publishConfig": {
6
6
  "access": "public"