• OpenERP 疑问之一


    def _get_send_amount(self,cr,uid,ids,name,args,context=None):
            res={}
            MRP={}
            lines = self.browse(cr,uid,ids)
            #odd code:here the code will execute towice,first time execute by line id asc
            #but second time it will execute by line id desc
            #so,I have to sort it before the loop.
            lines.sort(key=lambda x:x.id)
            for line in lines:
    	    result=self._get_send_data(cr,uid,line.id,name,args,context=context)
    	    if result["amount"] > line.amount:
    		if not MRP.has_key(line.product_id.id):
    		    MRP[line.product_id.id]=result["amount"]-line.amount
    		    res[line.id]=line.amount
    		elif MRP[line.product_id.id]-line.amount>0:
    		    res[line.id]=line.amount
    		    MRP[line.product_id.id] -=line.amount
    		else:
    		    res[line.id]=MRP[line.product_id.id]
    		    MRP[line.product_id.id]=0
    	    else:
    		res[line.id]=result["amount"]
    	    
    	for line2 in lines:
    	    #产品是否是组合产品
    	    mrp = self.pool.get('mrp.bom').search(cr,uid,[('product_id','=',line2.product_id.id),('bom_id','=',False)],context=context)
    	    if len(mrp)>0:
    		min_count = 0
    		bom = self.pool.get('mrp.bom').browse(cr,uid,mrp[0],context=context)   
    		res_count=[]
    		#res_orders=[]
    		i=1
    		for bom_line in bom.bom_lines:
    		    res_count.append(int(res[line2.id+i] / bom_line.product_qty))
    		    i+=1
    		if len(res_count)>0: 
    		    amount =min(res_count)
    		else:
    		    amount =0
    		res[line2.id]=amount	
            return res
    

    我在迭代循环中发现,自定义方法_get_send_amount会执行两次,而且第一次执行的顺序是正序,第二次执行的顺序是倒序。

    不知到是为什么。。

  • 相关阅读:
    MYSQL索引
    MYSQL 外键 on语句 多表查询
    MYSQL用户管理
    MYSQL数据类型 表基本操作 表记录增删改 单表查询
    JQuery 引用方式
    JQuery 元素操作 each循环
    Android EditText方框验证码 短信验证码攻略
    android MVP模式介绍与实战
    一些不错的Android开源音视频播放器
    Android可伸缩布局-FlexboxLayout(支持RecyclerView集成)
  • 原文地址:https://www.cnblogs.com/kfx2007/p/3741214.html
Copyright © 2020-2023  润新知