def action_partner_account_state(self,cr,uid,context=None):
cr.execute(""" select id from res_partner where is_company='t' and customer='t' and active='t' order by id
""")
account_obj=self.pool.get('partner.account.state')
account_obj_line=self.pool.get('partner.account.state')
if cr.rowcount>0:
dict1=cr.fetchall()
for line in dict1:
vals={}
id=line[0]
vals['partner_id']=id
# 时间段会自动减少30天
vals['docdate_from']=(datetime.now()-timedelta(days=30))
vals['docdate_to']=datetime.now()
partner_id=vals['partner_id']
docdate_from=vals['docdate_from']
docdate_to= vals['docdate_to']
record=[]
seq=1
# # 本月的所有订单数量
if docdate_from and docdate_to:
if docdate_from<docdate_to:
语句sql
cr.execute(sql)
dict=cr.dictfetchall()
if dict:
# 这里只是带数据到订单里面去,所以append要加append((0,0,)
for line in dict:
record.append((0,0,{'sequence':seq, 'picking_id':line['id'],'product_id':line['product_id'],'qty':line['product_qty'],
'price':line['price'],'total':line['total'],'date_planned':line['date_done']
}))
seq+=1
print record
vals['order_line']=record
# 上月结存金额
语句sql
cr.execute(sql)
dict1=cr.dictfetchall()
if dict1:
vals['last_month_cj']=dict1[0]['syjcje']
else:
vals['last_month_cj']=0.0
# 收承兑金额
sql="select sum(type*pay_total) je from partner_for_payment where partner_id=%d and pay_date>='%s' and pay_date<='%s' and costtype=2 group by partner_id"%(partner_id,docdate_from,docdate_to)
cr.execute(sql)
dict2=cr.dictfetchall()
if dict2:
vals['scdje']=dict2[0]['je']
else:
vals['scdje']=0.0
#到款金额
sql="select sum(type*pay_total) je from partner_for_payment where partner_id=%d and pay_date>='%s' and pay_date<='%s' and costtype=1 group by partner_id"%(partner_id,docdate_from,docdate_to)
cr.execute(sql)
dict3=cr.dictfetchall()
if dict3:
vals['amount_to_money']=dict3[0]['je']
else:
vals['amount_to_money']=0.0
new_id=account_obj.create(cr,uid,vals,context=context)
return True