Skip to Content
Menu
This question has been flagged
1 Reply
2432 Views


I am doing technical customizing odoo 12. I have Customized "account.group" module as follow. I have added two computed fields called full_grp_name and full_codePrefix. They are calculated correctly. The problem is ordering. that is "_order = 'full_codePrefix' ". As anyone can see the order is not according to the code. For ex the last record should be at 3rd row.

How can this be corrected ? Is it bug ?

class AccountGroup(models.Model):
    _name = 'account.group'
    _inherit = 'account.group'
    _order = 'full_codePrefix'
 
    #parent_id = fields.Many2one(string = "Parent", index=True)
 
    full_grp_name = fields.Char(string="Full name", compute="get_full_name")
    full_codePrefix = fields.Char(string="Full Prefix", compute="get_full_name")
    #account_ids = field.One2many(comodel_name = 'account.account', inverse_name= 'gourp_id', string = "Accounts")
 
    parent_left = fields.Integer('Parent Left', index=True)
    parent_right = fields.Integer('Parent Right', index=True)
    child_ids = fields.One2many(comodel_name = 'account.group', inverse_name= 'parent_id', string = 'Child Account Groups')
 
    account_ids = fields.One2many('account.account', 'group_id', String='Accounts', help = 'List of accounts in the account group')
 
    def get_full_name(self):
 
        for rec in self:
            record = rec
            fname = rec.name
            fcode = rec.code_prefix
 
            while record.parent_id:
                if record.parent_id.name:
                    fname = record.parent_id.name + '-' + fname
                    fcode = record.parent_id.code_prefix + '-' + fcode
                record = record.parent_id
 
            rec.full_grp_name = fname
            rec.full_codePrefix = fcode
 
 
 
    @api.constrains('parent_id')
    def check_hierarchy(self):
        if not self._check_recursion():
            raise models.ValidationError("Error ! You can't create a recussive group")


The order is as shown below



Avatar
Discard
Best Answer

Make it like this

full_codePrefix = fields.Char(string="Full Prefix", compute="get_full_name", store=True)

Avatar
Discard
Author

I wish it works without storing computed field being store has its own problem

Unfortunately, you cannot

Author

when I add store=True the data of the field becomes invisible