2016-12-06 26 views
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 

我在做什麼錯?

+0

鑑於xx_section_id是如何命名它會出現,它的意思是一個id。但是,如果_get_sales_team返回None ...?難道這種情況應該被標記嗎? –

+0

@BillBell返回None類型用於標記缺少值,返回時保持爲空None – RandomPerson

回答

0

對於len(ids)== 0的情況,腳本嘗試'返回ids [0]'。

根據「IDS」的結果值,你的條件應該是:

if len(ids) > 0: 
+0

它只接受一個,因此條件檢查是否等於 – RandomPerson

相關問題