我有这段代码,如果该人在一个人中,则会获取销售团队的ID,否则它将返回None。
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
xx_section_id = fields.Many2one('crm.case.section', string='Invoice template', required=True,
default=lambda self: self._get_sales_team())
@api.model
def _get_sales_team(self):
ids = self.env['crm.case.section'].search([('member_ids', 'in', self._uid)])
if len(ids) != 1:
# Has no sales team or more than one
return None
return ids[0]
出于某种原因,这适用于我的本地环境,但不适用于服务器。我尝试安装模块时发生错误。服务器给我以下错误:
AttributeError: 'NoneType' object has no attribute 'id'
在记录中它说明:
2016-12-06 19:39:06,662 2005 ERROR None openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/Users/glenn/Documents/Work/odoo80_vzwwebcrm_tst/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Users/glenn/Documents/Work/odoo80_vzwwebcrm_tst/openerp/http.py", line 1415, in _dispatch_nodb
func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
File "/Users/glenn/.virtualenvs/odoo8/lib/python2.7/site-packages/werkzeug/routing.py", line 1430, in match
raise NotFound()
NotFound: 404: Not Found
我做错了什么?
答案 0 :(得分:0)
对于案例len(ids)== 0,脚本会尝试返回ids [0]'。
根据' ID'的结果值,您的条件应为:
if ids:
或
if len(ids) > 0: