Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat(production): open-ended custom due range in the batch builder
naveenkash2753d5f7e987
diff --git a/.claude/skills/carbon-design/references/tables-and-lists.md b/.claude/skills/carbon-design/references/tables-and-lists.mdindex eeaf2926bb..d4d9e82581 100644--- a/.claude/skills/carbon-design/references/tables-and-lists.md+++ b/.claude/skills/carbon-design/references/tables-and-lists.md@@ -184,7 +184,9 @@ const WidgetsTable = memo(({ data, count }: Props) => {- **Filters:** per column `meta.filter` — `static` options (label may be the cell component,e.g. the Status pill), `fetcher` (endpoint), `custom`, `dateRange` (From / To pickers on aDATE column, `?filter=col:between:from,to`, either side open). Active filters show as chips- under the toolbar. `pluralHeader` for the chip label.+ under the toolbar. `pluralHeader` for the chip label. The From / To pickers themselves are+ `DateRangeFields` (`components/DateRangeFields.tsx`) — reuse it for a date range kept in+ local state rather than the URL (e.g. the batch builder's Custom due filter).- **Sort:** header click menu; `?sort=`; `meta.sortBy` to redirect.- **Views:** `withSavedView` + `table="…"` on every top-level module list; views appear in themodule sub-nav under the matching submodule (same `table` key).diff --git a/apps/erp/app/components/DateRangeFields.tsx b/apps/erp/app/components/DateRangeFields.tsxnew file mode 100644index 0000000000..8abcb3ce3a--- /dev/null+++ b/apps/erp/app/components/DateRangeFields.tsx@@ -0,0 +1,104 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,+// including ports, remain AGPLv3; serving them over a network requires releasing their source.++import { cn, DatePicker } from "@carbon/react";+import type { CalendarDate } from "@internationalized/date";+import { Trans, useLingui } from "@lingui/react/macro";+import { useState } from "react";++export type DateRangeValue = {+ from: CalendarDate | null;+ to: CalendarDate | null;+};++type DateRangeFieldsProps = {+ /** Read once on mount; the fields hold the draft from then on. */+ defaultValue?: DateRangeValue;+ /** Called with every complete range — a From after To is never emitted. */+ onChange: (value: DateRangeValue) => void;+ /** `stacked` for a popover, `inline` for a toolbar. */+ layout?: "stacked" | "inline";+ /** Open the From calendar on mount, for a control the user just picked. */+ autoOpen?: boolean;+ /** Days to flag with a dot in both calendars. */+ isDateMarked?: (date: CalendarDate) => boolean;+ className?: string;+};++/**+ * From / To date pickers. Either side may be left empty for an open-ended+ * range ("on or after" / "on or before"); both bounds are inclusive.+ */+const DateRangeFields = ({+ defaultValue,+ onChange,+ layout = "stacked",+ autoOpen = false,+ isDateMarked,+ className+}: DateRangeFieldsProps) => {+ const { t } = useLingui();+ const [range, setRange] = useState<DateRangeValue>(+ () => defaultValue ?? { from: null, to: null }+ );++ const update = (next: DateRangeValue) => {+ setRange(next);+ // From after To is flagged on the pickers and never reaches the caller+ if (next.from && next.to && next.from.compare(next.to) > 0) return;+ onChange(next);+ };++ const inline = layout === "inline";+ const labelClassName = "text-xs text-muted-foreground";+ const fieldClassName = inline+ ? "flex items-center gap-2"+ : "flex flex-col gap-1";+ const pickerClassName = inline ? "w-[150px]" : undefined;++ return (+ <div+ className={cn(+ inline ? "flex items-center gap-3" : "flex flex-col gap-2",+ className+ )}+ >+ <div className={fieldClassName}>+ <span className={labelClassName}>+ <Trans>From</Trans>+ </span>+ <div className={pickerClassName}>+ <DatePicker+ aria-label={t`From`}+ size="sm"+ closeOnSelect+ defaultOpen={autoOpen}+ value={range.from}+ maxValue={range.to ?? undefined}+ isDateMarked={isDateMarked}+ onChange={(from) => update({ ...range, from })}+ />+ </div>+ </div>+ <div className={fieldClassName}>+ <span className={labelClassName}>+ <Trans>To</Trans>+ </span>+ <div className={pickerClassName}>+ <DatePicker+ aria-label={t`To`}+ size="sm"+ closeOnSelect+ value={range.to}+ minValue={range.from ?? undefined}+ isDateMarked={isDateMarked}+ onChange={(to) => update({ ...range, to })}+ />+ </div>+ </div>+ </div>+ );+};++export default DateRangeFields;diff --git a/apps/erp/app/components/Table/components/Filter/DateRangeFilter.tsx b/apps/erp/app/components/Table/components/Filter/DateRangeFilter.tsxindex cd7da974de..57a5b10ec1 100644--- a/apps/erp/app/components/Table/components/Filter/DateRangeFilter.tsx+++ b/apps/erp/app/components/Table/components/Filter/DateRangeFilter.tsx@@ -2,19 +2,16 @@// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,// including ports, remain AGPLv3; serving them over a network requires releasing their source.-import { DatePicker, useDebounce } from "@carbon/react";+import { useDebounce } from "@carbon/react";import type { CalendarDate } from "@internationalized/date";import { parseDate } from "@internationalized/date";-import { Trans, useLingui } from "@lingui/react/macro";import { useRef, useState } from "react";+import DateRangeFields, {+ type DateRangeValue+} from "~/components/DateRangeFields";import { formatRangeFilter, parseRangeFilter } from "~/utils/query";import { useFilters } from "./useFilters";-type DateRange = {- from: CalendarDate | null;- to: CalendarDate | null;-};-function toCalendarDate(value: string | null): CalendarDate | null {if (!value) return null;try {@@ -28,18 +25,16 @@ type DateRangeFilterProps = {accessorKey: string;};+/** `DateRangeFields` bound to the URL as `?filter=<key>:between:from,to`. */const DateRangeFilter = ({ accessorKey }: DateRangeFilterProps) => {- const { t } = useLingui();const { getFilterValue, removeKey, setFilter } = useFilters();- const [range, setRange] = useState<DateRange>(() => {+ const [defaultValue] = useState<DateRangeValue>(() => {const { from, to } = parseRangeFilter(getFilterValue(accessorKey) ?? "");return { from: toCalendarDate(from), to: toCalendarDate(to) };});- const apply = ({ from, to }: DateRange) => {- // From after To is flagged on the pickers and never reaches the URL- if (from && to && from.compare(to) > 0) return;+ const apply = ({ from, to }: DateRangeValue) => {const value = formatRangeFilter(from?.toString(), to?.toString());// Already what the URL says — closing the popover replays the last changeif (value === getFilterValue(accessorKey)) return;@@ -56,45 +51,13 @@ const DateRangeFilter = ({ accessorKey }: DateRangeFilterProps) => {const applyRef = useRef(apply);applyRef.current = apply;const debouncedApply = useDebounce(- (next: DateRange) => applyRef.current(next),+ (next: DateRangeValue) => applyRef.current(next),400,true);- const onChange = (next: DateRange) => {- setRange(next);- debouncedApply(next);- };-return (- <div className="flex flex-col gap-2">- <div className="flex flex-col gap-1">- <span className="text-xs text-muted-foreground">- <Trans>From</Trans>- </span>- <DatePicker- aria-label={t`From`}- size="sm"- closeOnSelect- value={range.from}- maxValue={range.to ?? undefined}- onChange={(from) => onChange({ ...range, from })}- />- </div>- <div className="flex flex-col gap-1">- <span className="text-xs text-muted-foreground">- <Trans>To</Trans>- </span>- <DatePicker- aria-label={t`To`}- size="sm"- closeOnSelect- value={range.to}- minValue={range.from ?? undefined}- onChange={(to) => onChange({ ...range, to })}- />- </div>- </div>+ <DateRangeFields defaultValue={defaultValue} onChange={debouncedApply} />);};diff --git a/apps/erp/app/modules/production/ui/Batches/BatchBuilder.tsx b/apps/erp/app/modules/production/ui/Batches/BatchBuilder.tsxindex e2d10db4a5..4f6d1cc9eb 100644--- a/apps/erp/app/modules/production/ui/Batches/BatchBuilder.tsx+++ b/apps/erp/app/modules/production/ui/Batches/BatchBuilder.tsx@@ -51,12 +51,10 @@ import {type CalendarDate,getLocalTimeZone,parseDate,- toCalendarDate,today} from "@internationalized/date";import { Trans, useLingui } from "@lingui/react/macro";import { useLocale } from "@react-aria/i18n";-import type { DateRange } from "@react-types/datepicker";import type { ColumnDef } from "@tanstack/react-table";import { useCallback, useEffect, useMemo, useRef, useState } from "react";import {@@ -76,6 +74,9 @@ import {} from "react-icons/lu";import { useFetcher, useNavigate } from "react-router";import { DateSelect, Enumerable, ItemThumbnail, Table } from "~/components";+import DateRangeFields, {+ type DateRangeValue+} from "~/components/DateRangeFields";import { EnumerableGroup } from "~/components/EnumerableGroup";import { path } from "~/utils/path";import type { jobStatus } from "../../production.models";@@ -344,17 +345,13 @@ export function BatchBuilder({const [search, setSearch] = useState("");const [facets, setFacets] = useState<Record<string, string[]>>({});// The due filter as the standard DateSelect holds it: "all", a preset day- // count, or "custom" with the calendar's range.+ // count, or "custom" with a From / To range, either side open.const [dueSelect, setDueSelect] = useState("all");- const [dueRange, setDueRange] = useState<DateRange | null>(null);+ const [dueRange, setDueRange] = useState<DateRangeValue | null>(null);const due = useMemo<DueFilter | null>(() => {if (dueSelect === "custom") {- return dueRange- ? {- kind: "range",- start: toCalendarDate(dueRange.start),- end: toCalendarDate(dueRange.end)- }+ return dueRange && (dueRange.from || dueRange.to)+ ? { kind: "range", start: dueRange.from, end: dueRange.to }: null;}const days = Number(dueSelect);@@ -1627,8 +1624,8 @@ function ComposePanel({dimensions: FacetDimension[];dueSelect: string;onDueSelectChange: (value: string) => void;- dueRange: DateRange | null;- onDueRangeChange: (range: DateRange | null) => void;+ dueRange: DateRangeValue | null;+ onDueRangeChange: (range: DateRangeValue | null) => void;isDueFiltered: boolean;dueDays: Set<string>;suggestions: Suggestion[];@@ -1718,10 +1715,16 @@ function ComposePanel({value={dueSelect}onValueChange={onDueSelectChange}options={dueOptions}- dateRange={dueRange}- onDateRangeChange={onDueRangeChange}- isDateMarked={isDueDay}/>+ {dueSelect === "custom" && (+ <DateRangeFields+ layout="inline"+ autoOpen+ defaultValue={dueRange ?? undefined}+ onChange={onDueRangeChange}+ isDateMarked={isDueDay}+ />+ )}</HStack>{view === "table" && suggestions.length > 0 && (<SuggestionsBannerdiff --git a/apps/erp/app/modules/production/ui/Batches/batch-builder-logic.ts b/apps/erp/app/modules/production/ui/Batches/batch-builder-logic.tsindex c8d16a43ca..a4443c2372 100644--- a/apps/erp/app/modules/production/ui/Batches/batch-builder-logic.ts+++ b/apps/erp/app/modules/production/ui/Batches/batch-builder-logic.ts@@ -461,7 +461,9 @@ export function deriveFacetDimensions(// included) or a calendar range picked day to day, both ends inclusive.export type DueFilter =| { kind: "window"; days: number }- | { kind: "range"; start: CalendarDate; end: CalendarDate };+ // Either bound may be open: no start is "due on or before", no end is+ // "due on or after"+ | { kind: "range"; start: CalendarDate | null; end: CalendarDate | null };// Every distinct day (YYYY-MM-DD) the candidates are due on — the calendar// marks these days so a planner can see where work falls before picking.@@ -504,11 +506,11 @@ export function filterAndSortCandidates();if (!anyLineMatches) return false;}- if (dueEnd) {+ if (dueStart || dueEnd) {const due = dueDateOf(c);if (!due) return false;const dueDay = parseDate(due);- if (dueDay.compare(dueEnd) > 0) return false;+ if (dueEnd && dueDay.compare(dueEnd) > 0) return false;if (dueStart && dueDay.compare(dueStart) < 0) return false;}if (term) {diff --git a/apps/erp/test/batch-suggestions.test.ts b/apps/erp/test/batch-suggestions.test.tsindex 4d17c621dd..55de1f7517 100644--- a/apps/erp/test/batch-suggestions.test.ts+++ b/apps/erp/test/batch-suggestions.test.ts@@ -784,6 +784,24 @@ describe("filterAndSortCandidates due filter", () => {"next-week"]);});++ it("a range with only a start keeps everything due on or after it", () => {+ expect(+ run({ kind: "range", start: parseDate("2026-10-01"), end: null })+ ).toEqual(["thu", "job-due", "next-week"]);+ });++ it("a range with only an end keeps everything due on or before it, overdue included", () => {+ expect(+ run({ kind: "range", start: null, end: parseDate("2026-09-29") })+ ).toEqual(["overdue", "today"]);+ });++ it("an open-ended range still drops undated operations", () => {+ expect(+ run({ kind: "range", start: parseDate("2026-01-01"), end: null })+ ).not.toContain("undated");+ });});describe("dueDatesOf", () => {