2017-05-04 22 views
0

我有两个型号:odoo如何显示我的两个字段的值,一旦我做了选择

  • medical.lab.test.type

这是我的课:

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

  • medical.lab

这是我的课:

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_PrixNbr_days值一旦我选择一个测试

我应该如何继续?,我应该使用onchange功能离子!!!

+0

使用'onchange'函数加载值,让用户编辑/更改。 – Zety

回答

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 
)  

,现在你查看喜欢

NB你可以添加此两个场:相关的领域并不存储在数据库中,他们的代理工作,如果你 要在数据库中创建野外使用store=True

EDITS:

使用的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) 
     ..... 
+0

谢谢,我会为你祈祷 – Borealis

+0

是的,我们需要它你知道。谢谢 – Cherif

+0

当我点击保存按钮时,如何评估字段值以更改另一个字段值? – Borealis

相关问题