简体   繁体   English

创建新的自定义字段类型 Odoo

[英]Create new custom field type Odoo

I want to create custom field type with use of existing field type.Just like Odoo have field types: Char,Integer etc.I want create new Interger type with use of existind Integer field type.我想使用现有字段类型创建自定义字段类型。就像 Odoo 有字段类型:Char、Integer 等。我想使用现有的 Integer 字段类型创建新的 Interger 类型。 So new custom field type has existing and new functionlity.所以新的自定义字段类型具有现有的和新的功能。

Odoo allow create custom field type? Odoo 允许创建自定义字段类型吗? If yes then how to create custom field type?如果是,那么如何创建自定义字段类型?

I guess that inherit existing field type we can create custom field type just like we create custom module with use of inherit existing model.我想继承现有字段类型我们可以创建自定义字段类型,就像我们使用继承现有模型创建自定义模块一样。

Thank you谢谢

Yes, Odoo allows creation of custom field type.是的,Odoo 允许创建自定义字段类型。 Conceptually, you will need to do the steps below:从概念上讲,您需要执行以下步骤:

  1. Implement a subclass of Odoo AbstractField in your javascript.在您的 javascript 中实现 Odoo AbstractField 的子类。
odoo.define('my_module.fields', function(require) {
"use strict"

var registry = require('web.field_registry');
var AbstractField = require('web.AbstractField'); 
var CustomField = AbstractField.extend({

    /**
     * @override
     */    
    _renderReadonly: function () {
       //...
    }
});

// add the custom widget to Odoo's widget registry
registry.add('my_custom_field', CustomField);
})

You may not need to extend AbstractField directly since there are already a number of built-in field widgets that can be closer to your need.您可能不需要直接扩展 AbstractField,因为已经有许多可以更接近您需要的内置字段小部件。 I suggest that you get Odoo's source code and look through different field widget implementation under addons/web/static/src/js/fields/basic_fields.js to find what best suits your need.我建议您获取 Odoo 的源代码并查看addons/web/static/src/js/fields/basic_fields.js下的不同字段小部件实现,以找到最适合您需要的内容。 And then extend from there.然后从那里延伸。

  1. Let Odoo knows that it should use the custom widget in the xml让 Odoo 知道它应该使用 xml 中的自定义小部件
<field name="content" widget="my_custom_field" /> 

You can look for more information in this example blog post I found.您可以在我找到的这个示例博客文章中查找更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM