Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create function Compute fields using API in Odoo-9

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.58k
    Comment on it

    In OpenERP first, we create existing module and then creates an object in own module and then creates fields and function in module and relate it to the fields, this fields computes all related records and saves it in a database.

    Here computed field is a field whose value is computed instead of simply being read from the database. To define such a field, you can simply provide a value for the attribute compute and get result.

    The attributes that are specific to computed fields are given below.

    For example you can see below code.

    class test(osv.osv):
    @api.depends('name')
    def _compute_upper(self):
        for rec in self:
            rec.upper = rec.name.upper() if rec.name else False
    
    def _inverse_upper(self):
        for rec in self:
            rec.name = rec.upper.lower() if rec.upper else False
    
    def _search_upper(self, operator, value):
        if operator == 'like':
            operator = 'ilike'
        return [('name', operator, value)]
    _columns = {
    
           upper = fields.Char(compute='_compute_upper',
                        inverse='_inverse_upper',
                        search='_search_upper')
                }
    test()
    

    In above function we decorator the openerp.api.depends() function must be applied on the computed fields and dependencies are used to determine when to recompute the field, and recomputation is jenerate the database consistency.

    Note-The search method is invoked when processing domains before doing an actual search on the model. It must return a domain equivalent to the condition: field operator value.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: