Skip to content

Commit

Permalink
imp: support odoo 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Oct 21, 2024
1 parent 33557d0 commit 5b9b195
Show file tree
Hide file tree
Showing 35 changed files with 169 additions and 88 deletions.
1 change: 1 addition & 0 deletions src/js/flow-typed/odoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare type OdooSession = {
storeData: Object,
[string]: number | string,
};
declare type OdooSessionInfo = Object;
declare type OdooLongpollingItem = [string, string] | {...};
declare type OdooSearchResponse = Object;

Expand Down
8 changes: 4 additions & 4 deletions src/js/page/loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import registerCommonFuncs from '@odoo/commands/common/__all__';
import OdooTerminal from '@odoo/terminal';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import getOdooService from '@odoo/utils/get_odoo_service';
import getUID from '@odoo/utils/get_uid';
import getUsername from '@odoo/utils/get_username';
import getUID from '@odoo/net_utils/get_uid';
import getUsername from '@odoo/net_utils/get_username';
import isBackOffice from '@odoo/utils/is_backoffice';
import registerMathFuncs from '@trash/libs/math/__all__';
import registerTimeFuncs from '@trash/libs/time/__all__';
Expand Down Expand Up @@ -63,7 +63,7 @@ async function postInitTerminal(term_obj: OdooTerminal, config: TerminalOptions)
version: odoo_ver,
};
const username = await getUsername(config.elephant);
const uid = getUID();
const uid = await getUID(config.elephant);
if (uid && uid !== -1) {
vals.username = username ? username : `uid: ${uid}`;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ async function initTerminal(config: TerminalOptions, info: {[string]: mixed}) {
let lazy_loader_obj = getOdooService("@web/legacy/js/public/lazyloader");
if (typeof lazy_loader_obj !== 'undefined') {
// Caching call: see command implementation for more details.
getUID();
await getUID(config.elephant);
lazy_loader_obj = lazy_loader_obj[Symbol.for('default')];
await lazy_loader_obj.allScriptsLoaded;
}
Expand Down
4 changes: 3 additions & 1 deletion src/js/page/odoo/commands/backoffice/lang.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import searchRead from '@odoo/orm/search_read';
import callModelMulti from '@odoo/osv/call_model_multi';
import callModel from '@odoo/osv/call_model';
import getContent from '@odoo/utils/get_content';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import file2base64 from '@terminal/utils/file2base64';
import isEmpty from '@trash/utils/is_empty';
import {ARG} from '@trash/constants';
Expand Down Expand Up @@ -152,6 +152,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['name'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'name ASC'},
item => item.name,
);
Expand All @@ -162,6 +163,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['code'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'code ASC'},
item => item.code,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/backoffice/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import doAction from '@odoo/base/do_action';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDDef} from '@trash/interpreter';
import type Terminal from '@terminal/terminal';
Expand All @@ -31,6 +31,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['name'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'name ASC'},
item => item.name,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/backoffice/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import doAction from '@odoo/base/do_action';
import getParentAdapter from '@odoo/utils/get_parent_adapter';
import getOdooService from '@odoo/utils/get_odoo_service';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDDef} from '@trash/interpreter';
import type Terminal from '@terminal/terminal';
Expand Down Expand Up @@ -93,6 +93,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/caf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import callModel from '@odoo/osv/call_model';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import isEmpty from '@trash/utils/is_empty';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
Expand Down Expand Up @@ -67,6 +67,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/call.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import rpcQuery from '@odoo/rpc';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';
Expand Down Expand Up @@ -33,6 +33,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/cam.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import callModel from '@odoo/osv/call_model';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';
Expand Down Expand Up @@ -45,6 +45,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
17 changes: 8 additions & 9 deletions src/js/page/odoo/commands/common/context.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

// $FlowIgnore
import i18n from 'i18next';
import getSessionInfo from '@odoo/net_utils/get_session_info';
import getOdooSession from '@odoo/utils/get_odoo_session';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';

async function cmdContextOperation(kwargs: CMDCallbackArgs, ctx: CMDCallbackContext): Promise<mixed> {
const session = getOdooSession();
const session = getOdooSession()?.user_context || (await getSessionInfo())?.user_context;
if (typeof session === 'undefined') {
throw new Error(
i18n.t('cmdContext.error.notSession', 'Cannot find session information')
Expand All @@ -29,22 +30,20 @@ async function cmdContextOperation(kwargs: CMDCallbackArgs, ctx: CMDCallbackCont
}

if (kwargs.operation === 'set') {
session.user_context = kwargs.value;
Object.apply(session, kwargs.value);
} else if (kwargs.operation === 'write') {
Object.assign(session.user_context, kwargs.value);
Object.assign(session, kwargs.value);
} else if (kwargs.operation === 'delete') {
// $FlowFixMe
if (Object.hasOwn(session.user_context, kwargs.value)) {
// $FlowFixMe
delete session.user_context[kwargs.value];
if (Object.hasOwn(session, kwargs.value)) {
delete session[kwargs.value];
} else {
throw new Error(
i18n.t('cmdContext.error.keyNotPresent', 'The selected key is not present in the terminal context'),
);
}
}
ctx.screen.print(session.user_context);
return session.user_context;
ctx.screen.print(session);
return session;
}

export default function (): Partial<CMDDef> {
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/count.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import searchCount from '@odoo/orm/search_count';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';
Expand All @@ -25,6 +25,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import i18n from 'i18next';
import doAction from '@odoo/base/do_action';
import createRecord from '@odoo/orm/create_record';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import Recordset from '@terminal/core/recordset';
import renderRecordCreated from '@odoo/templates/record_created';
import {ARG} from '@trash/constants';
Expand Down Expand Up @@ -43,6 +43,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/depends.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import callModel from '@odoo/osv/call_model';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import isEmpty from '@trash/utils/is_empty';
import {ARG} from '@trash/constants';
Expand Down Expand Up @@ -55,6 +55,7 @@ function getOptions(this: Terminal, arg_name: string): Promise<Array<string>> {
[],
['name'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'name ASC'},
item => item.name,
);
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/common/info.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import i18n from 'i18next';
import getOdooRoot from '@odoo/utils/get_odoo_root';
import getUrlInfo from '@odoo/utils/get_url_info';
import getUID from '@odoo/utils/get_uid';
import getUserName from '@odoo/utils/get_username';
import getUID from '@odoo/net_utils/get_uid';
import getUserName from '@odoo/net_utils/get_username';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';
Expand All @@ -23,7 +23,7 @@ async function cmdInfo(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCallback
res = hasProps ? activeProps.resModel : getUrlInfo('hash', 'model');
}
} else if (kwargs.user_id) {
res = getUID();
res = await getUID(true);
} else if (kwargs.user_login) {
res = await getUserName(true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import callModelMulti from '@odoo/osv/call_model_multi';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import {searchModules} from './__utils__';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
Expand Down Expand Up @@ -57,6 +57,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['name'],
this.getContext(),
undefined,
{orderBy: 'name ASC'},
item => item.name,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/jstest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import {ARG} from '@trash/constants';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import type {CMDCallbackArgs, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';

Expand All @@ -30,6 +30,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['name'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'name ASC'},
item => item.name,
);
Expand Down
5 changes: 3 additions & 2 deletions src/js/page/odoo/commands/common/login.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// $FlowIgnore
import i18n from 'i18next';
import getOdooSession from '@odoo/utils/get_odoo_session';
import cachedCallService from '@odoo/utils/cached_call_service';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedCallService from '@odoo/net_utils/cached_call_service';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';
Expand Down Expand Up @@ -63,6 +63,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['login'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'login ASC'},
item => item.name,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/metadata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// $FlowIgnore
import i18n from 'i18next';
import callModelMulti from '@odoo/osv/call_model_multi';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import renderMetadata from '@odoo/templates/metadata';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
Expand Down Expand Up @@ -57,6 +57,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/read.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import i18n from 'i18next';
import callModel from '@odoo/osv/call_model';
import searchRead from '@odoo/orm/search_read';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import Recordset from '@terminal/core/recordset';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
Expand Down Expand Up @@ -62,6 +62,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
3 changes: 2 additions & 1 deletion src/js/page/odoo/commands/common/search.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import i18n from 'i18next';
import searchRead from '@odoo/orm/search_read';
import getFieldsInfo from '@odoo/orm/get_fields_info';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {default as Recordset} from '@terminal/core/recordset';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
Expand Down Expand Up @@ -128,6 +128,7 @@ function getOptions(this: Terminal, arg_name: string) {
[],
['model'],
this.getContext({active_test: true}),
undefined,
{orderBy: 'model ASC'},
item => item.model,
);
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/common/uhg.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import i18n from 'i18next';
import callModel from '@odoo/osv/call_model';
import callModelMulti from '@odoo/osv/call_model_multi';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import getUID from '@odoo/utils/get_uid';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import getUID from '@odoo/net_utils/get_uid';
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
import {ARG} from '@trash/constants';
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
import type Terminal from '@odoo/terminal';

async function cmdUserHasGroups(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCallbackContext) {
const OdooVerMajor = getOdooVersion('major');
if (typeof OdooVerMajor === 'number' && OdooVerMajor >= 18) {
return callModelMulti<boolean>('res.users', [getUID()], 'has_group', [kwargs.group.join(',')], null, this.getContext()).then(
return callModelMulti<boolean>('res.users', [await getUID(true)], 'has_group', [kwargs.group.join(',')], null, this.getContext()).then(
result => {
ctx.screen.print(result);
return result;
Expand Down
Loading

0 comments on commit 5b9b195

Please sign in to comment.