Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
7400 มุมมอง

i created i module that has as a field manager, i want to be filled automatically with the value of the parent_id field of the hr.employee

how i can do this ? 

 

i tried this way but i don't know how to point to the parent_id field 

                class Job_Certification(models.Model):

                _name = 'job.certification'


              manager = fields.Many2one(

             'hr.employee',

             'manager',

             default=lambda self: self.env['hr.employee']._company_default_get('my_module_name')

            )

อวตาร
ละทิ้ง

Other module method can call same way, self.env['hr.employee']._company_default_get()

Did you find an answer to this?

คำตอบที่ดีที่สุด
You can create default custom method in the same class. In the method return the hr.employee record id based on required conditions.

Below Example from Default core Module:

def _get_default_journal(self):
return self.env['account.journal'].search([('type', '=', 'general')], limit=1).id


journal_id = fields.Many2one('account.journal', string='Journal', required=True, default=_get_default_journal, domain=[('type', '=', 'general')])
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

so in my case what should it put inside the domain ?  if i want to get the value of the parent_id field ? 

def _get_default_manager(self):
return self.env['hr.employee'].search([('??', '=', '??')], limit=1).id


manager = fields.Many2one('hr.employee', string='Manager', required=True, default=_get_default_manager, domain=[('??', '=', '??')])
อวตาร
ละทิ้ง

Yes, default which hr.employee id (name) would you like to display, based on that condition will apply.

ผู้เขียน

hh sorry but still i don't get it, can you please write it down ?

ผู้เขียน

let's say the id is 22

ผู้เขียน

i change the domain with the following

('name' = 'parent_id')

and it works just fine

thanks for your help

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 21
2422
2
ก.พ. 24
2608
3
ก.ย. 25
1811
2
ก.พ. 25
6354
4
พ.ค. 24
13263