0
我有這段代碼獲取銷售團隊的id,如果此人在一箇中,否則返回None。導致AttributeError的Lambda
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
我在做什麼錯?
鑑於xx_section_id是如何命名它會出現,它的意思是一個id。但是,如果_get_sales_team返回None ...?難道這種情況應該被標記嗎? –
@BillBell返回None類型用於標記缺少值,返回時保持爲空None – RandomPerson