/** @odoo-module **/ import { Component, useState, onWillStart } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { useService } from "@web/core/utils/hooks"; import { rpc } from "@web/core/network/rpc"; import { FusionHealthCard } from "./health_card"; import { FusionChatPanel } from "../chat/chat_panel"; export class FusionDashboard extends Component { static template = "fusion_accounting.Dashboard"; static components = { FusionHealthCard, FusionChatPanel }; static props = ["*"]; setup() { this.action = useService("action"); this.state = useState({ data: null, loading: true, chatSessionId: null, }); onWillStart(async () => { await this.loadDashboard(); }); } async loadDashboard() { this.state.loading = true; try { this.state.data = await rpc("/fusion_accounting/dashboard/data"); } catch (e) { console.error("Dashboard load error:", e); this.state.data = null; } this.state.loading = false; } async onCardClick(domain) { if (!this.state.chatSessionId) { const session = await rpc("/fusion_accounting/session/create", { context_domain: domain, }); this.state.chatSessionId = session.session_id; } } get cards() { if (!this.state.data) return []; const d = this.state.data; return [ { title: "Bank Reconciliation", metric: `${d.bank_recon.count} unmatched`, subtext: `$${(d.bank_recon.amount || 0).toFixed(2)} total`, domain: "bank_reconciliation", status: d.bank_recon.count === 0 ? "green" : d.bank_recon.count < 10 ? "yellow" : "red", }, { title: "AR Outstanding", metric: `$${(d.ar.total || 0).toFixed(2)}`, subtext: `${d.ar.overdue_count} overdue`, domain: "accounts_receivable", status: d.ar.overdue_count === 0 ? "green" : d.ar.overdue_count < 5 ? "yellow" : "red", }, { title: "AP Due", metric: `$${(d.ap.total || 0).toFixed(2)}`, subtext: `${d.ap.due_this_week} due this week`, domain: "accounts_payable", status: d.ap.due_this_week === 0 ? "green" : "yellow", }, { title: "HST Balance", metric: `$${(d.hst.balance || 0).toFixed(2)}`, subtext: d.hst.balance > 0 ? "Owing to CRA" : "Refund expected", domain: "hst_management", status: "blue", }, { title: "Audit Score", metric: `${d.audit.score}/100`, subtext: `${d.audit.flags} flags`, domain: "audit", status: d.audit.score >= 80 ? "green" : d.audit.score >= 60 ? "yellow" : "red", }, { title: "Month-End", metric: d.month_end.status, subtext: `${d.month_end.open_items} open items`, domain: "month_end", status: d.month_end.open_items === 0 ? "green" : "yellow", }, ]; } } registry.category("actions").add("fusion_accounting.dashboard", FusionDashboard);