Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
10705 มุมมอง

Hello, Odoo community! 

I have a text field that fills with a list of a product like below, how can I write each product in a separate line.

food = ['Gouda Cheese', 'Pizza Italiana']

I want :

food = ['Gouda Cheese',

              'Pizza Italiana']

my python code:

food = fields.Text(string = 'food')

@api.onchange('date')
def _onchange_food(self):
d= datetime.datetime.strptime(self.date , "%Y-%m-%d").strftime('%A')
self.food =self.env['lunch.menu'].search([('day', '=', d)]).mapped('product.name')


อวตาร
ละทิ้ง

Could you please explain more?

คำตอบที่ดีที่สุด

You can go with Join like this

self.food ='\n '.join(self.env['lunch.menu'].search([('day', '=', d)]).mapped('product.name'))



อวตาร
ละทิ้ง
ผู้เขียน

thanks a lot.

คำตอบที่ดีที่สุด

I normally use the Html field, but you can use the html widget for the field in the view. I use this method for logging while importing data in custom wizards. you can use ordered list or whatever you want and it shows the data line by line. 

I then normally just do

def display_log(self, log_list):
  tmp_text = ''
  for item in list:
     tmp_text + = '<p>{}</p>'.format(item)
  self.food = tmp_texp

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 15
3496
0
ม.ค. 25
1
0
ก.พ. 25
1202
0
ม.ค. 25
1023
Field service upgrade แก้ไขแล้ว
1
ธ.ค. 24
1325