简体   繁体   中英

How to using fields.function?

Can you help me understand the functions and working of Field.function through this code?

'progress': fields.function(_hours_get, string='Working Time Progress (%)', multi='hours', group_operator="avg", help="If the task has a progress of 99.99% you should close the task if it's finished or reevaluate the time",
                store = {
                    'project.task': (lambda self, cr, uid, ids, c={}: ids, ['work_ids', 'remaining_hours', 'planned_hours', 'state', 'stage_id'], 10),
                    'project.task.work': (_get_task, ['hours'], 10),
                }),

I needed to understand them. Hope the response. Thanks & Best Regards

I ll give you a simple exemple to understand Field.function.

Exemple:

    def _check_bool(self, cr, uid, ids, field_name, arg, context):
       res={}
       for req in self.browse(cr, uid, ids, context=context):
          if req.bool:
                res[req.id] = True
          else:
                res[req.id] = False
       return res

    _columns = {
       'bool' : fields.boolean(),
       'check_bool': fields.function(_check_bool, type="boolean", obj="generic.request", method=True),
    }

The _check_bool function checks if the field 'bool' is True of False and makes the same for field 'check_bool' the code is easy to undersant, if you have a question im here to help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM