Openerp创建函数不执行查询

问题描述 投票:0回答:1

以下是我的名册模块的创建函数。问题是只有更新查询无法正常工作。当它在pgadmin中单独运行时,查询工作正常,但在这里却不能。选择查询和插入查询都可以正常工作。

((我知道使用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)
postgresql python-2.7 openerp-7
1个回答
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))
© www.soinside.com 2019 - 2024. All rights reserved.