Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5354 Visualizzazioni

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 .

Avatar
Abbandona

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.

Risposta migliore

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.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
mag 25
2004
1
apr 25
1503
3
set 24
14529
2
feb 24
2645
1
lug 23
2870