콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5364 화면

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.

베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
3
5월 25
2016
1
4월 25
1508
3
9월 24
14545
2
2월 24
2653
1
7월 23
2874