odoo返写数据

时间:2021-10-02 00:55:51
#确认按钮  反写回合同页面,当前页面反写数据:

def action_split_order_ht(self,cr,uid,ids,context=None):
assert len(ids)==1
sigining_contract_obj=self.browse(cr,uid,ids,context)
sigining_contract_obj.state='confirm'
name=sigining_contract_obj.contract_origin
sql="select sum(total_pay) as paytotal,sum(total_jies) as jiestotal from settle_account where contract_origin='%s' GROUP BY contract_origin "%(str(name))
cr.execute(sql)
dict1=cr.dictfetchall()[0]
sigining_contract_obj.accumulated_amount= dict1['jiestotal']
sigining_contract_obj.accumulated_pay= dict1['paytotal'] 在其他页面反写数据,可用sql语句
#确认按钮
def action_split_order_js(self,cr,uid,ids,context=None):
assert len(ids)==1
settle_account_obj=self.browse(cr,uid,ids,context)
settle_account_obj.state='confirm'
name=settle_account_obj.contract_origin
print name 汇总合同号相同的数据,相当于每次做累加
sql="select sum(total_pay) as paytotal,sum(total_jies) as jiestotal from settle_account where contract_origin='%s' GROUP BY contract_origin "%(str(name))
cr.execute(sql)
dict1=cr.dictfetchall()[0]
反写数据
if dict1:
PT=dict1['paytotal']
JT=dict1['jiestotal']
sql2=" UPDATE sigining_contract SET accumulated_amount='%d',accumulated_pay='%d' where contract_origin='%s'"%(JT,PT,str(name))
cr.execute(sql2)
else: return True 这里调用其他模块所用方法
sigining_obj=self.pool.get('sigining.contract')
sigining_obj_obj=sigining_obj.brows(cr,uid,[str('contract_origin'),'=','id'],context)
sigining_obj.create(cr,uid,{'accumulated_amount':dict1['jiestotal'],'accumulated_pay':dict1['paytotal']},context=None)
sigining_obj.accumulated_amount= dict1['jiestotal']