コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
269 ビュー

I have this error in my controller, 


2025-07-08 08:22:24     raise TypeError(f"{fname} returns an invalid value: {result}")

2025-07-08 08:22:24 TypeError: <function> returns an invalid value: {}


My controller is:

@http.route('/hr_attendance/manual_selection', type="json", auth="public", csrf=False)

    def manual_selection(self, **kwargs):

        token = kwargs.get('token')

        employee_id = kwargs.get('employee_id')

        pin_code = kwargs.get('pin_code')

        work_location = kwargs.get('work_location', False)


        print("--------------------------------")

        print("manual_selection", token, employee_id, pin_code)


        company = self._get_company(token)

        if company:

            employee = request.env['hr.employee'].sudo().browse(employee_id)

            if employee.company_id == company and (

                (not company.attendance_kiosk_use_pin) or (employee.pin == pin_code)

            ):

                employee.sudo().with_context(work_location=work_location)._attendance_action_change(

                    self._get_geoip_response('kiosk')

                )

                employee_data = self._get_employee_info_response(employee)

                employee_data['work_location'] = work_location

                return employee_data

        return {}


and my call is

const result = await this.rpc("/hr_attendance/manual_selection", {

            token: this.props.token,

            employee_id: employeeId,

            pin_code: enteredPin,

            work_location: false

        });


why i need to return to solve this error?

アバター
破棄
最善の回答

Get ready to twist, turn, and flip through chaotic challenges in [L=Wacky Flip]https://wacky-flip.com[/L]  – the ultimate test of timing and fun!

アバター
破棄
最善の回答

Hii,

Solution: Always return a valid structure


Modify the end of your controller function to explicitly return a valid JSON response, like this:

return {'error': 'Invalid employee or company or PIN'}

So, update the last part of your controller like this

if company: employee = request.env['hr.employee'].sudo().browse(employee_id) if employee and employee.exists() and employee.company_id == company and ( (not company.attendance_kiosk_use_pin) or (employee.pin == pin_code) ): employee.sudo().with_context(work_location=work_location)._attendance_action_change( self._get_geoip_response('kiosk') ) employee_data = self._get_employee_info_response(employee) employee_data['work_location'] = work_location return employee_data # Return an explicit response return {'error': 'Invalid request data or unauthorized'}

Example Frontend (OWL/JS) Error Handling

const result = await this.rpc("/hr_attendance/manual_selection", { token: this.props.token, employee_id: employeeId, pin_code: enteredPin, work_location: false }); if (result.error) { console.error("Error:", result.error); // Show error message to user in UI } else { console.log("Attendance marked successfully:", result); // Proceed with success handling }

i hope it is use full

アバター
破棄