Skip to content

Commit 2fe3c4f

Browse files
committed
imp: command whoami: support odoo +18.2
1 parent 2d5e303 commit 2fe3c4f

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

src/js/page/odoo/commands/common/whoami.mjs

+32-52
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpret
1414
import type Terminal from '@odoo/terminal';
1515

1616
async function cmdShowWhoAmI(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCallbackContext) {
17+
const OdooVerMajor = getOdooVersion('major');
18+
const OdooVerMinor = getOdooVersion('minor');
19+
let field_group_ids = 'groups_id';
20+
if (typeof OdooVerMajor === 'number' && typeof OdooVerMinor === 'number' && ((OdooVerMajor >= 18 && OdooVerMinor > 1) || OdooVerMajor >= 19)) {
21+
field_group_ids = 'group_ids';
22+
}
1723
const result = await searchRead(
1824
'res.users',
1925
[['id', '=', await getUID(true)]],
20-
['id', 'display_name', 'login', 'partner_id', 'company_id', 'company_ids', 'groups_id'],
26+
['id', 'display_name', 'login', 'partner_id', 'company_id', 'company_ids', field_group_ids],
2127
await this.getContext(),
2228
);
2329
if (!result.length) {
2430
throw new Error(i18n.t('cmdWhoami.error.noLogin', "Oops! can't get the login :/"));
2531
}
2632
const record = result[0];
27-
const OdooVerMajor = getOdooVersion('major');
28-
const OdooVerMinor = getOdooVersion('minor');
2933
const groups_list = [];
3034
const companies_list = [];
31-
if (typeof OdooVerMajor === 'number' && typeof OdooVerMinor === 'number' && OdooVerMajor >= 17 && OdooVerMinor > 1) {
35+
if (typeof OdooVerMajor === 'number' && typeof OdooVerMinor === 'number' && ((OdooVerMajor >= 17 && OdooVerMinor > 1) || OdooVerMajor >= 18)) {
3236
const result_tasks = await Promise.all([
3337
searchRead(
3438
'res.groups',
35-
[['id', 'in', record.groups_id]],
39+
[['id', 'in', record[field_group_ids]]],
3640
['display_name'],
3741
await this.getContext(),
3842
),
@@ -50,54 +54,30 @@ async function cmdShowWhoAmI(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCa
5054
companies_list.push(renderWhoamiListItem(company.display_name, 'res.company', company.id));
5155
}
5256
} else {
53-
if (typeof OdooVerMajor === 'number' && OdooVerMajor >= 18) {
54-
const result_tasks = await Promise.all([
55-
searchRead(
56-
'res.groups',
57-
[['id', 'in', record.groups_id]],
58-
['display_name'],
59-
await this.getContext(),
60-
),
61-
searchRead(
62-
'res.company',
63-
[['id', 'in', record.company_ids]],
64-
['display_name'],
65-
await this.getContext(),
66-
),
67-
]);
68-
69-
for (const group of result_tasks[0]) {
70-
groups_list.push(renderWhoamiListItem(group.display_name, 'res.groups', group.id));
71-
}
72-
for (const company of result_tasks[1]) {
73-
companies_list.push(renderWhoamiListItem(company.display_name, 'res.company', company.id));
74-
}
75-
} else {
76-
const result_tasks = await Promise.all([
77-
callModelMulti<$ReadOnlyArray<[number, string]>>(
78-
'res.groups',
79-
record.groups_id,
80-
'name_get',
81-
null,
82-
null,
83-
await this.getContext(),
84-
),
85-
callModelMulti<$ReadOnlyArray<[number, string]>>(
86-
'res.company',
87-
record.company_ids,
88-
'name_get',
89-
null,
90-
null,
91-
await this.getContext(),
92-
),
93-
]);
57+
const result_tasks = await Promise.all([
58+
callModelMulti<$ReadOnlyArray<[number, string]>>(
59+
'res.groups',
60+
record[field_group_ids],
61+
'name_get',
62+
null,
63+
null,
64+
await this.getContext(),
65+
),
66+
callModelMulti<$ReadOnlyArray<[number, string]>>(
67+
'res.company',
68+
record.company_ids,
69+
'name_get',
70+
null,
71+
null,
72+
await this.getContext(),
73+
),
74+
]);
9475

95-
for (const group of result_tasks[0]) {
96-
groups_list.push(renderWhoamiListItem(group[1], 'res.groups', group[0]));
97-
}
98-
for (const company of result_tasks[1]) {
99-
companies_list.push(renderWhoamiListItem(company[1], 'res.company', company[0]));
100-
}
76+
for (const group of result_tasks[0]) {
77+
groups_list.push(renderWhoamiListItem(group[1], 'res.groups', group[0]));
78+
}
79+
for (const company of result_tasks[1]) {
80+
companies_list.push(renderWhoamiListItem(company[1], 'res.company', company[0]));
10181
}
10282
}
10383

0 commit comments

Comments
 (0)