Skip to content

Commit

Permalink
imp: support odoo 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Nov 20, 2023
1 parent 9c923e1 commit fa945ac
Show file tree
Hide file tree
Showing 28 changed files with 302 additions and 137 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Changelog

**10.4.2**

```
IMP: Browse action icon badge (issue #129)
```

**10.4.1**

```
IMP: Tests messages
FIX: Trash: Interpreter (issue #128)
FIX: TraSH: Interpreter (issue #128)
FIX: User input: key up (prev. history)
```

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"moment": "readonly",
"odoo": "readonly",
"owl": "readonly",
"luxon": "readonly",
"openerp": "off"
},
"rules": {
Expand Down
6 changes: 4 additions & 2 deletions src/js/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const COMPATIBLE_VERSIONS = [
'saas~14',
'15.',
'saas~15',
'16.0',
'saas~16.0',
'16.',
'saas~16',
'17.0',
'saas~17.0',
];
12 changes: 6 additions & 6 deletions src/js/page/odoo/base/do_action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import asyncSleep from '@terminal/utils/async_sleep';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import getOdooRoot from '@odoo/utils/get_odoo_root';
import doTrigger from './do_trigger';

export default async function (action, options) {
const OdooVer = getOdooVersionMajor();
if (OdooVer >= 17) {
return getOdooRoot().actionService.doAction(action, options);
} else if (OdooVer >= 14) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor >= 17) {
return await getOdooRoot().actionService.doAction(action, options);
} else if (OdooVerMajor >= 14) {
doTrigger('do-action', {action, options});
// Simulate end of the 'action'
// FIXME: This makes me cry
await asyncSleep(1800);
return {id: action};
}

return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
doTrigger('do_action', {
action: action,
options: options,
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/base/do_trigger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooEnv from '@odoo/utils/get_odoo_env';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';

export default function (event_name, event_options) {
const OdooVer = getOdooVersionMajor();
const OdooVerMajor = getOdooVersion('major');
const OdooEnv = getOdooEnv();
let trigger = null;
let context = null;
if (OdooVer >= 14) {
if (OdooVerMajor >= 14) {
trigger = OdooEnv.bus.trigger;
context = OdooEnv.bus;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/base/execute_action.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright Alexandre Díaz <dev@redneboa.es>
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import doTrigger from './do_trigger';

export default function (payload) {
const OdooVer = getOdooVersionMajor();
if (OdooVer < 15) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor < 15) {
return;
}
doTrigger('execute-action', payload);
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/base/show_effect.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright Alexandre Díaz <dev@redneboa.es>
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import doTrigger from './do_trigger';

export default function (type, options) {
const OdooVer = getOdooVersionMajor();
if (OdooVer < 15) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor < 15) {
return;
}
const payload = Object.assign({}, options, {type: type});
Expand Down
2 changes: 1 addition & 1 deletion src/js/page/odoo/commands/backoffice/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import doAction from '@odoo/base/do_action';
import {ARG} from '@trash/constants';

async function cmdCallAction(kwargs) {
return doAction(kwargs.action, kwargs.options);
return await doAction(kwargs.action, kwargs.options);
}

export default {
Expand Down
5 changes: 3 additions & 2 deletions src/js/page/odoo/commands/backoffice/effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import showEffect from '@odoo/base/show_effect';
import getOdooService from '@odoo/utils/get_odoo_service';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import isEmpty from '@terminal/utils/is_empty';
import {ARG} from '@trash/constants';

async function cmdShowEffect(kwargs, screen) {
if (getOdooVersionMajor() < 15) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor < 15) {
// Soft-Error
screen.printError('This command is only available in Odoo 15.0+');
return;
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/backoffice/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import doAction from '@odoo/base/do_action';
import getParentAdapter from '@odoo/utils/get_parent_adapter';
import getOdooService from '@odoo/utils/get_odoo_service';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import {ARG} from '@trash/constants';

function openSelectCreateDialog(model, title, domain, on_selected) {
const OdooVer = getOdooVersionMajor();
if (OdooVer < 16) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor < 16) {
const dialogs = getOdooService('web.view_dialogs');
const dialog = new dialogs.SelectCreateDialog(getParentAdapter(), {
res_model: model,
Expand Down
10 changes: 5 additions & 5 deletions src/js/page/odoo/commands/common/barcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooService from '@odoo/utils/get_odoo_service';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import asyncSleep from '@terminal/utils/async_sleep';
import {ARG} from '@trash/constants';

Expand All @@ -17,8 +17,8 @@ const AVAILABLE_BARCODE_COMMANDS = [
];

function getBarcodeEvent(data) {
const OdooVer = getOdooVersionMajor();
if (OdooVer >= 16) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor >= 16) {
return new KeyboardEvent('keydown', {
key: data,
});
Expand All @@ -31,8 +31,8 @@ function getBarcodeEvent(data) {
}

function getBarcodeInfo(barcodeService) {
const OdooVer = getOdooVersionMajor();
if (OdooVer >= 16) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor >= 16) {
return [
`Max. time between keys (ms): ${barcodeService.barcodeService.maxTimeBetweenKeysInMs}`,
'Reserved barcode prefixes: O-BTN., O-CMD.',
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/common/context.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooSession from '@odoo/utils/get_odoo_session';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import {ARG} from '@trash/constants';

const session = getOdooSession();

async function cmdContextOperation(kwargs, screen) {
const OdooVer = getOdooVersionMajor();
if (OdooVer >= 15) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor >= 15) {
if (
kwargs.operation === 'set' ||
kwargs.operation === 'write' ||
Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/common/depends.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import callModel from '@odoo/osv/call_model';
import cachedSearchRead from '@odoo/utils/cached_search_read';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import isEmpty from '@terminal/utils/is_empty';
import {ARG} from '@trash/constants';

function sanitizeCmdModuleDepends(module_name) {
const OdooVer = getOdooVersionMajor();
if (OdooVer >= 16) {
const OdooVerMajor = getOdooVersion('major');
if (OdooVerMajor >= 16) {
return `_______${module_name}`;
}
return module_name;
Expand Down
49 changes: 39 additions & 10 deletions src/js/page/odoo/commands/common/now.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
// Copyright Alexandre Díaz <dev@redneboa.es>
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import getOdooVersion from '@odoo/utils/get_odoo_version';
import getOdooService from '@odoo/utils/get_odoo_service';
import getUserTZ from '@odoo/utils/get_user_tz';
import {ARG} from '@trash/constants';

async function cmdNow(kwargs, screen) {
const time = getOdooService('web.time');
const time = getOdooService('web.time', '@web/core/l10n/dates');
const OdooVerMajor = getOdooVersion('major');
let res = false;
if (kwargs.type === 'full') {
if (kwargs.tz) {
res = moment().format(time.getLangDatetimeFormat());
if (OdooVerMajor >= 17) {
if (kwargs.tz) {
res = time.formatDateTime(luxon.DateTime.local().setZone(getUserTZ()));
} else {
res = time.serializeDateTime(luxon.DateTime.local());
}
} else {
res = time.datetime_to_str(new Date());
if (kwargs.tz) {
res = moment().format(time.getLangDatetimeFormat());
} else {
res = time.datetime_to_str(new Date());
}
}
} else if (kwargs.type === 'date') {
if (kwargs.tz) {
res = moment().format(time.getLangDateFormat());
if (OdooVerMajor >= 17) {
if (kwargs.tz) {
res = time.formatDate(luxon.DateTime.local().setZone(getUserTZ()));
} else {
res = time.serializeDate(luxon.DateTime.local());
}
} else {
res = time.date_to_str(new Date());
if (kwargs.tz) {
res = moment().format(time.getLangDateFormat());
} else {
res = time.date_to_str(new Date());
}
}
} else if (kwargs.type === 'time') {
if (kwargs.tz) {
res = moment().format(time.getLangTimeFormat());
if (OdooVerMajor >= 17) {
if (kwargs.tz) {
res = time
.formatDateTime(luxon.DateTime.local().setZone(getUserTZ()))
.split(' ')[1];
} else {
res = time.serializeDateTime(luxon.DateTime.local()).split(' ')[1];
}
} else {
res = time.time_to_str(new Date());
if (kwargs.tz) {
res = moment().format(time.getLangTimeFormat());
} else {
res = time.time_to_str(new Date());
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/page/odoo/commands/common/ref.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import callModel from '@odoo/osv/call_model';
import getOdooVersionMajor from '@odoo/utils/get_odoo_version_major';
import getOdooVersion from '@odoo/utils/get_odoo_version';
import {ARG} from '@trash/constants';

async function cmdRef(kwargs, screen) {
const OdooVer = getOdooVersionMajor();
const OdooVerMajor = getOdooVersion('major');
const tasks = [];
for (const xmlid of kwargs.xmlid) {
if (OdooVer < 15) {
if (OdooVerMajor < 15) {
tasks.push(
callModel(
'ir.model.data',
Expand Down
Loading

0 comments on commit fa945ac

Please sign in to comment.