Oh Yeah! I did that before and don't know why I changed it! Thanks so much for taking the time to go through my code. It worked
Mariano. On Thursday, January 8, 2015 12:52:52 PM UTC-3, jmartin wrote: > > > > 2015-01-08 15:10 GMT+01:00 Mariano Ramon <[email protected] > <javascript:>>: > >> >> >> Ok this got a bit long so I summarize and I added the corrections that >> were made along the way: >> >> >> 1) I have two classes Party and Patient >> >> 2) The only constraint to create a Patient is to have a related Party >> >> 3)I need to create a Patient when a Party is created and set the relation >> between the two >> >> (Actually when updating and deleting too and it has to work both ways but >> I'm focusing just on this for now) >> >> >> >> here are the two classes: >> >> class Patient(ModelSQL, ModelView): >> __name__ = 'gnuhealth.patient' >> >> >> name = fields.Many2One( >> 'party.party', 'Patient', required=True, >> domain=[ >> ('is_patient', '=', True), >> ('is_person', '=', True), >> ], >> states={'readonly': Bool(Eval('name'))}, >> help="Person associated to this patient") >> >> >> >> >> >> >> class Party(ModelSQL, ModelView): >> 'Party' >> __name__ = 'party.party' >> >> >> @classmethod >> def create(cls, vlist): >> records = super(Party, cls).create(vlist) >> pool = Pool() >> Patient = pool.get('gnuhealth.patient') >> patient = Patient() >> patient.name = records >> > > You are assigning a list of instances of parties to M2O record instead of > a party instance. Try to select the first one. > > >> patient.save() >> >> return records >> >> >> when I try to create a party I get: >> >> Traceback (most recent call last): >> File >> "/gnuhealth/tryton/server/trytond-3.2.4/trytond/protocols/dispatcher.py", >> line 158, in dispatch >> result = rpc.result(meth(*c_args, **c_kwargs)) >> File >> "/gnuhealth/tryton/server/trytond-3.2.4/trytond/modules/custom/custom.py", >> line 283, in create >> patient.name = records >> File "/gnuhealth/tryton/server/trytond-3.2.4/trytond/model/model.py", >> line 445, in __setattr__ >> super(Model, self).__setattr__(name, value) >> File >> "/gnuhealth/tryton/server/trytond-3.2.4/trytond/model/fields/many2one.py", >> line 80, in __set__ >> assert isinstance(value, (Target, NoneType)) >> AssertionError >> >> >> >> a representation of "records" which would be "value" in the last line of >> the stack trace gives me: >> >> [Pool().get('party.party')(17809)] >> >> >> other thing I tried is not saving Patient and appending it to records: >> >> @classmethod >> def create(cls, vlist): >> records = super(CustomParty, cls).create(vlist) >> pool = Pool() >> Patient = pool.get('gnuhealth.patient') >> patient = Patient() >> records.append(patient) >> >> return records >> >> >> which gives me: >> >> Traceback (most recent call last): >> File >> "gnuhealth/tryton/server/trytond-3.2.4/trytond/protocols/dispatcher.py", >> line 158, in dispatch >> result = rpc.result(meth(*c_args, **c_kwargs)) >> File >> "gnuhealth/tryton/server/trytond-3.2.4/trytond/model/modelstorage.py", line >> 51, in <lambda> >> result=lambda r: map(int, r)), >> File "gnuhealth/tryton/server/trytond-3.2.4/trytond/model/model.py", >> line 456, in __int__ >> return int(self.id) >> TypeError: int() argument must be a string or a number, not 'NoneType' >> >> >> >> Regards >> Mariano >> >> >> >> >> >> >> >> >> > > > > -- > > Jesús Martín > > Zikzakmedia SL > C/ de Sant Jaume, 9, baixos, 2ª > 08720 Vilafranca del Penedès > ☏ 93 890 21 08 >
