Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Creating a New Field Type Odoo ?

By
salman
on 2/27/15, 9:14 AM 669 views

I want to create a new field type , so is there any documentation on how to create a new field type api for example fields.char or fields.date such that I can begin from it .

I don't think there is any (official) documentation on that, but you should look through the code. Depending on your Odoo version (7 or 8 and up) the field definitions are either on osv.osv or Model class. You could use for example the structure used for char as a starting point. Disclaimer: I have never done this myself and do not know how it is done precisely, but this would be my approach.

Ludo - Neobis
on 2/27/15, 9:39 AM
0
Jordan Vrtanoski
On 2/27/15, 3:52 PM

You need to start by reading the implementations in the osv.fields module. In nutshell, all fields are inherited from _column. Depending on the nature of the field you are creating, you might need to implement your own "set", "get" and "serach" methods to handle the database interaciton. Here is small example to get you started. You can read more from the sourcecode of fields.py

from openerp.osv import fields, osv
class mynewfield(fields._column):

    _type = 'char'
    def __init__(self, string="unknown", size=None, **args):
        fields._column.__init__(self, string=string, size=size or None, **args)
        # self._symbol_set_char defined to keep the backward compatibility
        self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x)
        self._symbol_set = (self._symbol_c, self._symbol_f)
fields.mynewfield = mynewfield

Having saed this, I strongly recommand you to try and reusing some of the existing fields and if you need specialized display in the GUI or you need specilaized GUI editor, you can write a web Widget in JavaScript withouth creating a custom fields in the OSV. There are good tutorials how to create new Widgets and are asy to follow.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/27/15, 9:14 AM
Seen: 669 times
Last updated: 3/16/15, 8:10 AM