2016-03-04 113 views
-2

我應該做的這個功能是保存表單時保存在一個字段('niu')中的一個序列。此表單位於sale.order.line模型中。
enter image description hereAttributeError:'NoneType'對象沒有屬性'id'

niu = fields.Char(string="NIU", readonly=True) 

    @api.model 
    def create(self, vals): 
     for rec in self: 
      if rec.product_id.product_tmpl_id.type == 'product' and not rec.niu: 
       if vals.get('niu') == ' ': 
        vals[u'niu'] = self.env['ir.sequence'].next_by_code('sale.order.line') 
       result = super(SaleOrder, self).create(vals) 
       return result 

但是,當我點擊保存按鈕,Odoo顯示我下面的錯誤: AttributeError的: 'NoneType' 對象有沒有屬性 'ID'

這究竟是爲什麼?我能做什麼? 任何幫助表示讚賞。謝謝

+0

的可能的複製[Python的:屬性錯誤 - 「NoneType」對象有沒有屬性「東西」(http://stackoverflow.com/questions/8949252/python-attribute-error-nonetype-object-has-no-attribute-something) – tripleee

+0

對我來說似乎不是重複的:我們不知道其他帖子指的是哪個問題 至 –

回答

2

你不需要作爲rec自我循環,因爲你進入創建。 您無權通過self訪問對象字段,該字段此刻爲空。您只需要使用vals。 您需要更改的方法裝飾:

@api.model 
@api.returns('self', lambda value:value.id) 
def create(self, vals): 

我真的覺得你應該Odoo basics有讀,這是不是你有,你可以迴避閱讀他們深深... 另外,第一個問題,有看看account_invoice.py考慮模塊,表現出豐富的V8 API的