Skip to Content
Menú
This question has been flagged

I have a model which inherits "res.partner" (Patient) and this model have a One2many field with the Patient family members (family members are Patients to), and here is the problem.
In the dopdown list I can select other patients to add as a family member, but every time I add a new family member the stored family member is always the patient to which I am adding the relatives.

Does anyone have any idea why this happens?

Code:

# Patient Management
class HealthcarePatient(models.Model):
_name = 'healthcare.patient'
_description = 'Patient information'
_inherit = ['mail.thread', 'mail.activity.mixin']
_inherits = {
'res.partner': 'partner_id',
}

partner_id = fields.Many2one(
'res.partner',
string='Related Partner',
help='Partner-related data of the patient',
required=True,
ondelete='restrict',
index=True
)


family_ids = fields.One2many('healthcare.family', 'patient_id', string='Family')


# Family Management
class HealthcareFamily(models.Model):
_name = 'healthcare.family'
_description = 'Family Information'
_rec_name = 'patient_id'
_order = 'sequence, patient_id'

patient_id = fields.Many2one(
'healthcare.patient',
string='Patient',
domain=lambda self: self._get_patient_domain(),
required=True,
ondelete='cascade',
index=True
)
relation = fields.Many2one('healthcare.family.relation', string='Relation', required=True)
age = fields.Char(related='patient_id.age', string='Age')
sequence = fields.Integer(string='Sequence', index=True)

def _get_patient_domain(self):
parent_id = self.env.context.get('parent_id')
return [('id', '!=', parent_id)]


# Family Relation Management
class HealthcareFamilyRelation(models.Model):
_name = 'healthcare.family.relation'
_description = 'Family Relation'

name = fields.Char(string='Name')

Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de nov. 23
497
3
de jul. 23
3062
1
de maig 25
2410
1
d’abr. 25
3426
1
d’abr. 25
4244