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

How to create a complete_name field for a custom modules categories hierarchy like done in Product Categories?

By
Jesse Rye
on 9/19/16, 10:56 AM 163 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 )

 

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)

Jesse Rye
on 9/19/16, 12:32 PM
0
Jesse Rye
On 9/20/16, 10:20 AM

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

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: 9/19/16, 10:56 AM
Seen: 163 times
Last updated: 9/20/16, 10:20 AM