Skip to content

fix(sales): refuse a sales order dated after the farm's today - #1344

Merged
mforce merged 2 commits into
mainfrom
fix/1333-sales-order-future-date
Oct 21, 2026
Merged

mforce merged 2 commits into
mainfrom
fix/1333-sales-order-future-date

Conversation

@mforce

@mforce mforce commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closes #1333

Why

The API accepted a sales order dated in the future. CreateSalesOrderValidator checked only that OrderDate was set. The web form caps the date at today, but a direct POST /api/v1/sales skipped that cap. Payments, expenses, daily entries and the other dated records already refuse a date after the farm's today.

What changed

  • CreateSalesOrderValidator takes IFarmClock and adds the payment validator's two rules: SalesOrder.OrderDate.NotFuture (after the farm's today) and SalesOrder.OrderDate.NotTooOld (before 2000-01-01). The existing SalesOrder.OrderDate.Required stays first, and Cascade(Stop) keeps an omitted date at that one error.
  • Help ("today" list, en/es/tl) and the GLOSSARY "Operational day" entry now name orders among the records that cannot be dated in the future.
  • The k6 bundles.js script dated its orders with UTC today, which is the sim farm's tomorrow for part of each day (the farm is in America/Chicago). It now uses daysAgo(1), like the daily-entry write. I did not run the k6 scenario; its date-helper test passes.

SalesOrder.OrderDate is set only in SalesOrder.Create, and the REST endpoint is the only caller that takes a date from outside. The MCP commerce tools only read orders. The demo and simulation seeders call the module directly and skip the validator. Demo orders use the farm's today and yesterday; simulation orders use the seed's UTC anchor minus at least two days.

Verification

  • The repro commit lands first. FarmLocalBoundaryBehindUtcTests freezes UTC at 2026-07-16 01:00 with a farm in America/Los_Angeles, so the farm's tomorrow is UTC's today. On the old code, posting that date returned Created:
    Failed FarmLocalBoundaryBehindUtcTests.SalesOrder_DatedTheFarmsTomorrow_IsRefused [5 s]
    Expected: BadRequest
    Actual:   Created
    
    With the fix it returns 400 with SalesOrder.OrderDate.NotFuture, and the farm's today still returns 201.
  • FarmLocalDateRuleTests gains the today-passes / tomorrow-fails pair. Making the rule accept tomorrow turns SalesOrderDated_AfterFarmToday_Fails red.
  • A filtered integration run over 20 classes passed 282 tests, including the new future-date refusal. No existing order-creation test needed a change. ValidatorErrorCodeCoverageTests passes (44/44).
  • Web vitest on src/i18n and helpGlossary passes (342/342).

No test covers the 2000-01-01 floor or the single Required error for an omitted date. A search of tests/ for the floor's date, its error codes and its message found no test of the same floor on payments or expenses. A review probe of the built validator confirmed both behaviours.

Docs-impact: none — the in-app Operational day definition already covers every future-dated record in general terms; the Help "today" list now names orders.

CreateSalesOrderValidator now reads the farm clock like RecordPaymentValidator: SalesOrder.OrderDate.NotFuture past the farm's today, SalesOrder.OrderDate.NotTooOld before 2000-01-01. The k6 sales bundle sends UTC yesterday, and Help and the glossary list orders among the dates that cannot be in the future.

Refs #1333
@mforce

mforce commented Oct 21, 2026

Copy link
Copy Markdown
Owner Author

Help page, "Daily entry" section: the "today" bullet now lists orders among the dates that cannot be in the future. Captured at 1280x800, light theme, on the readme-farm owner. Before is from 63378d32 (main) and after is from 0a79e3de. Each frame came from its own sim stack, rebuilt at that commit. The red outline marks the changed bullet and was added only for the capture. No page errors were logged.

Before After
English Before, English: the Help today bullet without orders After, English: the Help today bullet listing orders
Spanish Before, Spanish: the Help today bullet without pedidos After, Spanish: the Help today bullet listing pedidos
Tagalog Before, Tagalog: the Help today bullet without order After, Tagalog: the Help today bullet listing order

@mforce
mforce merged commit e85b33f into main Oct 21, 2026
21 checks passed
@mforce
mforce deleted the fix/1333-sales-order-future-date branch October 21, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API accepts a sales order dated in the future

1 participant