Files
Odoo-Modules/fusion_accounting/static/src/components/dashboard/fusion_dashboard.js
gsinghpal 3cc93b8783 changes
2026-04-04 15:37:16 -04:00

109 lines
4.1 KiB
JavaScript

/** @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 onAttentionClick(domain, prompt) {
// Type the prompt into the chat input and send
if (!prompt) return;
const textarea = this.el?.querySelector('.fusion_chat_input textarea');
if (textarea) {
// Set value and trigger OWL's model update via input event
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLTextAreaElement.prototype, 'value'
).set;
nativeInputValueSetter.call(textarea, prompt);
textarea.dispatchEvent(new Event('input', { bubbles: true }));
// Click send button
setTimeout(() => {
const sendBtn = this.el?.querySelector('.fusion_chat_input .btn-primary');
if (sendBtn) sendBtn.click();
}, 50);
}
}
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).toLocaleString('en-CA', {minimumFractionDigits: 0})} total`,
domain: "bank_reconciliation",
status: d.bank_recon.count === 0 ? "green" : d.bank_recon.count < 10 ? "yellow" : "red",
},
{
title: "AR Outstanding",
metric: `$${Math.abs(d.ar.total || 0).toLocaleString('en-CA', {minimumFractionDigits: 0})}`,
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).toLocaleString('en-CA', {minimumFractionDigits: 0})}`,
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).toLocaleString('en-CA', {minimumFractionDigits: 0})}`,
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);