[tryton-dev] Problems using one2many and many2many fields

2017-05-03 Thread Carlos Ibrahim Arias
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.')



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'])

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.


[tryton-dev] Best way to test for a date in a date field

2017-05-03 Thread Vincent Bastos
Hi,

I wanted to know what the best way to write a domain for a search call to 
test for records that have a date in a particular field.

My idea is something like this:

nodate = Date(0)

invoices = Invoice.search([
('lease', '=', self.id),
('state', '!=', 'paid'),
('mydate', '!=', nodate),
], order=[('invoice_date', 'ASC')])

-- 
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/8355fce6-1a12-45e8-be59-b963d4fc3909%40googlegroups.com.


Re: [tryton-dev] Best way to test for a date in a date field

2017-05-03 Thread Sergi Almacellas Abellana

El 02/05/17 a les 07:59, Vincent Bastos ha escrit:

Hi,

I wanted to know what the best way to write a domain for a search call
to test for records that have a date in a particular field.

My idea is something like this:

nodate = Date(0)

invoices = Invoice.search([
('lease', '=', self.id),
('state', '!=', 'paid'),
('mydate', '!=', nodate),
], order=[('invoice_date', 'ASC')])
Not sure to understand, but if you want to search for invoices where the 
mydate field is empty you can search for None as values. The clause will be:


('mydate', '=', None)

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
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/a3d39cd9-3534-6baa-020d-551ba2f345ad%40koolpi.com.


Re: [tryton-dev] Problems using one2many and many2many fields

2017-05-03 Thread Sergi Almacellas Abellana

El 03/05/17 a les 04:23, Carlos Ibrahim Arias ha escrit:

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


I'm not sure to understand what are you trying to achieve. Can you 
elaborate?




This is the first class...

|
classZ_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
defdefault_medical_history_date():
returndatetime.now()

@staticmethod
defdefault_healthprof():
pool =Pool()
HealthProfessional=pool.get('gnuhealth.healthprofessional')
returnHealthProfessional.get_health_professional()


@staticmethod
defdefault_patient():
pool =Pool()
Patient=pool.get('gnuhealth.patient')
returnPatient.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.')



The second argument of the One2Many field is the target field. This 
means the name of the field which has the reverse Many2One relation in 
the target model. So in your case you have yo change 'Z_MedicalHistory' 
for 'patient'.

|


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.


With this description, I imagine you want a function field that returns 
all the MedialHistory entries for this patient, not a Many2Many.


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'])
|


Many2Many fields require an intermediary table to store the relation 
between both records.


I guess I'm not doing it right. :(

Thanks it advanced!


Hope it helps.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
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/e2e4884b-8c6a-3103-1d7e-389b7a08ecdc%40koolpi.com.


Re: [tryton-dev] Problems using one2many and many2many fields

2017-05-03 Thread Albert Cervera i Areny
2017-05-03 4:23 GMT+02:00 Carlos Ibrahim Arias :
> 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.


Re: [tryton-dev] resend:upgrade warnings with recent develop branch

2017-05-03 Thread Cédric Krier
On 2017-05-01 22:39, Richard PALO wrote:
> [resend, g$ggle still broke, apparently]
> full upgrade with recent 'develop' shows the following:
> > 4815 140668832162880 [2017-05-01 16:35:10,058] WARNING 
> > trytond.backend.postgresql.table Unable to set column company of table 
> > account_fiscalyear_invoice_sequence not null !
> > Try to re-run: trytond.py --update=module
> > If it doesn't work, update records and execute manually:
> > ALTER TABLE "account_fiscalyear_invoice_sequence" ALTER COLUMN "company" 
> > SET NOT NULL
> > 
> 
> Indeed I have 25 records where company is not set here (single company db).
> 
> Is this a case where I need to manually set the company (id=1), or is
> it a possible omission in the migration code to check?

I'm pretty sure it is because you are migrating between two development
versions. We do not support such migration, only between releases.

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
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/20170503081210.GE55822%40tetsuo.


Re: [tryton-dev] Problems using one2many and many2many fields

2017-05-03 Thread Carlos Ibrahim Arias
I created the model Z_MecialHistory to store information of the patient (*date, 
patient and healthprofessional*) and it is related to the model PatientData. 
The point is that, as Albert said, I need to access to the information in 
the model PatientEvaluation.

After adding the function field Albert recommended to the model 
PatientEvaluation


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


... I added the following function to PatientEvaluation model guessing that 
I had to use the current patient 

def get_z_medical_history(self, name):
pool = Pool()
Patient = pool.get('gnuhealth.patient')
return Patient.z_medical_history

But it doesnt work... I dont really understant how to the get function 
should be coded to worrk...





And got the following error...





El miércoles, 3 de mayo de 2017, 8:46:36 (UTC+1), Albert Cervera i Areny 
escribió:
>
> 2017-05-03 4:23 GMT+02:00 Carlos Ibrahim Arias  >: 
> > 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/27fea2b4-79d6-4019-a477-3f1dbf17d8d2%40googlegroups.com.


Re: [tryton-dev] Problems using one2many and many2many fields

2017-05-03 Thread Sergi Almacellas Abellana

El 03/05/17 a les 16:55, Carlos Ibrahim Arias ha escrit:

I created the model Z_MecialHistory to store information of the patient
(/date, patient and healthprofessional/) and it is related to the model
PatientData. The point is that, as Albert said, I need to access to the
information in the model PatientEvaluation.

After adding the function field Albert recommended to the model
PatientEvaluation


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

|

... I added the following function to PatientEvaluation model guessing
that I had to use the current patient 

|
defget_z_medical_history(self,name):
pool =Pool()
Patient=pool.get('gnuhealth.patient')
returnPatient.z_medical_history
|

But it doesnt work... I dont really understant how to the get function
should be coded to worrk...
You should return the list of ids of the related record. So it will be 
something like:


def get_z_medical_history(self, name):
pool = Pool()
History = pool.get('...')
return [x.id for x in History.search([('patient', '=', self.id)])


Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
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/2c1e7d40-5ad2-7d26-d4bf-de6d8c850fad%40koolpi.com.