2017-05-04 21 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

相關問題