Skip to Content
Menu
This question has been flagged
2 Replies
211 Views

Hello. I'm trying to understand "what happens where". As I'm unable to modify/ use the default website from the "Recruitment Application" of odoo I'm trying RPC calls.


So when the (default) form is submitted a email is sent, and from the models a "candiate-model" is created. 

Looking at the hr.applicant ("where the form is going to") the is the candiate id mandatory (relation) but I cant see where the candidate (relation) is created.


Using RPC to hr.applicant using the fields the htpp form is also sending I can't create the entity as a relation to "candidate" is missing. Passing an exisiting id as candidate id I also get an error:

message": "The operation cannot be completed: Error, a partner cannot follow twice the same object.",

            "arguments": [

                "The operation cannot be completed: Error, a partner cannot follow twice the same object."

            ],

Avatar
Discard
Author

Thanks. I understand. But when I pass an exisiting candidate_id I receive:

UniqueViolation: duplicate key value violates unique constraint \"mail_followers_mail_followers_res_partner_res_model_id_uniq\"\nDETAIL:  Key (res_model, res_id, partner_id)=(hr.applicant, 97, 3) already exists.

Provide a full example of what you are doing

Author Best Answer

Sure

I do this RPC call to  http://odooserver:8069/jsonrpc

{

    "jsonrpc": "2.0",

    "method": "call",

    "params": {

        "service": "object",

        "method": "execute",

        "args": [

            "SLTEST",

            "2",

            "123456789",

            "hr.applicant",

            "create",

            {

                "partner_name": "Harry",

                "email_from": "harry@success.com",

                "partner_phone": "1234567",

                "job_id": 2,

                "department_id": 2,

                "linkedin_profile": "abc",

                "candidate_id": 29

            }

        ]

    },

    "id": 33

}


And I receive


{
    "jsonrpc": "2.0",
    "id": 33,
    "error": {
        "code": 200,
        "message": "Odoo Server Error",
        "data": {
            "name": "odoo.exceptions.ValidationError",
            "debug": "Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 137, in retrying\n    result = func()\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 517, in call_kw\n    result = getattr(recs, name)(*args, **kwargs)\n  File \"<decorator-gen-315>\", line 2, in create\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 479, in _model_create_multi\n    return create(self, [arg])\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base_automation/models/base_automation.py\", line 774, in create\n    records = create.origin(self.with_env(automations.env), vals_list, **kw)\n  File \"<decorator-gen-289>\", line 2, in create\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 480, in _model_create_multi\n    return create(self, arg)\n  File \"/usr/lib/python3/dist-packages/odoo/addons/hr_recruitment/models/hr_applicant.py\", line 323, in create\n    applicants = super().create(vals_list)\n  File \"<decorator-gen-139>\", line 2, in create\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 480, in _model_create_multi\n    return create(self, arg)\n  File \"/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py\", line 271, in create\n    self.env['mail.followers']._insert_followers(\n  File \"/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_followers.py\", line 417, in _insert_followers\n    sudo_self.create([\n  File \"<decorator-gen-146>\", line 2, in create\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 480, in _model_create_multi\n    return create(self, arg)\n  File \"/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_followers.py\", line 54, in create\n    res = super(Followers, self).create(vals_list)\n  File \"<decorator-gen-31>\", line 2, in create\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 480, in _model_create_multi\n    return create(self, arg)\n  File \"/usr/lib/python3/dist-packages/odoo/models.py\", line 4975, in create\n    records = self._create(data_list)\n  File \"/usr/lib/python3/dist-packages/odoo/models.py\", line 5159, in _create\n    cr.execute(SQL(\n  File \"/usr/lib/python3/dist-packages/odoo/sql_db.py\", line 354, in execute\n    res = self._obj.execute(query, params)\npsycopg2.errors.UniqueViolation: duplicate key value violates unique constraint \"mail_followers_mail_followers_res_partner_res_model_id_uniq\"\nDETAIL:  Key (res_model, res_id, partner_id)=(hr.applicant, 98, 3) already exists.\n\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 2386, in __call__\n    response = request._serve_nodb()\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 1858, in _serve_nodb\n    response = self.dispatcher.dispatch(rule.endpoint, args)\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 2178, in dispatch\n    result = endpoint(**self.request.params)\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 727, in route_wrapper\n    result = endpoint(self, *args, **params_ok)\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base/controllers/rpc.py\", line 178, in jsonrpc\n    return dispatch_rpc(service, method, args)\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 398, in dispatch_rpc\n    return dispatch(method, params)\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 37, in dispatch\n    res = execute(db, uid, *params[3:])\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 68, in execute\n    res = execute_cr(cr, uid, obj, method, *args, **kw)\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 52, in execute_cr\n    result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env)\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 156, in retrying\n    raise _as_validation_error(env, exc) from exc\nodoo.exceptions.ValidationError: The operation cannot be completed: Error, a partner cannot follow twice the same object.\n",
            "message": "The operation cannot be completed: Error, a partner cannot follow twice the same object.",
            "arguments": [
                "The operation cannot be completed: Error, a partner cannot follow twice the same object."
            ],
            "context": {}
        }
    }
}



Avatar
Discard
Best Answer

candidate_id on hr.applicant is defined here:

https://github.com/odoo/odoo/blob/18.0/addons/hr_recruitment/models/hr_applicant.py#L39


Now, when taking a look at the website form for applying to a job, https://github.com/odoo/odoo/blob/18.0/addons/website_hr_recruitment/views/website_hr_recruitment_templates.xml#L206, you can see that Odoo uses a generic form action (/website/form/) to post data to; Thus, the route for it is defined here: https://github.com/odoo/odoo/blob/18.0/addons/website/controllers/form.py.

Now, investigating it further you'll come across a call to _handle_website_form() (line 65 as of today) which does some extract_data() shenanigans.

This extract_data() is then extended in the website specific module for HR Recruitment (https://github.com/odoo/odoo/blob/18.0/addons/website_hr_recruitment/controllers/main.py#L349) in which you then can find the actual creation of such a candidate, based on the form data:

if partner_phone and partner_email:
candidate = request.env['hr.candidate'].sudo().search([
    ('email_from', '=', partner_email),
        ('partner_phone', '=', partner_phone),
    ], limit=1)
if not candidate:
candidate = request.env['hr.candidate'].sudo().create({
    'partner_name': partner_name,
        'email_from': partner_email,
        'partner_phone': partner_phone,
        'company_id': company_id,
})

and finally, a little further down the line, the candidate_id is passed on for using it in the actual hr.applicant record:

if candidate:
data['record']['candidate_id'] = candidate.id



Avatar
Discard