以下是我为名册模块创建的功能。问题是只有更新查询不起作用。当它在pgadmin中单独运行时,查询工作正常但在此处却没有。 Select和Insert查询都正常工作。
(我知道使用cr.execute不是一个很好的做法,但我对截止日期有点匆忙)。
def create(self, cr, uid, values, context=None):
#rec_id=values['id']
sub_day=values['roster_day']
ros_time=values['time_slot']
emp = values['employee']
dept = values['department_id']
sub_emp = values['sub_employee']
#sub_day = datetime.datetime.strptime(sub_day, '%Y-%m-%d')
cr.execute("""SELECT ra.id , ra.emp_id FROM roster_allocation ra, roster_days_allocation rda
WHERE rda.roster_allocation_connection=ra.id and
rda.allocation_start_day='%s' and
rda.roster_time_list=%d and
ra.emp_id=%d"""%(sub_day,ros_time,emp))
exers=cr.fetchone()[0]
cr.execute("""INSERT INTO roster_allocation (write_uid,emp_id,department_id) VALUES(%d,%d,%d)""" %(context['uid'], sub_emp, dept))
print "Employee for substitution record inserted successfully"
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
WHERE allocation_start_day = '%s' AND roster_time_list = %d AND roster_allocation_connection = %d""" %(sub_day, ros_time,exers))
print "Employee for substitution record updated successfully"
return super(roster_substitution, self).create(cr, uid, values, context=context)
答案 0 :(得分:0)
我已经编辑了UPDATE查询,即使它不是最佳实践,但它仍然有用。
cr.execute (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
val=cr.fetchone()
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = %d
WHERE allocation_start_day = '%s' AND roster_time_list = %d AND roster_allocation_connection = %d""" %(val,sub_day, ros_time,exers))