39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
from odoo import http
|
|
from odoo.http import request
|
|
import json
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
class GanttExportController(http.Controller):
|
|
|
|
@http.route('/gantt_view_ck/export/data', type='http', auth='user')
|
|
def export_data(self, format='json'):
|
|
# For simplicity, exporting all tasks. You can filter by active project.
|
|
tasks = request.env['project.task'].search([])
|
|
|
|
if format == 'json':
|
|
data = [{'name': t.name, 'start': str(t.gantt_start_date), 'end': str(t.gantt_end_date)} for t in tasks]
|
|
return request.make_json_response(data)
|
|
|
|
elif format == 'xml':
|
|
root = ET.Element("GanttProject")
|
|
for t in tasks:
|
|
task_el = ET.SubElement(root, "Task")
|
|
task_el.set("name", t.name)
|
|
task_el.set("start", str(t.gantt_start_date))
|
|
return request.make_response(ET.tostring(root), headers=[('Content-Type', 'application/xml')])
|
|
|
|
elif format == 'ical':
|
|
ical = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//CK Gantt//EN\n"
|
|
for t in tasks:
|
|
if t.gantt_start_date:
|
|
ical += "BEGIN:VEVENT\n"
|
|
ical += f"UID:{t.id}@odoo\n"
|
|
ical += f"DTSTART:{t.gantt_start_date.strftime('%Y%m%d')}T000000Z\n"
|
|
if t.gantt_end_date:
|
|
ical += f"DTEND:{t.gantt_end_date.strftime('%Y%m%d')}T000000Z\n"
|
|
ical += f"SUMMARY:{t.name}\nEND:VEVENT\n"
|
|
ical += "END:VCALENDAR"
|
|
return request.make_response(ical, headers=[('Content-Type', 'text/calendar')])
|
|
|
|
return request.not_found() |