Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6086 Lượt xem

Hi , 

I have 2 models , in the 1st model i have name and date , and in the 2nd model i have the name .


First model:

class Patient(models.Model):

_inherit = 'res.partner'

_name = 'res.partner'

Date_naissance = fields.Date()


Second model:

class ordonnance(models.Model):

_inherit = 'account.invoice'

...


I want to choose the name and get the value of field Date_naissance related to this name, then I need to show it in the view of 2nd model. how can I do it please ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

try this
In Second Model, write this

@api.onchange('name')
def get_date_from_first_model_using_name(self):
  Obj= self.env['res.partner'].search([('name', '=', self.name)])
get_date= Obj[0].Date_naissance
  self.second_model_column_name= get_date # This will get date from first model using name field # Please Tick this answer if this help you

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you for your answer Sah Vinay Mahabir, please how can I call it in my xml ?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 24
2354
4
thg 11 23
6519
0
thg 10 23
2298
0
thg 12 22
3071
2
thg 12 23
20167