Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
39611 Lượt xem

I want to remove a group from HR Settings section using my customized module.

Section to be removed in hr.view_employee_form has been added by hr_holidays_view.xml using inheritance

hr_view.xml(view_employee_form form)

<page string="HR Settings" groups="base.group_hr_user">
           <group>
                       <group string="Active" name="active_group">
                                <field name="active"/>
                         </group>
            </group>

 </page>

Code added by hr_holidays_view.xml

 <xpath expr="//group[@name='active_group']" position="before">
          <group string="Leaves">
                   <label for="remaining_leaves"/>
                        <div>
                            <field name="remaining_leaves" class="oe_inline"/> days
                        </div>
           </group>
  </xpath>

 

Code written by me to remove that Remaining Leaves block, in my customized module is :

<xpath expr="/form/sheet/notebook/page[@string='HR Settings']/group/group[@string='Leaves']" position="replace">

</xpath>

and I am getting following error:

 

AttributeError: View definition error for inherited view 'custom_emp.emp_code_view_form' on model 'hr.employee': Element '<xpath expr="/form/sheet/notebook/page[@string='HR Settings']/group/group[@string='Leaves']">' not found in parent view 'hr.view_employee_form'

Please help!

 

Updated Full Code :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

        <!--Employee form view -->
        <record id="emp_code_view_form" model="ir.ui.view">
            <field name="name">hr.employee.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form" />
            <field name="arch" type="xml">
                <xpath expr="/form/sheet/notebook/page[@string='HR Settings']/group/group[@string='Leaves']" position="replace">
                </xpath>
                <xpath expr="/form/sheet/notebook/page[@string='HR Settings']/group/group[@string='Active']/field[@name='active']" position="after"
                         <field name="working_status" />
                </xpath>
             </field>
        </record>
     </data>
</openerp>

 

Update: Above code is working well on one machine but not other one!!

Ảnh đại diện
Huỷ bỏ
Tác giả

I have tried <xpath expr="//group[@string='Leaves']" position="replace"> code as well....but no success

Please post your complete custom view declaration.

Tác giả

Code has been updated....2nd xpath tags are working well....

Câu trả lời hay nhất

Hi,

You can solve this issue by two way.

1) Just write down the inheritance as like below.

        <record id="view_employee_form_leave_inherit_to_remove_leaves" model="ir.ui.view">
            <field name="name">hr.employee.leave.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr_holidays.view_employee_form_leave_inherit"/>
            <field name="arch" type="xml">
                <xpath expr="//group[@string='Leaves']" position="replace">
                </xpath>
            </field>
        </record>

 

2) Override the view of the hr_holidays like below.

        <record id="hr_holidays.view_employee_form_leave_inherit" model="ir.ui.view">
            <field name="name">hr.employee.leave.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <xpath expr="//group[@name='active_group']" position="before">
                </xpath>
                <xpath expr="//div[@name='button_box']" position="inside">
                    <button name="%(act_hr_employee_holiday_request)d" string="Leaves" type="action" groups="base.group_hr_user"/>
                </xpath>
            </field>
        </record>

 

Ảnh đại diện
Huỷ bỏ

Hi, I have tested it in my local system. It is working perfectly. So, just try it and mark my answer with your vote.

Tác giả

@Chirag : Much thanks dude.......I opted first one and it worked!!! Thumbs up!!!

Câu trả lời hay nhất

Are you apply inheritance to inherited view?

Ảnh đại diện
Huỷ bỏ
Tác giả

yes

But Error point to parent view. Please post full your record.

Tác giả

Code has been updated.....please check

change reference on inhereted view!

field name="inherit_id" ref="hr.view_employee_form"

Tác giả

It's already there

must be (field name="inherit_id" ref="inhereted view from hr_holidays_view.xml")

Tác giả

then how i will make changes in hr.view_employee_form?

it will apply to new view (inhereted)

That will be combination of parent view plus change

Câu trả lời hay nhất

Change the inherit_id in your custom view to hr.employee.leave.form.inherit:

<field name="inherit_id" ref="hr.employee.leave.form.inherit"/>

 

Regards.

Ảnh đại diện
Huỷ bỏ
Tác giả

I can't do that because i am making changes in hr employee form view as well....you would have seen in my code that i have added working_status field as well using xpath

Give it a try (or inherit both views.)

Tác giả

Can't do because it's not present in any form....it has been inherited to hr employee module

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 2 25
2316
1
thg 8 24
1964
2
thg 11 24
3138
3
thg 10 23
14676
2
thg 2 23
2366