A method decorated with api.one decorator always returns a list

When you are using api.one decorator in Odoo, take into consideration that it always returns a list. That means even if you return from the method single value, it will add it to a list.

For example, If we add a method that adds five additional hours to the work_hours field’s value, the return value from the method will be added to a list as [total].

from openerp import models, fields, api

class PartnerContact(models.Model):
    _name = 'partner.contact'

    work_hours = fields.Float(string='Work Hours', index=True)
    def compute_work_hours(self)
        total = self.work_hours + 5
        return total

>> print self.compute_work_hours()
>> [10]

Leave a Reply

Your email address will not be published. Required fields are marked *