Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
17266 มุมมอง

Why am I getting the error:

"fault_code": "'hr.attendance' object has no attribute 'attendance_action_change'", "type": "server_exception"

I have this code in my controller, which works all the way up to the last line at which point it is having trouble calling the function in the hr.attendance module, but why? (It calls the authenticate function without problems)

    @http.httprequest
    def MyFunction(self, req, user_id, **kw):
        req.session.authenticate('db-name', 'username', 'password')
        hr = req.session.model("hr.attendance")        
        ids=[]      #creating my empty list of people to change attendance state
        ids.append(user_id)   #building my id list of people who will get their attendance state changed (only ever 1 person)
        print req.session._uid  #verifying I have something to submit as a uid
        cr = openerp.pooler.get_db('db-name').cursor()  #get a connection to the DB
        attendance_change_result = hr.attendance_action_change(cr, req.session._uid, ids)

EDIT: I think I should be inheriting the module I'm trying to use. So I tried that, but I still need to inherit web.http.Controller, so I'm guessing I need "_inherits". Here's my 2nd try:


import openerp
import openerp.addons.web.http as http
PUNCHCARD_TEMPLATE = """< !DOCTYPE html>
< html>
    < head>
[HTML omitted for brevity,  HTML also malformed so it will show in window]
        < /form>
    < /body>
< /html>
"""
class PunchcardController(http.Controller):
    _inherits={'hr.attendance':'hr_attendance_id','http.Controller':'Controller_id'}
    cp_path = '/my_punchcard'

    @http.httprequest
    def index(self, req, s_action=None, **kw):
        template = PUNCHCARD_TEMPLATE
        return template

    @http.httprequest
    def PunchIn(self, req, user_id, **kw):
        template = "< html>< head>< /head>< body>AND NOW USER # " + str(user_id) + " IS IN< /body>< /html>"

        req.session.authenticate('db-name', 'username', 'password')        

#        hr = req.session.model("hr.attendance")

        ids=[]                      #creating my empty list of people to change attendance state
        ids.append(user_id)         #building my id list of people who will get their attendance state changed (only ever 1 person)
        print req.session._uid      #verifying I have something to submit as a uid
        cr = openerp.pooler.get_db('db-name').cursor()  #get a connection to the DB
        attendance_change_result = super(PunchcardController, self).attendance_action_change(cr, req.session._uid, ids)

        if attendance_change_result:
            print "sign in/out should have changed" 
        return template

PunchcardController()        

When I didn't have http.Controller as an argument to the method then i got error 404 when I tried to load the 1st page. So it seems i need that in there, but then how should I also inherit hr.attendance?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Have you found an answer to your question? I'm looking for a similar answer for Openerp V7. Thank you

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ย. 23
1740
Controller not working แก้ไขแล้ว
2
ก.พ. 23
3020
0
ก.ค. 21
3667
How to get model object from Controller แก้ไขแล้ว
3
ก.ค. 20
12726
0
เม.ย. 20
4161