Skip to Content
Menu
This question has been flagged
2 Replies
4219 Views

I have been experiencing different issues with the number of arguments passed to a computed field and I´m confused on how this works, was hoping if someone could give me some guidance on how to troubleshoot the following error and explain when to use the different labels of @api.depends and @api.multi

Error:

result = self._fnct(obj, cr, uid, ids, name, self._arg, context)

TypeError: get_user() takes exactly 1 argument (7 given)

Code:

'make_visible':fields.function(get_user, string="User Visible", type="boolean"),
@api.depends('make_visible')  
def get_user(self, ): 
    user_crnt = self._uid
    res_user = self.env['res.users'].search([('id', '=', self._uid)]) 
    if res_user.has_group('hr_employee.GM'):
        self.make_visible = False 
    else: 
        self.make_visible = True
Avatar
Discard
Author Best Answer

Hello again.

     I still cant get it to work, I have tried differen ways but dont know how to distinguish between old api and new api.

This code gets me:

ValueError: dictionary update sequence element #0 has length 1; 2 is required

The code as simple as I could:

'make_invisible':fields.function(get_user, string="User Visible", readonly=0)
@api.multi  
def get_user(self ): 
    _logger.debug("This is GET_USER method ") 
    self.make_invisible=self.env['res.users'].has_group('hr_employee.GM')

The objective of this method is to define is logged user belongs to a certain group, because then I will use make_invisible flag to hide some fields to a certain group. NOTE: making the fields visible to certains groups is no option because it is a small group the one who should not see these fields.

Avatar
Discard
Best Answer

@api.multi :- Self will be the current RecordSet without iteration

@api.depends:- This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is altered by ORM or changed in the form.

reference

You are using old API for defining the computed field. seems to be wrong. look here

from openerp import api
total = fields.Float(compute='_compute_total')

@api.depends('value', 'tax')
def _compute_total(self):
    for record in self:
        record.total = record.value + record.value * record.tax

This is the new guideline to make a computed field.

reference

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 18
4571
2
Jul 24
413
1
Jan 24
422
2
Apr 24
1951
1
Aug 23
12549