Work with no assignment goes to the primary one
The rule
A person can hold several assignments at once: two stores, a job and a
second job, two customers of a staffing firm. When a punch names none and
no shift or work code says which, the engine does not guess: the work is an
assignment_ambiguous exception, waiting for someone to say. Many employers
have a rule instead: such work is the person’s primary (home) assignment,
or the first of an order of preference.
Who uses it
Retail and restaurant chains with people working at several locations, staffing firms with workers on more than one placement, public employers with secondary jobs. The home assignment is usually on the person’s record already, as an employment attribute.
How the recipe does it
Configuration only: a package (package.toml) of one layer running the
standard assign step, in the assign stage.
[[layer]]id = "assignment"[[layer.step]]id = "primary"uses = "standard/assign"params = { attribute = "primary_assignment" } # or prefer = ["A15", "A12"]The assign stage runs on each workday’s work that several active
assignments fit with nothing saying which: its segments (ctx.segments,
each with candidates: the assignments that fit, and its context so far)
and, once the lines are made, its labor entries and days of leave
(ctx.entries: each id, kind “entry” or “leave”, about, workday,
context, candidates). Its step calls ctx:assign(id, assignment, why).
The engine resolves the work’s context again with that assignment (its
defaults, its allowed values), says where it came from (step:primary),
and stamps the line. Work the step chooses nothing for stays an exception.
One rule decides everywhere the assignment is not said.
Parameters
| Parameter | Meaning |
|---|---|
prefer | Assignment ids in order: the first that fits. |
attribute | The employment attribute naming the person’s primary assignment, used when prefer gives none that fits. |
What the scenarios show
the-primary-assignment: work naming nothing goes to the primary assignment, with its defaults, stamped; work naming one keeps it.a-preference-that-does-not-fit: a company preferring the warehouse assignment (its layer setsprefer): the preferred assignment while it is active; after it ends, the one left is the work’s anyway.entries-and-leave-too: hours of training entered and a day of vacation, naming no assignment, go to the primary one too.
Legal note
This is a common way companies put unassigned work on an assignment; check the rules where you operate. Where assignments pay differently, the work must be paid at the rate of the work actually done.
Get the recipe
The recipe’s package and its scenarios are in the example packages repository: attendance/primary_assignment. Test it, or your own copy of it, with hourctl attend test, and publish it with hourctl attend pkg publish.
The policy package
The package’s layers, with the standard steps each one runs and their settings:
name = "primary_assignment"version = "1.0.0"description = "A person with several assignments who punches without naming one has the work put on their primary assignment, instead of an exception for each shift."
# Work that several assignments fit, naming none, goes to the person's# primary assignment, named by their employment attribute# primary_assignment.[[layer]]id = "assignment"[[layer.step]]id = "primary"uses = "standard/assign"params = { attribute = "primary_assignment" }Scenarios
Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).
The policy prefers the warehouse assignment (A15), which ends on Tuesday. Monday's work, which both fit, goes to A15. On Wednesday only the store assignment is active: nothing is ambiguous, and the work takes it as the only one.
description = "The policy prefers the warehouse assignment (A15), which ends on Tuesday. Monday's work, which both fit, goes to A15. On Wednesday only the store assignment is active: nothing is ambiguous, and the work takes it as the only one."
punch = [ { at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" }, { at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 16:00", kind = "out" },]
[policy]zone = "America/Chicago"
# A company that prefers the warehouse assignment, then the store.[[layer]]id = "prefer-warehouse"[[layer.step]]id = "primary"change = "params"params = { prefer = ["A15", "A12"] }
[[assignment]]id = "A12"
[[assignment]]id = "A15"to = "2026-10-06"
[expect]week = "2026-10-05"allocations = [ "2026-10-05 08:00-16:00 work 8.00 assignment=A15", "2026-10-07 08:00-16:00 work 8.00 assignment=A12",]The same rule wherever the assignment is not said: 3 hours of training entered for Tuesday and a day of vacation on Wednesday, neither naming an assignment, go to the primary one, A12, with its defaults, stamped. Without the step each would be assignment_ambiguous
description = "The same rule wherever the assignment is not said: 3 hours of training entered for Tuesday and a day of vacation on Wednesday, neither naming an assignment, go to the primary one, A12, with its defaults, stamped. Without the step each would be assignment_ambiguous"
[policy]zone = "America/Chicago"
[[employment]]effective = "2026-01-05"kind = "hired"attributes = { primary_assignment = "A12" }
[[assignment]]id = "A12"defaults = { cost_center = "store" }
[[assignment]]id = "A15"defaults = { cost_center = "warehouse" }
[[measure]]id = "hours"kind = "duration"
[[category]]id = "vacation"worked = false
[[labor]]workday = "2026-10-06"measure = "hours"quantity = "3h"category = "training"
[[leave]]id = "v1"category = "vacation"days = { "2026-10-07" = "8h" }
[[approval]]subject = "leave:v1:2026-10-07"stage = "approval"decision = "approve"recorded = "2026-10-07 00:00"
[expect]week = "2026-10-05"allocations = [ "2026-10-06 untimed training 3.00 assignment=A12 cost_center=store", "2026-10-07 untimed vacation 8.00 assignment=A12 cost_center=store",]stamps = [ "2026-10-06 00:00-03:00 training: primary [[email protected]/assignment rev 1]: assigned to A12: preferred of those that fit", "2026-10-07 00:00-08:00 vacation: primary [[email protected]/assignment rev 1]: assigned to A12: preferred of those that fit",]The person works two assignments, a store (A12) and a warehouse (A15), and punches without saying which. The engine will not guess: each segment is assignment_ambiguous. The policy sends work that says nothing to the assignment the person's employment names as primary, A12: no exception, each segment stamped with why. Thursday's punch says A15, and keeps it
description = "The person works two assignments, a store (A12) and a warehouse (A15), and punches without saying which. The engine will not guess: each segment is assignment_ambiguous. The policy sends work that says nothing to the assignment the person's employment names as primary, A12: no exception, each segment stamped with why. Thursday's punch says A15, and keeps it"
punch = [ { at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" }, { at = "2026-10-08 08:00", kind = "in", values = { assignment = "A15" } }, { at = "2026-10-08 12:00", kind = "out" },]
[policy]zone = "America/Chicago"
[[employment]]effective = "2026-01-05"kind = "hired"attributes = { primary_assignment = "A12" }
[[assignment]]id = "A12"defaults = { cost_center = "store" }
[[assignment]]id = "A15"defaults = { cost_center = "warehouse" }
[expect]week = "2026-10-05"allocations = [ "2026-10-05 08:00-16:00 work 8.00 assignment=A12 cost_center=store", "2026-10-08 08:00-12:00 work 4.00 assignment=A15 cost_center=warehouse",]stamps = ["2026-10-05 08:00-16:00 work: primary [[email protected]/assignment rev 1]: assigned to A12: preferred of those that fit"]