2016-04-29 8 views
0

私はautoincrement番号を得るためにaccount.invoiceの下にこのフィールドを追加しましたが、動作しません。整数欄を増やすOdoo

は私が私のエラーすべての

サンプルコード

class invoice(osv.osv): 
    _inherit = 'account.invoice' 

    def _get_increment(self, cr, uid, ids, fields, arg, context=None): 
     if context is None: context = {} 
     res = {} 
     if type == 'out_invoice': 
      ids = self.search(cr,uid,[('id','!=',False),('type','in',('out_invoice','out_refund'))]) 
      if ids: 
       last_id = ids and max(ids) 
       print 'last_id',last_id 
       for invoice in self.browse(cr, uid, last_id, context): 
        print 'invoice', invoice 
        if invoice.name1: 
         res[invoice.id] = invoice.name1 
        else : 
         res[invoice.id] = invoice.name1 + 1 
      return res 

    _columns={ 
      'name1':fields.function(_get_increment, type='integer', string='Name1'), 

    } 

答えて

0

ファーストを把握するために助けてください。型が設定されていないので、関数は決して値を返しません。 これは、if条件が決して引き起こされないことを意味します。

秒です。新しいOdoo APIを使用することをお勧めします。 関数フィールドはフィールドのcompute属性で置き換えられ、宣言は_columnsディクショナリではなくなります。

代わりに次をインポートする必要があります openerp.osvからのインポートの

新しいAPI

from openerp import fields, models, api 

コードは次のようになります。あなたがする必要がある

from openerp import fields, models, api 
class invoice(models.Model): 
    _inherit = 'account.invoice' 
    name1 = fields.Integer('Name1', compute='_get_increment') 

    @api.one 
    def _get_increment(self): 
     self.name1 = 1 + 1 #This value should be the value that you've calculated 

唯一のものメソッド_get_incrementは、self.name1に設定されています。 新しいAPIでselfはレコードです。だからself.idはあなたにレコードのIDなどを渡します。

+0

あなたの答えはありがたいですが、私が654を入力すると追加された最後のものに基づいてインクリメントする必要があります655 –

+0

そのため、_get_incrementメソッドを編集する必要があります。 これはソリューションの単なる例でした – JordyRitzen