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

I'm trying to create a field “complete_name” that displays a hierarchy name similar to whats done on the product categories grid but I can't seem to get it to work. It just puts Odoo in an endless loading screen when I access the relevant view using the new field "complete_name".

I have tried to copy the code used in \addons/product/product.py and migrate to work with Odoo 9 API by using compute instead of .function type but it did not work.

Can someone help me understand whats wrong? Below is my model class which works fine without the complete_name field in my view.

class cb_public_catalog_category( models.Model ):
    _name = "cb.public.catalog.category"
    _parent_store = True
    parent_left = newFields.Integer( index = True )
    parent_right = newFields.Integer( index = True )
    name = newFields.Char( string = 'Category Name' )
    child_id = newFields.One2many( 'catalog.category', 'parent_id', string = 'Child Categories' ) complete_name = newFields.Char( compute = '_name_get_fnc', string = 'Name' )
   
def _name_get_fnc( self ):
    res = self.name_get( self )
    return dict( res )

 

아바타
취소
작성자

I included a link to the Odoo 9 code on github but for some reason it didn't save. Here is the link to product.py (https://github.com/odoo/odoo/blob/9.0/addons/product/product.py#L204)

작성자 베스트 답변

After further review I I have the answer to my own question. It turns out as with a lot of things its very simple

and I was just doing it all wrong. lol

Simply use "_inherit" and inherit the product.category model. This gives access to all the functions and fieldsof product.category including the complete_name fieldand computes the name from my custom model data. I wasable to remove my _name_get_func and just use the inheritedfunction.

The final model definition is below. Once this update was complete I was able to add a "complete_name" fieldto my view and the results were as desired!

    class cb_public_catalog_category( models.Model ):
         _name = "cb.public.catalog.category"
        _inherit = 'product.category'
         _parent_store = True
         parent_left = newFields.Integer( index = True )
         parent_right = newFields.Integer( index = True )
         name = newFields.Char( string = 'Category Name' )
         child_id = newFields.One2many( 'cb.public.catalog.category', 'parent_id', string = 'Child Categories' )
아바타
취소
관련 게시물 답글 화면 활동
2
3월 24
1911
2
11월 19
6753
1
5월 17
3254
2
9월 16
9085
5
5월 16
2669