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

I am trying to return the entire XML chunk to the controller in order to make them downloaded as an XML file.

  from xml.etree import ElementTree as ET  
    @api.model
    
def _xml_download(self): root
root = ET.Element("Test A")
doc = ET.Element("Test B")
root.append(doc)
return ET.ElementTree(root)

And here is my controller:

class TestXMl(http.Controller):
    @http.route('/xml/download/report', type='http', auth="user")
@serialize_exception
def sale_xml_download(self, model, id, filename=None, **kw):
filename = 'Test%s.xml'%('Test')
records= http.request.env['sale.order'].search([('some_attribute', '=', True)])
if records:
xml_record = http.request.env['sale.order']._xml_download()
else:
xml_record = 'Test'
filename = 'Test%s.xml'%('Test') headers = [
('Content-Type', 'application/xml'),
('Content-Disposition', content_disposition(filename)),
('charset', 'utf-8'),
]
return request.make_response(
xml_record, headers=headers, cookies=None)
But I xml_record is not getting the element tree. It is saying TypeError: 'ElementTree' object is not iterable - - - In this case how we suppose to pass the elementTree. Looking for useful response, thank you in advance
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

you directly pass etree object as response data (xml_record). you have to convert it to string before you pass as response data.  ref. etree.tosting(xml_record)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Odoo Date Total In Version 11 แก้ไขแล้ว
3
มี.ค. 19
3084
Hide field using One2many domain แก้ไขแล้ว
1
ม.ค. 19
5690
3
ธ.ค. 18
8513
0
พ.ย. 18
5309
0
พ.ค. 22
2916