|
| 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