تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
5179 أدوات العرض

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? 
الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة
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
الصورة الرمزية
إهمال
أفضل إجابة

Use one2many relation for hr.employee:

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

    compaint_ids = fields.One2many("complaint", "employee", "Complaints")
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يناير 24
3592
0
فبراير 16
4331
2
أغسطس 25
2185
1
يوليو 25
739
1
أغسطس 25
1150