تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
501 أدوات العرض

I have this error with a rpc call to a controller, im editing the kiosk app but when i call the endpoint /manual_selection i have error: 


ODOO 18


TypeError: HrAttendanceExtended.manual_selection() missing 3 required positional arguments: 'token', 'employee_id', and 'pin_code'


This is my component:

import { rpc } from "@web/core/network/rpc";

setup() {

        this.rpc = rpc

        this.barcode = useService("barcode");

        this.notification = useService("notification");

    }

async onManualSelection(employeeId, enteredPin) {


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

            token: this.props.token,

            employee_id: employeeId,

            pin_code: enteredPin

        });


        console.log(result)


        if (result?.attendance) {

            this.employeeData = result;

            this.switchDisplay('greet');

        } else if (enteredPin) {

            this.displayNotification(_t("Wrong Pin"));

        }

    }


This is my function in controller


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

    def manual_selection(self, token, employee_id, pin_code, 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 {}


How can i give the parameters to the function? and what i need to return?

الصورة الرمزية
إهمال

console.log(this.props.token, employeeId, enteredPin);
and see if these actually are set

أفضل إجابة

Hi,


The issue was that JSON RPC passes parameters as keyword arguments, but your controller was expecting positional arguments. Using **kwargs fixes this.


Js:

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

    token: this.props.token,

    employee_id: employeeId,

    pin_code: enteredPin,

    work_location: false

});


Controller:

@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)

    # rest of your existing code remains the same


Hope it helps

الصورة الرمزية
إهمال
أفضل إجابة

Hii,

The issue you're encountering is because the rpc call you're making sends the parameters as a dictionary inside params, but your controller method is expecting positional arguments, not a dictionary.

Update your controller method to extract parameters from request.params

@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 {}

I hope it is usefull

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 25
916
4
أغسطس 25
1176
0
يونيو 25
559
1
يونيو 25
1703
1
يونيو 25
875