1
votes

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. So new custom field type has existing and new functionlity.

Odoo allow create custom field type? 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

1
@TadeuszKarpinski Thanks for reply.Actually we want to create own custom binary type for upload that binary to cloud. We use that custom binary field in UI and user pick image/video/doc ans save record then picked image/video/doc will upload to cloud.Upload logic will bind into Custom field type file.Girish Ghoda

1 Answers

0
votes

Yes, Odoo allows creation of custom field type. Conceptually, you will need to do the steps below:

  1. Implement a subclass of Odoo AbstractField in your javascript.
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. 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. And then extend from there.

  1. Let Odoo knows that it should use the custom widget in the xml
<field name="content" widget="my_custom_field" /> 

You can look for more information in this example blog post I found.