/** @odoo-module **/ import { registry } from "@web/core/registry"; import { _t } from "@web/core/l10n/translation"; import { standardFieldProps } from "@web/views/fields/standard_field_props"; import { Component, xml } from "@odoo/owl"; export class JsonTemplateWidget extends Component { static template = xml`
` static props = { ...standardFieldProps, }; setup() { console.log(this) } get isReadonly() { return true; } get_template_id() { if (!this.template_id) { try { debugger let name = this.props.name; let data = this.props.record.data; let value = data[name] || "{}" this.value = JSON.parse(value); if (!this.value || !this.value.template) { this.template_id = xml``; } else { this.template_id = this.value.template; } } catch (e) { this.template_id = xml`${e.message}`; } } return this.template_id; } } export const JsonTemplateField = { component: JsonTemplateWidget, displayName: _t("Json Template"), supportedTypes: ["char", "text"], isEmpty: () => false }; registry.category("fields").add("json_template", JsonTemplateField);