跳至内容
菜单
此问题已终结
1 回复
16910 查看

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

形象
丢弃
相关帖文 回复 查看 活动
0
9月 23
1485
2
2月 23
2714
0
7月 21
3332
3
7月 20
12414
0
4月 20
3921