2012-07-20 40 views
1

OI從mo.queue選擇同一領域,我希望它保存到procurement.order保存到另一臺

我的代碼如下:

def action_ship_create(self, cr, uid, ids, id_queue, context=None): 
    queue_obj = self.pool.get('mo.queue'). browse (cr, uid, id_queue, context=context) 
    mo_name = queue_obj.name 
    query_param = (mo_name) 
    cr.execute("select origin,create_date,product_uos_qty,product_qty,name,city from mo_queue",(query_param,)) 
    ads = cr.fetchone() 
    name = ads and ads [0] or None 
    print "======================" 
    print name 
    print "======================" 

    val = { 'origin': name, 
      } 
    print "======================" 
    print val 
    print "======================" 

    return {'value': val } 


    proc_id = self.pool.get('procurement.order').create(cr, uid, { 
     'origin':origin, 
    }) 
    proc_ids.append(proc_id) 

打印的結果:

print name = SO013 

print val = {'origin': u'SO013'} 

但數據未插入到procurement.order表中。

回答

1

你的代碼我看起來像這樣return語句不執行任何事情在返回之前放置cdeo並且你的代碼需要很多調優,就像不使用SQL注入它不是個好主意。

def action_ship_create(self, cr, uid, ids, id_queue, context=None): 
     queue_obj = self.pool.get('mo.queue'). browse (cr, uid, id_queue, context=context) 
     queue_model = self.poo.get(queue_obj.name) 
     procurement_pool = self.pool.get('procurement.order') 
     qsids = queue_model.search(cr, uid,) 
     for record in queue_model.browse(cr, uid, qsids): 
      if record.origin: 
       #this will crate a new record the table procurement.order so 
       #field values may be not enough so you can update logic 
       #and If you want to update record value you need a proc ids and you can do it. 
       procurement_pool.create(cr, uid, {'origin':record.origin}) 
     return {'value': {'origin': record.origin}} 

希望這會幫助你讓我知道我失蹤了。

謝謝

+0

這只是一個領域**起源**,如果多.. ..? (來源,名稱,date_planned等)? – Dja 2012-07-20 05:10:11

+0

@Dja:簡單的循環,你可以創建一個字典,然後record.field_name你有vlaue。你可以使用它們。 – 2012-07-20 05:40:26

相關問題