Fix invoicing period selfwash counts

This commit is contained in:
Jeppe Bundgaard
2026-07-06 10:33:48 +02:00
parent cf1509e34f
commit 1a1c3db8e5
8 changed files with 86 additions and 22 deletions
@@ -22,7 +22,7 @@ const props = defineProps({
import {computed, ref, watch} from 'vue';
import { departments, getDepartments, getDepartmentName} from "@/components/pagination/departmentTabs.vue";
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import {orderBy, orderDirection, setOrder, loadList} from "@/components/pagination/paginatedList.vue";
import { usePaginatedListInstance } from "@/components/pagination/paginatedList.vue";
import ActionSettingsWheelItem from "@/components/displays/buttons/ActionSettingsWheelItem.vue";
import Swal from "sweetalert2";
import ActionSettingsWheelItemLabel from "@/components/displays/buttons/ActionSettingsWheelItemLabel.vue";
@@ -38,6 +38,8 @@ import {
setCachedXlvaskUsageAmount
} from "@/components/displays/department/pos/sync/xlvaskUsageAmountCache.js";
const { orderBy, orderDirection, setOrder, loadList } = usePaginatedListInstance();
const redirectDepartmentOrderPage = (orderId, departmentId) => {
// Send the user to the order page (In a new tab)
// `/admin/${departmentId}/modules/pos/orders/${orderId}`
@@ -0,0 +1 @@
export const SELFWASH_PERIOD_ALL_LIMIT = 10000;
@@ -21,9 +21,31 @@ const props = defineProps({
type: Number, default: 0
}
})
import {computed, ref, watch } from "vue";
import {computed, provide, ref, watch } from "vue";
import { useRouter } from "vue-router";
import {
PaginatedListKey,
usePaginatedList,
} from "@/components/pagination/paginatedList.vue";
import PaginationNavigation from "@/components/displays/pagination/PaginationNavigation.vue";
import LoadButtonWhileAwait from "@/components/request/LoadButtonWhileAwait.vue";
import PaginationDisplay from "@/components/displays/pagination/PaginationDisplay.vue";
import XlvaskUsageOrdersTable from "@/components/displays/department/pos/sync/xlvaskUsageOrdersTable.vue";
import PaginationDisplayTemplateDates
from "@/components/displays/pagination/templates/PaginationDisplayTemplateDates.vue";
import ShowErrorField from "@/components/global/ShowErrorField.vue";
import { useI18n } from 'vue-i18n'
import { BSwitch } from "buefy";
import { isUsageOrderAttachedToOrder } from "@/components/displays/department/pos/sync/xlvaskUsageFilters.js";
import { SELFWASH_PERIOD_ALL_LIMIT } from "@/components/displays/department/pos/sync/xlvaskUsagePeriodConstants.js";
const { t } = useI18n()
const router = useRouter();
const paginatedList = usePaginatedList();
provide(PaginatedListKey, paginatedList);
const {
isLoading,
list,
loadList,
@@ -38,22 +60,8 @@ import {
setOrder,
hideSearchField,
setHideSearchField,
} from "@/components/pagination/paginatedList.vue";
import PaginationNavigation from "@/components/displays/pagination/PaginationNavigation.vue";
} = paginatedList;
import LoadButtonWhileAwait from "@/components/request/LoadButtonWhileAwait.vue";
import PaginationDisplay from "@/components/displays/pagination/PaginationDisplay.vue";
import XlvaskUsageOrdersTable from "@/components/displays/department/pos/sync/xlvaskUsageOrdersTable.vue";
import PaginationDisplayTemplateDates
from "@/components/displays/pagination/templates/PaginationDisplayTemplateDates.vue";
import ShowErrorField from "@/components/global/ShowErrorField.vue";
import { useI18n } from 'vue-i18n'
import { BSwitch } from "buefy";
import { isUsageOrderAttachedToOrder } from "@/components/displays/department/pos/sync/xlvaskUsageFilters.js";
const { t } = useI18n()
const router = useRouter();
const SELFWASH_PERIOD_ALL_LIMIT = 10000;
setEndpoint("/modules/xlvask/services/usage/orders", false);
if (props.loadAllAtOnce) {
setMetaItemsPerPage(SELFWASH_PERIOD_ALL_LIMIT, false);
@@ -23,6 +23,7 @@ import {
} from "../../imports/InvoicingBillingPeriodImportPaging.js";
import { buildPossibleDuplicateGroups } from "../../utils/possibleDuplicateGroups.js";
import { isUsageOrderAttachedToOrder } from "@/components/displays/department/pos/sync/xlvaskUsageFilters.js";
import { SELFWASH_PERIOD_ALL_LIMIT } from "@/components/displays/department/pos/sync/xlvaskUsagePeriodConstants.js";
const period_result = ref<any>(null);
const route = useRoute();
@@ -416,7 +417,7 @@ const loadSelfWashCounts = async ({ forceRefresh = false } = {}) => {
'GET',
{
page: 1,
limit: 500,
limit: SELFWASH_PERIOD_ALL_LIMIT,
filters,
order: 'StartTime:desc',
},
@@ -4,7 +4,7 @@ export const PERIOD_CACHE_TTL_MS = 10 * 60 * 1000;
export const PERIOD_LIMIT_OPTIONS = [10, 25, 50, 100, 200, 500, "all"];
const CACHE_PREFIX = "invoicing-period-page:v2:";
const SELF_WASH_COUNTS_CACHE_PREFIX = "invoicing-period-self-wash-counts:";
const SELF_WASH_COUNTS_CACHE_PREFIX = "invoicing-period-self-wash-counts:v2:";
const DEFAULT_LIMIT = 100;
const ALL_LIMIT = "all";
+4 -2
View File
@@ -1132,7 +1132,6 @@ test.describe("Invoicing period tab", () => {
};
await openPeriodView(page);
await setEntireMarchPeriod(page);
await page.route("**/modules/xlvask/services/usage/orders**", async (route) => {
const path = new URL(route.request().url()).pathname;
@@ -1242,8 +1241,10 @@ test.describe("Invoicing period tab", () => {
);
});
await setEntireMarchPeriod(page);
await expect(page.getByTestId("invoicing-period-view-selector-self_wash")).toBeVisible();
await expect(page.getByTestId("invoicing-period-view-selector-self_wash")).toContainText("Selvvask (0/1)");
await expect(page.getByTestId("invoicing-period-view-selector-self_wash")).toContainText("Selvvask (0/2)");
await expect(page.getByTestId("invoicing-period-view-selector-progress-self_wash")).toBeVisible();
await page.getByTestId("invoicing-period-view-selector-self_wash").click();
@@ -1273,6 +1274,7 @@ test.describe("Invoicing period tab", () => {
await page.getByTestId("xlvask-automation-accept-8101").click();
await expect(page.getByTestId("xlvask-automation-suggestion-8101")).toContainText("Accepteret #7001");
expect(automationAcceptRequests).toEqual([{ suggestion_id: 7101 }]);
await expect(page.getByTestId("invoicing-period-view-selector-self_wash")).toContainText("Selvvask (1/2)");
await expect.poll(() => usageOrderRequests.length).toBeGreaterThan(0);
expect(usageOrderRequests.some((request) => request.limit === "10000")).toBe(true);
@@ -755,6 +755,42 @@ describe("Invoicing period queue-driven refresh", () => {
expect(selfWashCalls()).toHaveLength(1);
});
it("loads Selvvask selector counts with the full selected-period limit", async () => {
requestMock.mockImplementation((url) => {
if (url === "/superuser/invoicing/period") {
return Promise.resolve(emptyPeriodResponse());
}
return Promise.resolve(
selfWashResponse(
[
{ id: 8101, linked_order_id: 7001 },
{
id: 8102,
linked_order_id: null,
automation: {
status: "accepted",
action: "attach_order",
},
},
{ id: 8103, linked_order_id: null },
],
3
)
);
});
const wrapper = mountRight();
await flushAll();
expect(wrapper.get("[data-testid='invoicing-period-view-selector-self_wash']").text()).toContain("Selvvask (2/3)");
expect(selfWashCalls()[0][2]).toMatchObject({
limit: 10000,
filters: "StartTime-date_from:2026-04-01,StartTime-date_to:2026-04-30",
order: "StartTime:desc",
});
});
it("ignores stale period responses that resolve after a newer search request", async () => {
const deferred = [];
requestMock.mockImplementation((url) => {
+15 -1
View File
@@ -100,6 +100,10 @@ const xlvaskUsagePaginationSource = readFileSync(
join(root, "src/components/displays/pagination/models/DepartmentPos/XLVaskUsagePagination.vue"),
"utf8"
);
const xlvaskUsagePeriodConstantsSource = readFileSync(
join(root, "src/components/displays/department/pos/sync/xlvaskUsagePeriodConstants.js"),
"utf8"
);
const xlvaskUsageOrdersTableSource = readFileSync(
join(root, "src/components/displays/department/pos/sync/xlvaskUsageOrdersTable.vue"),
"utf8"
@@ -477,7 +481,7 @@ describe("Periode tab contract", () => {
expect(periodViewSelfWashSource).toContain(':load-all-at-once="true"');
expect(xlvaskUsagePaginationSource).toContain("inheritPeriodFilters");
expect(xlvaskUsagePaginationSource).toContain("loadAllAtOnce");
expect(xlvaskUsagePaginationSource).toContain("const SELFWASH_PERIOD_ALL_LIMIT = 10000");
expect(xlvaskUsagePeriodConstantsSource).toContain("export const SELFWASH_PERIOD_ALL_LIMIT = 10000");
expect(xlvaskUsagePaginationSource).toContain("setMetaItemsPerPage(SELFWASH_PERIOD_ALL_LIMIT, false)");
expect(xlvaskUsagePaginationSource).toContain(
"const shouldShowLocalFilters = computed(() => !props.inheritPeriodFilters)"
@@ -494,6 +498,7 @@ describe("Periode tab contract", () => {
expect(periodRightSource).toContain("getCachedSelfWashCounts");
expect(periodRightSource).toContain("setCachedSelfWashCounts");
expect(periodRightSource).toContain("'/modules/xlvask/services/usage/orders'");
expect(periodRightSource).toContain("limit: SELFWASH_PERIOD_ALL_LIMIT");
expect(periodRightSource).toContain("StartTime-date_from:${dates.computed.formattedStartDate.value}");
expect(periodRightSource).toContain("StartTime-date_to:${dates.computed.formattedEndDate.value}");
expect(periodRightSource).toContain("if (type.name === 'self_wash')");
@@ -502,6 +507,15 @@ describe("Periode tab contract", () => {
expect(periodRightSource).not.toContain("showProgress: false");
});
it("keeps Selvvask usage pagination scoped to the period view", () => {
expect(xlvaskUsagePaginationSource).toContain("usePaginatedList");
expect(xlvaskUsagePaginationSource).toContain("provide(PaginatedListKey, paginatedList)");
expect(xlvaskUsageOrdersTableSource).toContain("usePaginatedListInstance");
expect(xlvaskUsageOrdersTableSource).toContain(
"const { orderBy, orderDirection, setOrder, loadList } = usePaginatedListInstance();"
);
});
it("keeps Selvvask usage entries wrapped inside the period content area", () => {
expect(xlvaskUsageOrdersTableSource).toContain("xlvask-usage-card-primary");
expect(xlvaskUsageOrdersTableSource).toContain("xlvask-usage-card-status");