This question has been flagged
2 Replies
4342 Views

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 )

 

Avatar
Discard
Author

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)

Author Best Answer

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' )
Avatar
Discard