mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-18 20:42:05 +02:00
Initial commit: Report packages
This commit is contained in:
commit
bc5e1e9efa
604 changed files with 474102 additions and 0 deletions
|
|
@ -0,0 +1,52 @@
|
|||
/** @odoo-module */
|
||||
|
||||
const { DateTime } = luxon;
|
||||
import { Domain } from "@web/core/domain";
|
||||
|
||||
function getDateDomainBounds(domain) {
|
||||
const startDateStr = domain[1][2];
|
||||
const endDateStr = domain[2][2];
|
||||
|
||||
const isDateTime = startDateStr.includes(":");
|
||||
|
||||
if (isDateTime) {
|
||||
const dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
const start = DateTime.fromFormat(startDateStr, dateTimeFormat);
|
||||
const end = DateTime.fromFormat(endDateStr, dateTimeFormat);
|
||||
return { start, end };
|
||||
}
|
||||
|
||||
const start = DateTime.fromISO(startDateStr);
|
||||
const end = DateTime.fromISO(endDateStr);
|
||||
const startIsIncluded = domain[1][1] === ">=";
|
||||
const endIsIncluded = domain[2][1] === "<=";
|
||||
return {
|
||||
start: startIsIncluded ? start.startOf("day") : start.endOf("day"),
|
||||
end: endIsIncluded ? end.endOf("day") : end.startOf("day"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} assert
|
||||
* @param {string} field
|
||||
* @param {string} start
|
||||
* @param {string} end
|
||||
* @param {import("@web/core/domain").DomainRepr} domain
|
||||
*/
|
||||
export function assertDateDomainEqual(assert, field, start, end, domain) {
|
||||
domain = new Domain(domain).toList();
|
||||
assert.deepEqual(domain[0], "&");
|
||||
assert.deepEqual(domain[1], [field, ">=", start]);
|
||||
assert.deepEqual(domain[2], [field, "<=", end]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("@web/core/domain").DomainRepr} domain
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getDateDomainDurationInDays(domain) {
|
||||
domain = new Domain(domain).toList();
|
||||
const bounds = getDateDomainBounds(domain);
|
||||
const diff = bounds.end.diff(bounds.start, ["days"]);
|
||||
return Math.round(diff.days);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue