如何使用OpenERP中的browse方法从另一个类获取属性

时间:2014-07-15 16:21:27

标签: python orm openerp-7

我已经在我的OperERP 7中安装了oemedical插件。我在其上添加了一些修改。 我在约会模块中创建的函数 _get_ssn_from_name 有问题,它从 oemedical.patient 类中获取SSN以在 oemedical中显示它。预约视图。

以下是包含我已经开发的功能的oemedical.appointment类的代码

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()

以下是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()

以下是创建新约会的界面: Interface of adding a new appointment

当我在约会创建表单(我可以在屏幕截图中选择患者的字段)中创建新患者时,我没有收到错误并且一切顺利,但是当我尝试创建预约时对于现有患者,我收到以下错误:

AttributeError: 'Field lastname not found in browse_record(oemedical.patient, 8)'

请帮助我,并提前致谢!!

1 个答案:

答案 0 :(得分:0)

我在official OpenERP Q/A forum得到了答案,问题解决了。