İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
3375 Görünümler

i want to hide the field "parent_id"  in the 'hr.department' form view if the field "scale" equal to "top" 

the thing is the "scale" field from diffrent class than the partner_id 


in my model.py 

class depart_typ(models.Model):

    _inherit = "hr.department"


    depart_typ = fields.Many2one('department.type', 'Type')

    

class depart_line(models.Model):

    _name = "department.type"

    _description = "Type Hierarchie"


    nom_typ = fields.Char(string="Nom")

    scale =  fields.Selection([ ('type1', 'top'),('type2', 'intermed'),('type3', 'child'),],'Niveau', default='type2')


and on my xm file 


<record id="view_hr_department_inherit" model="ir.ui.view">

                <field name="name">hr.department.form.inherit</field>

                <field name="model">hr.department</field>

                <field name="inherit_id" ref="hr.view_department_form"/>

                <field name="arch" type="xml">

                    <xpath expr="//form/sheet/group/field[@name='parent_id']" position="before">

                        <field name="depart_typ">

                            <form>

                                <group>

                                    <field name="scale"/>

                                    <field name="parent_id" string="Unité fonctionnement Parent" attrs="{'invisible':[('scale', '==', 'type1')]}"/>

                                    <field name="nom_typ"/>

                                </group>

                            </form>

                        </field>

                        

                    </xpath>


                </field>

    </record>


and i get the error that the partner_id dosen't exist 

which is totally logical, the filed in not on the same classe. is there any solution ? 

     

Avatar
Vazgeç

Which Field you want to hide?? parent _id or partner_id ? ?

didn't saw any field named partner_id in your code .

Üretici

yes the parent_id sorry for miss leading you, i updated my question 

Üretici En İyi Yanıt
i got this error when i declared as a related field 

File "/usr/lib/python3/dist-packages/odoo/fields.py", line 486, in _setup_related_full
    field = target._fields[name]
KeyError: 'depart_typ'



Avatar
Vazgeç

Did you declare this field in the hr.department model? Also if you can please share the complete code here to see where the problem is.

Üretici

here is my code on model.py

class depart_typ(models.Model):

_inherit = "hr.department"

depart_typ = fields.Many2one('department.type', 'Type')

class depart_line(models.Model):

_name = "department.type"

_description = "Type Hierarchie"

name = fields.Char(string="Nom", store=True, readonly=False)

scale = fields.Selection([ ('type1', 'Top'),('type2', 'Interm'),('type3', 'Child'),],'Scale', default='type2')

the xml file

<record id="view_hr_department_inherit" model="ir.ui.view">

<field name="name">hr.department.form.inherit</field>

<field name="model">hr.department</field>

<field name="inherit_id" ref="hr.view_department_form"/>

<field name="arch" type="xml">

<xpath expr="//form/sheet/group/field[@name='parent_id']" position="before">

<field name="depart_typ">

<form>

<group>

<field name="name"/>

<field name="scale"/>

<field name="parent_id" string="Unité fonctionnement Parent" attrs="{'invisible':[('scale', '==', 'type1')]}"/-->

</group>

</form>

</field>

</xpath>

</field>

</record>

En İyi Yanıt

Hi himaOdoo,

You will have to declare a related field in hr.department like

scale = fields.Selection(related='depart_typ.scale')
Hope it will solve your issue!!!

P.S. You will get an error for 

<field name="nom_typ"/> 
as nom_type does not belong to hr.department model
Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Kas 24
9310
4
May 24
12661
1
Nis 24
3286
0
Kas 23
2032
1
Eyl 23
2117