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

How change format display a field in qweb report?


function in python file:

def _get_name(self,partner_id):

    sql = """ select name as name1 from res_partner
                    where id=%s """ %(partner_id)
    self.env.cr.execute(sql)
    return self.env.cr.dictfetchone()


template xml:

            <span t-esc="get_name(partner_id)"/>

output pdf report:


    {'name1': mosao}


I want just display: mosao

please help me.

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

Hi Anu and Sudhir Arya, Thanks for your answer correct.

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

dictfetchone will give you the dictionary for the single record. So you have to fetch the value from the dict.

Try following code:

return self.env.cr.dictfetchone().get('name1', '')

See different python fetch types for fetching data from query.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

  just try any of the following

     <span t-esc="get_name(partner_id)['name1']"/>

or 
      record =  self.env.cr.dictfetchone() 

 retrun record['name1']                                                                                                          

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
1962
1
พ.ค. 25
2050
QWeb: use t-if to check birthday date แก้ไขแล้ว
1
เม.ย. 25
2481
1
ก.พ. 25
1751
0
ต.ค. 24
1494