Community mailing list archives

community@mail.odoo.com

Path Complete Name for store function not worked for new API

by
hans.yonathan
- 08/04/2015 03:13:23
Hi Odoo Community,

There's a question for new API on Odoo on store function,
I want to create a module to stored the full path name of the ledger account,
I found there's some kind of code on stock location that fit my requirement.
is it something like this:

        'complete_name': fields.function(_complete_name, type='char', string="Location Name",
                            store={'stock.location': (_get_sublocations, ['name', 'location_id', 'active'], 10)}),


    def _complete_name(self, cr, uid, ids, name, args, context=None):
        """ Forms complete name of location from parent location to child location.
        @return: Dictionary of values
        """
        res = {}
        for m in self.browse(cr, uid, ids, context=context):
            res[m.id] = m.name
            parent = m.location_id
            while parent:
                res[m.id] = parent.name + ' / ' + res[m.id]
                parent = parent.location_id
        return res

    def _get_sublocations(self, cr, uid, ids, context=None):
        """ return all sublocations of the given stock locations (included) """
        if context is None:
            context = {}
        context_with_inactive = context.copy()
        context_with_inactive['active_test'] = False
        return self.search(cr, uid, [('id', 'child_of', ids)], context=context_with_inactive)



But because my module want to use a new api,
I created it like this:

    def _get_fal_one_full_name(self, elmt, level=6):
        if elmt.parent_id:
            parent_path = self._get_fal_one_full_name(elmt.parent_id, level-1) + " / "
        else:
            parent_path = ''
        return parent_path + elmt.code + ' ' + elmt.name
        
    @api.one
    @api.depends('name', 'code', 'parent_id', 'parent_id.code', 'parent_id.name', 'parent_id.type', 'parent_id.active')
    def _get_fal_full_name(self):
        children_ids = self.search([('id', 'child_of', self.id)])
        for children_id in children_ids:
            print children_id
            children_id.fal_complete_name = self._get_fal_one_full_name(children_id)
        
    fal_complete_name = fields.Char(compute=_get_fal_full_name,
                           string='Full Name', readonly=True, store=True)


The problem is the code is not worked, it just update the first level of children.
Its weird because when I print the children_id, its print all the children that I want.
But the system not update it.

Is there someone can help me?

Thank You.