Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3220 Tampilan
I want to inherit the widget in the recruitment module under hr.job model and add one level record rule
restricting employees from publishing the job unless they're managers.

  • How can I go about this?
    Any assistance will be highly appreciated.





Avatar
Buang
Jawaban Terbai

Hello Jay, how you're doing... 

I am here to help you.. maybe I will just paste here the working code and you will analyze it yourself after then.


The goal is to give the field right "groups" attribute. Then it will be only seen for this group. So for manager there is "group_hr_recruitment_manager" which comes from hr.recruitment module. So the code will be something like this.

<record id="view_hr_job_form_website_published_button_limited" model="ir.ui.view">
<field name="name">hr.job.form.inherit.published.button_limited</field>
<field name="model">hr.job</field>
<field name="inherit_id" ref="website_hr_recruitment.view_hr_job_form_website_published_button"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='website_published']" position="attributes">
<attribute name="groups">hr_recruitment.group_hr_recruitment_manager</attribute>
</xpath>
<xpath expr="//field[@name='is_published']" position="attributes">
<attribute name="groups">hr_recruitment.group_hr_recruitment_manager</attribute>
</xpath>
</field>
</record>

Explanation: 

1. inheriting the right view with the button included 

website_hr_recruitment.view_hr_job_form_website_published_button

2. using xpath for selection + position="attributes" to add additional attribute called "groups"

<xpath expr="//field[@name='website_published']" position="attributes">

3. putting the content of the attribute
<attribute name="groups">hr_recruitment.group_hr_recruitment_manager</attribute>

4. NOTICE: I have put this attribute to 2 fields as maybe it's wiser to hide both of these fields in the form
look at the screenshot -> https://ibb.co/kBjrWGC  

5. Now you can switch the Manager/Officer group for Recruitment module and only Managers will be able to see and use them.
look at the screenshot -> https://ibb.co/d0FnM0g

Hope this will help you a lot.
Please remember, to vote +1 👍 to my answer for the effort, and mark as Best Answer if it worked for you 😎


Avatar
Buang
Penulis

Thanks a lot, Krys.Raj, the answer is well explained and working perfectly well.
Thanks again, man.

Penulis

Only one error below, kindly check.
odoo.exceptions.ValidationError: Error while validating view:

Element '<xpath expr="//field[@name='is_published']">', '<xpath expr="//field[@name='website_published']">' cannot be located in parent view

Will check in a minute up to 30 minutes will be back

Ok, the problem is I did it for Odoo 15, now after checking the soruce code od Odoo 14 I see there is no field with "name='website_published'" in this view you tries to inherit.. So remove this xpath:
<xpath expr="//field[@name='is_published']" position="attributes">
<attribute name="groups">hr_recruitment.group_hr_recruitment_manager</attribute>
</xpath>

Penulis

Hi Krys.Raj,
I have removed the xpath and still getting this error:
odoo.exceptions.ValidationError: Error while validating view:

Element '<xpath expr="//field[@name='website_published']">' cannot be located in parent view

Or you have removed the wrong xpath... not the one with 'is_published' or you havent yet updated the module.. from App menu.. check it out.
You should be left only with one xpath
this one;
<xpath expr="//field[@name='website_published']">

so the code should be like this:

<record id="view_hr_job_form_website_published_button_limited" model="ir.ui.view">
    <field name="name">hr.job.form.inherit.published.button_limited</field>
    <field name="model">hr.job</field>
    <field name="inherit_id" ref="website_hr_recruitment.view_hr_job_form_website_published_button"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='is_published']" position="attributes">
            <attribute name="groups">hr_recruitment.group_hr_recruitment_manager</attribute>
        </xpath>
    </field>
</record>

and then update the module...

Oh, and the question is, how do you do it? With module? Have you created one? If you paste this code into the view of course it will generate the error.
Send me screenshot + more explanations..

On Nov 19 2021, at 11:32 am, Jay <jaymezon@gmail.com> wrote:

Hi Krys.Raj,
I have removed the xpath and still getting this error:
odoo.exceptions.ValidationError: Error while validating view:

Element '<xpath expr="//field[@name='website_published']">' cannot be located in parent view
Sent by Odoo S.A. using Odoo.
Sent from Mailspring
Penulis

Now showing this error:
Field "is_published" does not exist in model "hr.job"

Can you explain where do you paste it? Because if you modify the template directly in odoo it has no sense.. this will work only if you created a module and from that you inherit and load that view.

Screenshot, please! It will tell more than words :)

On Nov 19 2021, at 11:47 am, Jay <jaymezon@gmail.com> wrote:

Now showing this error:
Field "is_published" does not exist in model "hr.job"
Sent by Odoo S.A. using Odoo.
Sent from Mailspring
Penulis

I had commented this field in my inherited hr.job and the error is gone.
is_published = fields.Boolean('Is Published', copy=False, default=False)

Will this override the 'Go to Website' from here https://ibb.co/kBjrWGC ?

Penulis

Also, it shouldn't allow employees to publish jobs from recruitment as well as shown here, circled part.
https://ibb.co/nByh6jY

hello jay I am back to the office... taking look into it
Sent from Mailspring
Jay are you there yet? My question is if you like it in the form of xpath full code or just telling you wich view you should modify and how?
Sent from Mailspring
Penulis

xpath full code is fine Krys

I can record a video for you how to find how to find view you want to modify..
but now xpath -> ok 10 minutes.. had a guest in my office before.
Sent from Mailspring
Hello again, here is a link to the pastebin, as the forum code editor is a disaster
What is important your manifest.py (if you do it with custom module) file should include dependency on "website_hr_recruitment" module
like this:
"depends": ["website_hr_recruitment"],
Then this xpath will work as you need.
If you do it in other way than custom module let me know
Sent from Mailspring
Penulis

Code and explanations are fine Krys, no need for a video.

Penulis

added this field in hr.job model:
is_published = fields.Boolean('Is Published', copy=False, default=False)

Will this override the 'Go to Website' from here https://ibb.co/kBjrWGC
and Also, it shouldn't allow employees to publish jobs from recruitment as well as shown here, circled part.
https://ibb.co/nByh6jY?

The code I have provided you is exactly doing the thing
You do not have to recreate the field. Yes, it will be override
Sent from Mailspring
Penulis

Thanks a lot, Krys.Raj.
Working perfectly fine now.

Post Terkait Replies Tampilan Aktivitas
0
Okt 21
1977
2
Jun 22
3894
0
Feb 22
2825
0
Des 21
1634
2
Mei 21
2116