2016-12-06 6 views
0

人が1人であれば、販売チームのIDを取得します。それ以外の人はNoneを返します。AttributeErrorを引き起こすラムダ

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

。しかし、_get_sales_teamがNoneを返すと...?この状態に何とかフラグを立てるべきでしょうか? –

+0

@BillBell戻り値なしの型は、値がないことを示すために使用され、返されないときは空のままです。 – RandomPerson

答えて

0

len(ids)== 0の場合、スクリプトは「ids [0]」を返そうとします。

「IDS」の結果値に応じて、条件は次のようになります。xx_section_idは、IDを意味するものだと思われる命名方法を考える

または

if len(ids) > 0: 
+0

これは1つしか受け入れないため、 – RandomPerson

関連する問題