19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:27 +01:00
parent d1963a3c3a
commit 2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions

View file

@ -0,0 +1,5 @@
import { onRpc } from "@web/../tests/web_test_helpers";
onRpc("/bus/has_missed_notifications", function hasMissedNotifications() {
return false;
});

View file

@ -0,0 +1,12 @@
declare module "mock_models" {
import { BusBus as BusBus2 } from "@bus/../tests/mock_server/mock_models/bus_bus";
import { IrWebSocket as IrWebSocket2 } from "@bus/../tests/mock_server/mock_models/ir_websocket";
export interface BusBus extends BusBus2 {}
export interface IrWebSocket extends IrWebSocket2 {}
export interface Models {
"bus.bus": BusBus,
"ir.websocket": IrWebSocket,
}
}

View file

@ -0,0 +1,75 @@
import { getWebSocketWorker } from "@bus/../tests/mock_websocket";
import { models } from "@web/../tests/web_test_helpers";
export class BusBus extends models.Model {
_name = "bus.bus";
/** @type {Record<number, string[]>} */
channelsByUser = {};
lastBusNotificationId = 0;
/**
* @param {models.Model | string} channel
* @param {string} notificationType
* @param {any} message
*/
_sendone(channel, notificationType, message) {
this._sendmany([[channel, notificationType, message]]);
}
/** @param {[models.Model | string, string, any][]} notifications */
_sendmany(notifications) {
/** @type {import("mock_models").IrWebSocket} */
const IrWebSocket = this.env["ir.websocket"];
if (!notifications.length) {
return;
}
const values = [];
const authenticatedUserId =
"res.users" in this.env
? this.env.cookie.get("authenticated_user_sid") ?? this.env.uid
: null;
const channels = [
...IrWebSocket._build_bus_channel_list(this.channelsByUser[authenticatedUserId] || []),
];
notifications = notifications.filter(([target]) =>
channels.some((channel) => {
if (typeof target === "string") {
return channel === target;
}
if (Array.isArray(target) && Array.isArray(channel)) {
const [target0, target1] = target;
const [channel0, channel1] = channel;
return (
channel0?._name === target0?.model &&
channel0?.id === target0?.id &&
channel1 === target1
);
}
return channel?._name === target?.model && channel?.id === target?.id;
})
);
if (notifications.length === 0) {
return;
}
for (const notification of notifications) {
const [type, payload] = notification.slice(1, notification.length);
values.push({
id: ++this.lastBusNotificationId,
message: { payload: JSON.parse(JSON.stringify(payload)), type },
});
}
getWebSocketWorker().broadcast("BUS:NOTIFICATION", values);
}
/**
* Close the current websocket with the given reason and code.
*
* @param {number} closeCode the code to close the connection with.
* @param {string} [reason] the reason to close the connection with.
*/
_simulateDisconnection(closeCode, reason) {
getWebSocketWorker().websocket.close(closeCode, reason);
}
}

View file

@ -0,0 +1,32 @@
import { makeKwArgs, models } from "@web/../tests/web_test_helpers";
export class IrWebSocket extends models.ServerModel {
_name = "ir.websocket";
/**
* @param {number} inactivityPeriod
*/
_update_presence(inactivityPeriod) {}
/**
* @returns {string[]}
*/
_build_bus_channel_list(channels = []) {
/** @type {import("mock_models").ResPartner} */
const ResPartner = this.env["res.partner"];
channels = [...channels];
channels.push("broadcast");
const authenticatedUserId = this.env.cookie.get("authenticated_user_sid");
const [authenticatedPartner] = authenticatedUserId
? ResPartner.search_read(
[["user_ids", "in", [authenticatedUserId]]],
makeKwArgs({ context: { active_test: false } })
)
: [];
if (authenticatedPartner) {
channels.push(authenticatedPartner);
}
return channels;
}
}