Files
goodie/frontend/crm/static/tests/crm_mock_server.js
Marc 8741282322 Eliminate Python dependency: embed frontend assets in odoo-go
- Copy all OWL frontend assets (JS/CSS/XML/fonts/images) into frontend/
  directory (2925 files, 43MB) — no more runtime reads from Python Odoo
- Replace OdooAddonsPath config with FrontendDir pointing to local frontend/
- Rewire bundle.go, static.go, templates.go, webclient.go to read from
  frontend/ instead of external Python Odoo addons directory
- Auto-detect frontend/ and build/ dirs relative to binary in main.go
- Delete obsolete Python helper scripts (tools/*.py)

The Go server is now fully self-contained: single binary + frontend/ folder.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:09:12 +02:00

71 lines
3.1 KiB
JavaScript

import { onRpc } from "@web/../tests/web_test_helpers";
import { deserializeDateTime } from "@web/core/l10n/dates";
onRpc("get_rainbowman_message", function getRainbowmanMessage({ args, model }) {
let message = false;
if (model !== "crm.lead") {
return message;
}
const records = this.env["crm.lead"];
const record = records.browse(args[0])[0];
const won_stage = this.env["crm.stage"].search_read([["is_won", "=", true]])[0];
if (
record.stage_id === won_stage.id &&
record.user_id &&
record.team_id &&
record.planned_revenue > 0
) {
const now = luxon.DateTime.now();
const query_result = {};
// Total won
query_result["total_won"] = records.filter(
(r) => r.stage_id === won_stage.id && r.user_id === record.user_id
).length;
// Max team 30 days
const recordsTeam30 = records.filter(
(r) =>
r.stage_id === won_stage.id &&
r.team_id === record.team_id &&
(!r.date_closed || now.diff(deserializeDateTime(r.date_closed)).as("days") <= 30)
);
query_result["max_team_30"] = Math.max(...recordsTeam30.map((r) => r.planned_revenue));
// Max team 7 days
const recordsTeam7 = records.filter(
(r) =>
r.stage_id === won_stage.id &&
r.team_id === record.team_id &&
(!r.date_closed || now.diff(deserializeDateTime(r.date_closed)).as("days") <= 7)
);
query_result["max_team_7"] = Math.max(...recordsTeam7.map((r) => r.planned_revenue));
// Max User 30 days
const recordsUser30 = records.filter(
(r) =>
r.stage_id === won_stage.id &&
r.user_id === record.user_id &&
(!r.date_closed || now.diff(deserializeDateTime(r.date_closed)).as("days") <= 30)
);
query_result["max_user_30"] = Math.max(...recordsUser30.map((r) => r.planned_revenue));
// Max User 7 days
const recordsUser7 = records.filter(
(r) =>
r.stage_id === won_stage.id &&
r.user_id === record.user_id &&
(!r.date_closed || now.diff(deserializeDateTime(r.date_closed)).as("days") <= 7)
);
query_result["max_user_7"] = Math.max(...recordsUser7.map((r) => r.planned_revenue));
if (query_result.total_won === 1) {
message = "Go, go, go! Congrats for your first deal.";
} else if (query_result.max_team_30 === record.planned_revenue) {
message = "Boom! Team record for the past 30 days.";
} else if (query_result.max_team_7 === record.planned_revenue) {
message = "Yeah! Best deal out of the last 7 days for the team.";
} else if (query_result.max_user_30 === record.planned_revenue) {
message = "You just beat your personal record for the past 30 days.";
} else if (query_result.max_user_7 === record.planned_revenue) {
message = "You just beat your personal record for the past 7 days.";
}
}
return message;
});