消息错误:
TypeError:old_api()至少需要3个参数(给定1个)
代码py:
@api.model
def domain_users(self):
if self.env.user.login=="bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels fields.One2many('gmat.journaleline','rapJor_ids',string='Materiel',domain=domain_users)
类py:
class Journaleline(models.Model):
_name = 'gmat.journaleline'
_description = 'Detail materiel'
rapJor_ids = fields.Many2one('gmat.rapporjournal',string='num')
exp_P = fields.Float(string='Panne(H)',default=0)
答案 0 :(得分:0)
所有邮件错误:
Traceback (most recent call last):
File "/opt/odoo/openerp/http.py", line 544, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/openerp/http.py", line 581, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/openerp/http.py", line 317, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/openerp/http.py", line 314, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/openerp/http.py", line 810, in __call__
return self.method(*args, **kw)
File "/opt/odoo/openerp/http.py", line 410, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/openerp/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/openerp/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3148, in read
result = BaseModel.read(records, fields, load=load)
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3183, in read
self._read_from_database(stored, inherited)
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3370, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/opt/odoo/openerp/osv/fields.py", line 773, in get
domain = self._domain(obj) if callable(self._domain) else self._domain
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
TypeError:old_api()至少需要3个参数(给定1个)
答案 1 :(得分:0)
试试这个:
# remove the decorator
def domain_users(self):
domain = False
if self.env.user.login=="bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain=lambda self: self.domain_users())
或更少打字
# no need to define method
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain = lambda self: self.env.user.login == "bendjedou.o" and [('exp_P','>',0)] or [])
<强>编辑:强> 好吧,出于某种原因,我认为该方法的签名 必须在旧的api尝试这个:
# or this
# def domain_users(self, cr, uid, ids, context=None):
def domain_users(self, cr, uid, context=None):
domain = False
user = self.pool.get('res.users').browse(cr, uid, uid, context).
if user.login == "bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain=domain_users)
可能因为您的模型是使用osv.Model
而不是model.Model