我做了一个选择后如何显示我的两个字段的值

时间:2017-05-04 16:10:28

标签: openerp

我有两种模式:

  • openssl asn1parse -i -dump -inform DER < your.signed.cms

这是我的班级:

&#13;
&#13;
medical.lab.test.type
&#13;
&#13;
&#13; 和

  • class MedicalLabTestType(models.Model): _name = "medical.lab.test.type" _description = "Medical Lab Test Types" name = fields.Char( 'Test', help='Name of test type, such as X-Ray, Hemogram, Biopsy, etc.', required=True, ) code = fields.Char( 'Code', size=128, help='Short name or code for test type.', required=True, ) description = fields.Text('Description') Test_Prix = fields.Float( string='Price of the test', required=True, ) Nbr_days = fields.Integer( string='Number of days to have results', required=True, )

这是我的班级:

&#13;
&#13;
medical.lab
&#13;
&#13;
&#13;

问题是,一旦我选择了测试,就会在视图中显示class MedicalLab(models.Model): _name = 'medical.lab' _description = "Medical Labs" test_type_id = fields.Many2one( string='Test Type', comodel_name='medical.lab.test.type', help='Lab test type.', ) physician_id = fields.Many2one( string='Pathologist', comodel_name='medical.physician', help='Pathologist that performed the exam.', ) request_physician_id = fields.Many2one( string='Requesting Physician', comodel_name='medical.physician', help='Physician that requested the exam.', )Test_Prix的值

我该怎么办?,我应该使用onchange功能!!!

1 个答案:

答案 0 :(得分:0)

在您应该使用的当前视图上显示所选m2o的字段 相关领域。

midecal.lab模型中添加:

# related field should always keep the same type Foalt Float, Char Char
# and it's recommended that you put readonly because if you edit 
# the value the value will be edited in the related record when you save
Test_Prix = fields.Float(
 retlated='test_type_id.Test_Prix',
 readonly=True
)

Nbr_days = fields.Integer(
    retlated='test_type_id.Nbr_days',
    readonly=True
)    

现在您可以将此两个字段添加到您的视图中,如

  

注意:相关字段不存储在数据库中,如果您使用它们作为代理   想要使用store=True

在数据库中创建字段

编辑:

使用onchange而不是计算字段计算

date_perform = fields.Datetime( string='Date of Results', )

@api.onchange('date_request', 'Nbr_days') 
def _compute_date_result(self): 
    for record in self: 
        business_days_to_add = record.Nbr_days 
        current_date = fields.Datetime.from_string(record.date_request) 
        .....