2017-05-03 4:23 GMT+02:00 Carlos Ibrahim Arias <braim...@gmail.com>:
> Hi! I'm having problems using a one2many field on another model different
> from the class it was created on. I tried to use a many2many field so that I
> can view the related fields but cant make it work
>
> This is the first class...
>
> class Z_MedicalHistory(ModelSQL, ModelView):
>
>     'Patient Medical History'
>     __name__ = 'gnuhealth.z_medical_history'
>
>     medical_history_date = fields.DateTime('Date and Time', required=True)
>
>     healthprof = fields.Many2One(
>         'gnuhealth.healthprofessional', 'Health Prof',
>         select=True, required=True, help='Health Professional')
>
>     patient = fields.Many2One(
>         'gnuhealth.patient', 'Patient',
>         select=True, required=True, help='Patient Name')
>
>     comments = fields.Text('Comments', required=True)
>
>     @staticmethod
>     def default_medical_history_date():
>         return datetime.now()
>
>     @staticmethod
>     def default_healthprof():
>         pool = Pool()
>         HealthProfessional = pool.get('gnuhealth.healthprofessional')
>         return HealthProfessional.get_health_professional()
>
>
>     @staticmethod
>     def default_patient():
>         pool = Pool()
>         Patient = pool.get('gnuhealth.patient')
>         return Patient.name
>
>
> I added the following lines to the class PatientData (gnuhealth.patient) so
> that they are related
>
>     z_medical_history = fields.One2Many(
>         'gnuhealth.z_medical_history',
>         'Z_MedicalHistory', 'Patient Medical History', help='Enter the
> Patient Medical History'
>         ' for the patient.')

AFAIS the One2Many definition should be:

     z_medical_history = fields.One2Many(
         'gnuhealth.z_medical_history',
         'patient', 'Patient Medical History', help='Enter the Patient
Medical History'
         ' for the patient.')

Note the second parameter must be the name of the Many2One field of
the related model.

>
>
>
> The problem is that there is another class call PatientEvaluation where I
> need to hace access and view Z_MedicalHistory using the patient field of
> PatientEvaluation. Tried the following but it's not working:
>
>     z_medical_history = fields.Many2Many('gnuhealth.z_medical_history',
>         'patient', None, 'Historial Medico del Paciente',
>         domain=[('patient', '=', Eval('patient'))],
>         depends=['patient'])

If you need to access the information of z_medial_history from another
model either you link it directly or you create a Function field. I
guess the latter is what you're looking for. So you need something
like this:

     z_medical_history =
fields.Function(fields.Many2Many('gnuhealth.z_medical_history',
         None, None, 'Historial Medico del Paciente'), 'get_z_medial_history')


>
> I guess I'm not doing it right. :(
>
> Thanks it advanced!
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "tryton-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tryton-dev/5e9dceb7-28d3-4dc1-be43-61b5834cf895%40googlegroups.com.



-- 
Albert Cervera i Areny
http://www.NaN-tic.com
Tel. 93 553 18 03

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/CADWJ7Gn-voz7kQ6fm6diS7rxmrHbzspHd7bdptog6me0bRbKhw%40mail.gmail.com.

Reply via email to