By extending the ir.qweb class in odoo/addons/base/ir , to extend and implement custom functions, the copy class structure is as follows:
# -*- coding: utf-8 -*- import ast from urlparse import urlparse from lxml import html from .qweb import QWeb, Contextifier from .assetsbundle import AssetsBundle from lxml import etree from collections import OrderedDict from odoo import api, models, tools from odoo.tools.safe_eval import assert_valid_codeobj, _BUILTINS, _SAFE_OPCODES from odoo.http import request from odoo.modules.module import get_resource_path import json from time import time import logging _logger = logging.getLogger(__name__) class IrQWebCF(models.AbstractModel, QWeb): ''' Inherit the ir.qweb class to realize the rendering output of custom attributes ''' _name = 'ir.qweb' _inherit = 'ir.qweb' def _get_field(self, record, field_name, expression, tagName, field_options, options, values): field = record._fields[field_name] field_options['tagName'] = tagName field_options['expression'] = expression field_options['type'] = field_options.get('widget', field.type) inherit_branding = options.get('inherit_branding', options.get('inherit_branding_auto') and record.check_access_rights('write', False)) field_options['inherit_branding'] = inherit_branding translate = options.get('edit_translations') and options.get('translatable') and field.translate field_options['translate'] = translate # field converter model = 'ir.qweb.field.' + field_options['type'] converter = self.env[model] if model in self.env else self.env['ir.qweb.field'] # get content content = converter.record_to_html(record, field_name, field_options) attributes = converter.attributes(record, field_name, field_options, values) return (attributes, content, inherit_branding or translate)
At runtime, it will report that QWeb, Contextifier, and AssetsBundlecannot be imported. Just change it to the following.
# -*- coding: utf-8 -*- import ast from urlparse import urlparse from lxml import html #### The next two lines #from .qweb import QWeb, Contextifier #from .assetsbundle import AssetsBundle ### Change to from odoo.addons.base.ir.ir_qweb.qweb import QWeb, Contextifier from odoo.addons.base.ir.ir_qweb.assetsbundle import AssetsBundle