2017-05-30 90 views
0

我與序列Odoo 9工作,我需要一些幫助,默認功能:與序列工作odoo 9

我的實際模型從現場讀出的值,然後在序列表中檢查是否存在序列與該代碼(與標籤相同),如果不存在,我的自定義創建函數將創建序列併爲序列字段分配一個值。

現在我的問題是,當我斷開一個記錄,我想讓空閒的序列再次點。

作爲參考生病後我的創建功能:

@api.model 
def create(self,vals): 
    prefix   = "v" 
    code   = str(vals['label']) 
    name   = prefix+"_"+code 
    implementation = "no_gap" 
    dict   = {"prefix":prefix, 
         "code":code, 
         "name":name, 
         "active":True, 
         "implementation":implementation 
         } 

    if vals.get('sequence','New') == 'New': 
     #First if will return True if can find a value for the field sequence in the current entry, if not, will return 'New' 
     if self.env['ir.sequence'].search([('code','=',code)]).code == code: 
      vals['sequence'] = self.env['ir.sequence'].next_by_code(code) 
      result = super(t_self_sequence,self).create(vals) 
      return result 
     else: 
      new_seq = self.env['ir.sequence'].create(dict) 
      vals['sequence'] = self.env['ir.sequence'].next_by_code(code) 
      result = super(t_self_sequence,self).create(vals) 
      return result 

我試圖更新number_next valuein我的unlink()函數,但不能弄清楚如何做是正確的,因爲如果我只是用在序列模型寫我會更新的價值,但如果作爲例子,我有3個記錄:

版/標籤

V1你好

V2你好

V3你好

然後,我刪除了V2您好,寫成number_next 2我的順序,下面的記錄將有V2您好但number_next將更新3,所以如果我添加另一條記錄生病有另一個V3你好,這將使我的數據不一致

回答

0

爲什麼你想重新打開序列中的點如果記錄被刪除?我能想到的唯一解決方案是遍歷整個系列,並使用第一個找不到的解決方案。像這樣?

# I'm not sure of your exact fields, so you'll want to adapt some of this 
object = self.env['model.name'] 
i = 1 
stop = False 
while stop != True: 
    label = 'V%d Hello' % i 
    record = object.search([('name','=',label)]) 
    if record: 
     i += 1 
    else: 
     stop = True 

new_sequence = label 

免責聲明:我不喜歡這個解決方案