feat(automation): separate lot number counters per raw material kind
With {ART} in the raw material number format (default {ART}-{YYYY}-{SEQ:4}),
beeswax and propolis each count on their own: WA-2026-0001, PR-2026-0001.
Counters live in the new AutomationSequence table (one row per rule and
scope). Without {ART} the rule keeps its single shared counter, since
separate counters behind one prefix would hand out duplicate numbers.
Resetting a rule clears all of its counters.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
5408711b2d
commit
cfd3a187af
9 files changed
+252
-24
No files matched your search
@@ -9,13 +9,22 @@
|
||||
// every keystroke and freeze the settings page.
|
||||
const MAX_SEQUENCE_PAD_WIDTH = 20;
|
||||
|
||||
export function formatGeneratedNumber(format: string, sequence: number, date: Date): string {
|
||||
export function formatGeneratedNumber(
|
||||
format: string,
|
||||
sequence: number,
|
||||
date: Date,
|
||||
vars: Record<string, string> = {},
|
||||
): string {
|
||||
const yyyy = String(date.getFullYear());
|
||||
const yy = yyyy.slice(-2);
|
||||
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const dd = String(date.getDate()).padStart(2, "0");
|
||||
|
||||
return format
|
||||
const withVars = Object.entries(vars).reduce(
|
||||
(result, [key, value]) => result.split(`{${key}}`).join(value),
|
||||
format,
|
||||
);
|
||||
return withVars
|
||||
.replace(/\{YYYY\}/g, yyyy)
|
||||
.replace(/\{YY\}/g, yy)
|
||||
.replace(/\{MM\}/g, mm)
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface AutomationRule {
|
||||
config: Record<string, unknown> | null;
|
||||
actionTemplate: string | null;
|
||||
sequenceValue: number;
|
||||
/** Separate counters per scope, e.g. per raw material kind ({ART}). */
|
||||
sequences?: { scope: string; value: number }[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user