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

hey, can any body help me im new in Odoo and I have a question the question is :

I have this relation :

class Complaint(models.Model):


    _name = 'complaint'

    _description = 'Manage employee complaint'

    employee = fields.Many2one('hr.employee', string="Employee", required=True)



  the question is how can add a field into Employee model that field have all complaint created by this employee or in other world reverse this relation in the base Employee model? 
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Use One2Many.

* Syntax:

fields.One2many('related_model', 'related_field')

* Example 
class HRemployee(models.Model):
    _inherit = 'hr.employee'

    compaint_ids = fields.One2many("complaint", "employee", string="Complaints")


Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
Hi,

class HrEmployee(models.Model):
_inherit = 'hr.employee'

complaint_ids = fields.One2many('related_model', 'related_field', string="Complaints")

class Complaint(models.Model):
_name = 'complaint'
_description = 'Manage employee complaint'

employee = fields.Many2one('hr.employee', string="Employee", required=True)

Based on the employee selected in the 'complaint' model, records created will be related to respective employee.

Thanks
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Use one2many relation for hr.employee:

class HRemployee(models.Model):
    _inherit = 'hr.employee'

    compaint_ids = fields.One2many("complaint", "employee", "Complaints")
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 24
3663
0
thg 2 16
4357
2
thg 8 25
2394
1
thg 7 25
898
1
thg 8 25
1151