changes
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
// Sub 12 Phase D — Unified Quality Dashboard.
|
||||
// Five tabs (Holds / Checks / NCRs / CAPAs / RMAs) backed by their list
|
||||
// kanbans, with a header summary card showing open + overdue counts.
|
||||
// Each tab embeds the corresponding model's kanban via an action service
|
||||
// switch. The header counters refresh on tab switch and on a 60-second
|
||||
// poll.
|
||||
|
||||
import { Component, useState, onWillStart, onMounted, onWillUnmount } from "@odoo/owl";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
|
||||
const TABS = [
|
||||
{ id: "holds", label: "Holds", model: "fusion.plating.quality.hold", group: "state", domain: [["state", "in", ["on_hold", "under_review"]]] },
|
||||
{ id: "checks", label: "Checks", model: "fusion.plating.quality.check", group: "state", domain: [] },
|
||||
{ id: "ncrs", label: "NCRs", model: "fusion.plating.ncr", group: "stage_id", domain: [["state", "!=", "closed"]] },
|
||||
{ id: "capas", label: "CAPAs", model: "fusion.plating.capa", group: "state", domain: [["state", "not in", ["closed", "effective"]]] },
|
||||
{ id: "rmas", label: "RMAs", model: "fusion.plating.rma", group: "stage_id", domain: [["state", "not in", ["closed", "cancelled"]]] },
|
||||
];
|
||||
|
||||
export class FpQualityDashboard extends Component {
|
||||
static template = "fusion_plating_quality.FpQualityDashboard";
|
||||
static props = ["*"];
|
||||
|
||||
setup() {
|
||||
this.action = useService("action");
|
||||
this.state = useState({
|
||||
activeTab: "ncrs",
|
||||
counts: TABS.reduce((acc, t) => ({ ...acc, [t.id]: { open: 0, overdue: 0 } }), {}),
|
||||
});
|
||||
|
||||
onWillStart(async () => {
|
||||
await this._refreshCounts();
|
||||
});
|
||||
onMounted(() => {
|
||||
this._poll = setInterval(() => this._refreshCounts(), 60000);
|
||||
});
|
||||
onWillUnmount(() => {
|
||||
if (this._poll) clearInterval(this._poll);
|
||||
});
|
||||
}
|
||||
|
||||
async _refreshCounts() {
|
||||
try {
|
||||
const result = await rpc("/fp/quality/dashboard/counts");
|
||||
if (result && typeof result === "object") {
|
||||
for (const tab of TABS) {
|
||||
if (result[tab.id]) {
|
||||
this.state.counts[tab.id] = result[tab.id];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Best-effort; leave counts at zero on RPC failure.
|
||||
console.warn("FpQualityDashboard: count refresh failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
selectTab(id) {
|
||||
this.state.activeTab = id;
|
||||
}
|
||||
|
||||
async openTab(tab) {
|
||||
// Open the model's full kanban view in the main app area.
|
||||
await this.action.doAction({
|
||||
type: "ir.actions.act_window",
|
||||
name: tab.label,
|
||||
res_model: tab.model,
|
||||
view_mode: "kanban,list,form",
|
||||
views: [[false, "kanban"], [false, "list"], [false, "form"]],
|
||||
domain: tab.domain,
|
||||
context: { group_by: tab.group },
|
||||
});
|
||||
}
|
||||
|
||||
get tabs() {
|
||||
return TABS;
|
||||
}
|
||||
|
||||
get totalOpen() {
|
||||
return TABS.reduce(
|
||||
(sum, t) => sum + (this.state.counts[t.id]?.open || 0), 0,
|
||||
);
|
||||
}
|
||||
|
||||
get totalOverdue() {
|
||||
return TABS.reduce(
|
||||
(sum, t) => sum + (this.state.counts[t.id]?.overdue || 0), 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("actions").add("fp_quality_dashboard", FpQualityDashboard);
|
||||
Reference in New Issue
Block a user