Skip to content

Commit 3eea692

Browse files
committed
add: command 'doc'
1 parent 3fc63a1 commit 3eea692

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

_locales/en/translation.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@
276276
"value": "Name/Value/Argument"
277277
}
278278
},
279+
"cmdDoc": {
280+
"args": {
281+
"method": "The method name",
282+
"model": "The model technical name"
283+
},
284+
"definition": "Open thecnical documentation page",
285+
"detail": "Open thecnical documentation page."
286+
},
279287
"cmdEffect": {
280288
"args": {
281289
"options": "The extra options to use",

_locales/es/translation.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@
276276
"value": "Nombre/Valor/Argumento"
277277
}
278278
},
279+
"cmdDoc": {
280+
"args": {
281+
"method": "El nombre del método",
282+
"model": "El nombre técnico del modelo"
283+
},
284+
"definition": "Abre la página de documentación técnica",
285+
"detail": "Abre la página de documentación técnica."
286+
},
279287
"cmdEffect": {
280288
"args": {
281289
"options": "Las opciones adicionales para usar",

src/js/page/odoo/commands/backoffice/__all__.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cmdEffect from './effect';
77
import cmdLang from './lang';
88
import cmdSettings from './settings';
99
import cmdView from './view';
10+
import cmdDoc from './doc';
1011
import type VMachine from '@trash/vmachine';
1112

1213
export default function (vm: VMachine) {
@@ -15,4 +16,5 @@ export default function (vm: VMachine) {
1516
vm.registerCommand('lang', cmdLang());
1617
vm.registerCommand('action', cmdAction());
1718
vm.registerCommand('effect', cmdEffect());
19+
vm.registerCommand('doc', cmdDoc());
1820
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// @flow strict
2+
// Copyright Alexandre Díaz <dev@redneboa.es>
3+
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
// $FlowIgnore
6+
import i18n from 'i18next';
7+
import cachedSearchRead from '@odoo/net_utils/cached_search_read';
8+
import getOdooVersion from '@odoo/utils/get_odoo_version';
9+
import {ARG} from '@trash/constants';
10+
import type {CMDCallbackArgs, CMDCallbackContext, CMDDef} from '@trash/interpreter';
11+
import type Terminal from '@terminal/terminal';
12+
13+
async function cmdDoc(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCallbackContext): Promise<void> {
14+
const OdooVerMajor = getOdooVersion('major');
15+
if (typeof OdooVerMajor === 'number' && OdooVerMajor < 19) {
16+
// Soft-Error
17+
ctx.screen.printError(
18+
i18n.t('cmdDoc.error.incompatibleOdooVersion', 'This command is only available in Odoo 19.0+'),
19+
);
20+
return;
21+
}
22+
23+
let pathname = '/doc';
24+
if (kwargs.model) {
25+
pathname += `/${kwargs.model}`;
26+
}
27+
if (kwargs.method) {
28+
pathname += `#${kwargs.method}`;
29+
}
30+
window.location = `${window.location.origin}${pathname}`;
31+
}
32+
33+
async function getOptions(this: Terminal, arg_name: string) {
34+
if (arg_name === 'model') {
35+
return cachedSearchRead(
36+
'options_ir.model_active',
37+
'ir.model',
38+
[],
39+
['model'],
40+
await this.getContext({active_test: true}),
41+
undefined,
42+
{orderBy: 'model ASC'},
43+
item => item.model,
44+
);
45+
}
46+
return [];
47+
}
48+
49+
export default function (): Partial<CMDDef> {
50+
return {
51+
definition: i18n.t('cmdDoc.definition', 'Open thecnical documentation page'),
52+
callback: cmdDoc,
53+
options: getOptions,
54+
detail: i18n.t('cmdDoc.detail', 'Open thecnical documentation page.'),
55+
args: [
56+
[
57+
ARG.String,
58+
['m', 'model'],
59+
false,
60+
i18n.t('cmdDoc.args.model', 'The model technical name'),
61+
],
62+
[
63+
ARG.String,
64+
['me', 'method'],
65+
false,
66+
i18n.t('cmdDoc.args.method', 'The method name'),
67+
],
68+
],
69+
example: '-m sale_management',
70+
};
71+
}

0 commit comments

Comments
 (0)