""" Odoo file export. Odoo integration is still in development on your end, so for now we generate a CSV of orders that fits your import template. This is a placeholder column layout - once you know the exact columns your Odoo import template expects, update ODOO_EXPORT_COLUMNS below (or tell me and I'll adjust it) and the export will follow automatically. When live Odoo API access is ready, this file is where an OdooService(OrderService)-style push would go instead/alongside. """ from __future__ import annotations import csv from pathlib import Path from typing import List from app.models import Order # (header label, function to get the value from an Order) ODOO_EXPORT_COLUMNS = [ ("Order Reference", lambda o: o.ticket_number or o.external_id), ("Company", lambda o: o.company), ("Source", lambda o: o.source), ("SKUs", lambda o: ", ".join(o.skus or [])), ("Status", lambda o: o.status), ("Summary", lambda o: o.summary), ("Source Created At", lambda o: o.source_created_at.isoformat() if o.source_created_at else ""), ] def export_orders_to_csv(orders: List[Order], filepath: str) -> int: """Write orders to a CSV file. Returns the number of rows written.""" path = Path(filepath) path.parent.mkdir(parents=True, exist_ok=True) with path.open("w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow([label for label, _ in ODOO_EXPORT_COLUMNS]) for order in orders: writer.writerow([getter(order) for _, getter in ODOO_EXPORT_COLUMNS]) return len(orders)