使用stock move openerp7 odoo 8迁移Stock_quants

时间:2016-06-02 08:11:56

标签: python openerp database-migration odoo-8 talend

如何用stock_move将stock.mant和stock_quants_move_rel填充到odoo8? 我试图重新处理库存移动状态完成填充库存量但我在stock_moves中有很多数据

1 个答案:

答案 0 :(得分:0)

这是我的代码

    from openerp.osv import osv,fields
    from openerp import SUPERUSER_ID

    from openerp import netsvc


    class generation(osv.osv):
    _name ="generation.models"
    _columns={
              "visible":fields.boolean("Visible")

              }
    _defaults={
               'visible':False
               }
    def get_stockmovedone(self,cr ,uid ,ids, Context=None):
        cr.execute("SELECT id from stock_move where state='done' order by 
    date ASC") 
        liste_move_done =[]
        res = cr.fetchall()
        for i in range(len(res)):
            liste_move_done.append(res[i][0])
        return liste_move_done

    def get_id_wkf_workitem(self,cr ,uid,ids ,Context=None): 
        cr.execute("select distinct(wkf_workitem.id)  from wkf_workitem \
        where inst_id in (select distinct(wkf_instance.id) from stock_move\
        inner join wkf_instance\
        on stock_move.id=wkf_instance.res_id \
        where stock_move.state='done'\
        and wkf_instance.res_type='stock.move')")
        res=cr.fetchall()

        liste_wkf_work=[]
        for i in range(len(res)):
            liste_wkf_work.append(res[i][0])


        return liste_wkf_work

    def get_id_wkf_inst(self,cr ,uid,ids ,Context=None): 
        cr.execute("select distinct(wkf_instance.id) from stock_move \
        inner join wkf_instance on stock_move.id=wkf_instance.res_id \
        where stock_move.state='done' and wkf_instance.res_type='stock.move'")
        res=cr.fetchall()
        liste_wkf_inst=[]

        for i in range(len(res)):

            liste_wkf_inst.append(res[i][0])

        return liste_wkf_inst

    def update_leisyah(self,cr,uid,ids,Context=None):
        liste1= self.get_id_wkf_inst(cr, uid, ids, Context)
        liste2= self.get_id_wkf_workitem(cr, uid, ids, Context)
        liste_stockmove =self.get_stockmovedone(cr,uid,ids,Context)
        for t in liste_stockmove:
            cr.execute("UPDATE stock_move SET state ='assigned' where 
    id={}".format(t))

        for i in liste1:
            cr.execute("UPDATE  wkf_instance SET state='active' \
            where id={} ".format(i))

        for j in liste2:
            cr.execute("UPDATE wkf_workitem SET act_id=62 \
            where id={} ".format(j))   

        for r in liste_stockmove:
                netsvc.LocalService("workflow").trg_validate(SUPERUSER_ID, 
    'stock.move', r, 'action_done', cr)

        gener_obj = self.pool.get('generation.models')
        gener_obj.write(cr,uid, [ids[0]] , {'visible':True}, context=Context)