保存到另一个表中

时间:2012-07-20 02:27:30

标签: openerp

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 个答案:

答案 0 :(得分:1)

你的代码我看起来像这样,在返回语句之后没有执行任何事情,在返回之前把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}}  

希望这会帮助你让我知道我错过了。

谢谢