Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to functional field is replaced by computed field Odoo-8?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.50k
    Comment on it

    In Odoo-8 first, we create the own module and then create fields and make these fields a functional fields. Ones we create functional fields after this the functional field is replaced by computed field.

    Like, first create a computed field and after creating a compute field, set its attribute compute to the name of a method and The computation method should simply set the value of the field to compute on every record in self.

    Use this code in .py file show in given below:


     name = fields.Char(compute='_get_data', string='Name')
        value = fields.Char(string='Value')
        def _get_data(self):
            cursor = self._cr
            user = self._uid    
            today =
            start_date = str(today.replace(day=1).strftime('%m/%d/%Y'))
            next_month = today.replace(day=28) + datetime.timedelta(days=4)
            end_date = str(next_month - datetime.timedelta(
            sale_obj = self.pool.get('sale.order')
            order_ids =, user, [('date_order','>=',start_date),('date_order','<=',end_date),('partner_id','=',,('state','!=','draft')])
            total = 0.0
            for sale in sale_obj.browse(cursor, user, order_ids):
                total += sale.amount_total
            self.mtd_sales = total

    @api.depends('value') means that the decorator specifies the dependency on the 'value' field.
    and it is used by the ORM to trigger recomputation of the field.

    _get_data is the function name.

    Self refres to the same object and class of the module.

    @api is the API of the odoo-8 and we can use this API any where in server.

 0 Comment(s)

Sign In

Sign up using

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: