Repository navigation
fix(sales): refuse a sales order dated after the farm's today - #1344
Merged
Merged
Conversation
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
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.






Closes #1333
Why
The API accepted a sales order dated in the future.
CreateSalesOrderValidatorchecked only thatOrderDatewas set. The web form caps the date at today, but a directPOST /api/v1/salesskipped that cap. Payments, expenses, daily entries and the other dated records already refuse a date after the farm's today.What changed
CreateSalesOrderValidatortakesIFarmClockand adds the payment validator's two rules:SalesOrder.OrderDate.NotFuture(after the farm's today) andSalesOrder.OrderDate.NotTooOld(before 2000-01-01). The existingSalesOrder.OrderDate.Requiredstays first, andCascade(Stop)keeps an omitted date at that one error.bundles.jsscript 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 usesdaysAgo(1), like the daily-entry write. I did not run the k6 scenario; its date-helper test passes.SalesOrder.OrderDateis set only inSalesOrder.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
FarmLocalBoundaryBehindUtcTestsfreezes 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 returnedCreated:SalesOrder.OrderDate.NotFuture, and the farm's today still returns 201.FarmLocalDateRuleTestsgains the today-passes / tomorrow-fails pair. Making the rule accept tomorrow turnsSalesOrderDated_AfterFarmToday_Failsred.ValidatorErrorCodeCoverageTestspasses (44/44).src/i18nandhelpGlossarypasses (342/342).No test covers the 2000-01-01 floor or the single
Requirederror for an omitted date. A search oftests/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.