I've installed the oemedical addon in my OperERP 7. I'm adding some modifications on it.
I have a problem with the function _get_ssn_from_name that I have created in the appointment module, which gets the SSN from the oemedical.patient class to display it in oemedical.appointment view.
Here is the code of the class oemedical.appointment containing the function I've developed
class OeMedicalAppointment(osv.Model):
_name = 'oemedical.appointment'
# The function causing the problem
def _get_ssn_from_name(self, cr, uid, ids, field_name, arg, context=None):
res = {}
ssn = ''
for record in self.pool.get('oemedical.patient').browse(cr, uid, ids, context=context):
# When patient is not yet specified
if not record.lastname:
ssn = 'No Patient Specified!'
# Return the ssn when the caller is the field name
if field_name == 'alias':
if record.ssn:
ssn = record.ssn
else:
ssn = "Not Specified"
print("ssn : %s" % ssn)
res[record.id] = ssn
return res
_columns = {
'patient_id': fields.many2one('oemedical.patient', string='Patient',
required=True, select=True,
help='Patient Name'),
'name': fields.char(size=256, string='Appointment ID', readonly=True),
'appointment_date': fields.datetime(string='Date and Time'),
'appointment_day': fields.date(string='Date'),
# some other attributes
'alias': fields.function(_get_ssn_from_name, type='char', string='SSN', help="Social Security Number", multi=False),
# other attributes
}
OeMedicalAppointment()
And here is the code of the class oemedical.patient
class OeMedicalPatient(osv.Model):
_name='oemedical.patient'
_inherits={
'res.partner': 'partner_id',
}
_columns={
'partner_id': fields.many2one(
'res.partner', 'Related Partner', required=True,
ondelete='cascade', help='Partner-related data of the patient'),
'first_name': fields.char(size=256, string='Name', required=True),
'lastname': fields.char(size=256, string='Lastname', required=True),
# many other attributes..
'ssn': fields.char(size=256, string='SSN'),
# some other attributes..
'deceased': fields.boolean(string='Deceased'),
}
OeMedicalPatient()
Here is the interface of creation of a new appointment : http://i.stack.imgur.com/lX9CE.png
When I create a new patient on the Appointment creation form (the field where I can choose the patient in the screenshot), I doesnt't get an error and everything goes well, but when I try to create an appointment for an existing patient I get the following error :
AttributeError: 'Field lastname not found in browse_record(oemedical.patient, 8)'
Please help me, and thanks in advance!!