0
votes

I have created a related field on the custom payroll form and I use odoo 10. I can not get the same name in one2many form field with input field.

I have attached picture in below. Hope in here, I want to make the name in black pen same with the name in blue pen. But in the picture, I can't get the name from blue pen show in the black pen.

problem

Here my code :

gaji.py
  emp_id = fields.Many2one('karyawan', 'Karyawan')

karyawan.py
  nama = fields.Char(string="Nama Karyawan")
  gaji_ids = fields.One2many('gaji', 'emp_id', 'Gaji')

karyawan_view.xml
   <page string="Gaji" name="gaji">
                        <field name="gaji_ids" context="{'default_emp_id':nama}" widget="one2many_list">
                            <tree editable="bottom">
                                <field name="emp_id" attrs="{'readonly': [('emp_id', '!=', False)]}"/>
                                <field name="gaji_pokok"/>
                                <field name="jumlah_hari_kerja"/>                                    
                                <field name="jumlah_kerja"/>  
                                <field name="libur"/>                                                                      
                                <field name="jam_lembur"/>                                    
                                <field name="t_lembur"/>
                                <field name="t_transportasi"/>
                                <field name="total_pendapatan"/>
                            </tree>
                        </field>
                    </page>

Anyone can help me about this?

3

3 Answers

0
votes

Rename field name nama to name in karyawan.py

karyawan.py

name = fields.Char(string="Nama Karyawan")

In many2one field, the system will fetch value of name field in a comodel. If field name doesn't exist will display model name with id (karyawan,2).

Hope it will help you.

0
votes

You have two different field labels:

emp_id = fields.Many2one('karyawan', 'Karyawan')  # second parameter is the label

and

nama = fields.Char(string="Nama Karyawan")  # string parameter is the label

So change one of the two.

0
votes

add this in your model

 _rec_name= 'nama'

nama = fields.Char(string="Nama Karyawan") gaji_ids = fields.One2many('gaji', 'emp_id', 'Gaji')