OpenERP:循环中的值之和

时间:2014-01-25 11:17:41

标签: python openerp

我是Openerp的学习者可能是基本问题 以下是我的代码:

def add_slab_info(self, cr, uid, ids, context={}):     
   sqty=2
 for qty in range(0,sqty):   
   area = (length) * (width)                                           
   Self.pool.get(object).create(cr, uid, {'product_id':value.product_id.id,
       'sno':no,'length':length,'width':width,'price':price,
       'area':area,
        })                
   self.pool.get('purchase.order.line').write(cr,uid,record_id,
        'product_qty':  sum(area),
        'product_field':product}) 

如果sqty = 2,则创建2行

L W A 
1 2 2
1 2 2
    4 Sum(A)

我想得到面积的总和。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

你可以试试这个。希望这会有所帮助

def add_slab_info(self, cr, uid, ids, context={}):     
sqty=2
for qty in range(0,sqty):   
    area = (length) * (width)                                           
   Self.pool.get(object).create(cr, uid, {'product_id':value.product_id.id,
   'sno':no,'length':length,'width':width,'price':price,
   'area':area,
    }) 
  Sum_area += area               
  self.pool.get('purchase.order.line').write(cr,uid,record_id,
    'product_qty':  Sum_area,
    'product_field':product})