2016-06-22 5 views
0

以下は、私のロスタモジュールの作成関数です。問題は、更新クエリのみが機能していないことです。クエリがpgadminで単独で実行されていてもうまく動作していますが、ここではそうではありません。選択クエリと挿入クエリの両方が正常に動作しています。Openerp関数を作成するdosn'tクエリを実行する

(私は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

ここで「機能しない」とはどういう意味ですか?連結されたクエリが解決するものと、どのデータを処理する必要があるかを示すことができますか? – halfer

+0

3日間放棄されたように見えるので、今すぐ投票を断念してください。 – halfer

答えて

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)) 
関連する問題