I have to filter data in Many2one field

Viewed 9

I have to models related to employees, one with contracts

class Contract(models.Model):
    _name = 'hr.employee.contract'
    _description = "employee contract model"
    _rec_name = 'begin_date'
    _order = 'begin_date desc'

    type = fields.Many2one(string='Contract Type', comodel_name='hr.employee.contract_type')
    category = fields.Many2one(string='Contract Category', comodel_name='hr.employee.contract_category')
    begin_date = fields.Date(string='Begin Date')
    end_date = fields.Date(string='End Date')
    work_place = fields.Many2one(comodel_name='hr.employee.vessel', string='Work Place')
    enterprise = fields.Char(related='work_place.enterprise.name', string='Enterprise')
    sick_leave_reason = fields.Char(string='Sick Leave Reason')
    employee = fields.Many2one(comodel_name='hr.employee', string='Employee ID', ondelete='cascade')
    crew_member = fields.Many2one(string='Crew Member', comodel_name='hr.employee.crew_member')
    internal_contract_id = fields.Integer(string='Internal Contract Id')
    contract_code = fields.Integer(string='Contract Code')

And another model in whick I have to store the different work places for a certain contract. Both models are shown as tree list inside the employee card.

class Assignement(models.Model):
   _name = 'hr.employee.assignement'
   _description = "Employees assignement model"

  contract_id = fields.Many2one(comodel_name='hr.employee.contract', string='Contrato')
  employee = fields.Many2one(comodel_name='hr.employee', string='Employee ID')
  work_place = fields.Many2one(comodel_name='hr.employee.vessel', string='Work Place')
  begin_date = fields.Date(string='Begin Date')
  end_date = fields.Date(string='End Date')

As it should work, if I edit the employee card which has a certaint number of contracts linked, when I am going to introduce an assignement, when I click on the field contract it should show only contracts of the employee a I am editing.

Help please.

Best regards

0 Answers
Related