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.54k
    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:

    Example:

     name = fields.Char(compute='_get_data', string='Name')
        value = fields.Char(string='Value')
        @api.one
        @api.depends('value')
        def _get_data(self):
            cursor = self._cr
            user = self._uid    
            today = datetime.datetime.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(days=next_month.day-1))
            sale_obj = self.pool.get('sale.order')
            order_ids = sale_obj.search(cursor, user, [('date_order','>=',start_date),('date_order','<=',end_date),('partner_id','=',self.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
                           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: