fix(spp_registry): bound registration_date and the birthdate onchange by the user's today (#520) - #533
Open
gonzalesedwin1123 wants to merge 3 commits into
Open
fix(spp_registry): bound registration_date and the birthdate onchange by the user's today (#520)#533gonzalesedwin1123 wants to merge 3 commits into
gonzalesedwin1123 wants to merge 3 commits into
Conversation
… by the user's today The registration_date default used fields.Date.today() and _check_registration_date compared against date.today(), so a registrar east of UTC creating a registrant born earlier that local day was refused: the defaulted registration date was the server's yesterday, and entering the correct date was refused as future. _birthdate_onchange used the same server date and reset the valid birthdate in the form. All three now use fields.Date.context_today, the rule #397 gave _check_birthdate_not_future. Fixes #520
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 19.0 #533 +/- ##
==========================================
- Coverage 76.91% 76.88% -0.03%
==========================================
Files 704 740 +36
Lines 45774 48023 +2249
==========================================
+ Hits 35205 36922 +1717
- Misses 10569 11101 +532
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- TestRegistrationDateConstraint anchors on context_today like the code under test (mirrors #397's fix to the birthdate tests) - every timezone test asserts the frozen clock and tz context are in effect, so none can pass by collapsing onto the server date - cover the west-of-UTC direction, where the bound moved a day earlier (server's today refused, default follows the user) - cover the onchange's restore-previous branch on a saved record - constraint rationale moved into a docstring; HISTORY describes the read-only form field accurately and adds a multi-timezone note
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.
Fixes #520. Finishes the job #397 started when it moved
_check_birthdate_not_futuretofields.Date.context_today.Problem
Three sibling sites still compared against the server's UTC date, so a registrar east of UTC (on tomorrow's date for part of each day) was refused a registrant born earlier that local day:
registrant.pyregistration_datedefaulted tofields.Date.today(): the defaulted registration date was the server's yesterday relative to the birthdate, so_check_registration_datefailed with "must be later than the birth date".registrant.py_check_registration_datebounded the field bydate.today(): entering the correct local date was refused as "future".individual.py_birthdate_onchangecompared tofields.Date.today(): it silently reset the valid birthdate in the form. West of UTC it did the opposite, keeping the user's tomorrow only for the Fix/362 birthdate not future #397 constraint to refuse it on save.Fix
All three use
fields.Date.context_today(record). No schema change, no migration.spp_registry19.0.2.2.4 → 19.0.2.2.6 with a HISTORY fragment; 2.2.5 is taken by the unmerged #522, whichever lands second renumbers. README/index.html left for CI's pinned generator.Tests (
tests/test_constraints.py, new classTestUserTodayAcrossTimezones, 8 tests)The clock is frozen with freezegun (ships with Odoo) so the tests are deterministic at any wall-clock hour; the frozen instant is derived from the real date so nothing ages. Timezone is set with
with_context(tz=...), whichenv.tzhonours. Every test first asserts that the frozen clock and tz context really shift the user's today by one day, so none can pass by collapsing onto the server date.East of UTC (Asia/Manila at 23:00 UTC), the relaxing direction:
West of UTC (America/Los_Angeles at 05:00 UTC), the direction where the bound moved a day earlier:
5. the default follows the user: registration_date == user's today (a day behind the server), coexisting with a past birthdate;
6. registration_date = server's today (the user's tomorrow) → refused, by design; this is the one value accepted before and refused now;
7. onchange with birthdate = server's today → reset with warning, matching the #397 constraint;
8. onchange on a saved record restores the saved birthdate (the
_originbranch).The pre-existing
TestRegistrationDateConstrainttests now anchor oncontext_todaylike the code under test, as #397 did for the birthdate tests; on the server date they were green only because the test user has no timezone.Pre-fix: 1, 2, 4, 7 fail with exactly the errors described in the issue. Post-fix:
0 failed, 0 error(s) of 293 tests. All pre-commit hooks pass on the changed files.Review notes (adversarial review run before marking ready)
registration_datefeedscreate_dateonly or usesdays_back≥ 2,seeded_volume_generatorbackdates by 30–730 days, and no API v2 / change-request / DCI path writesregistration_date. Theregistration_date < birthdatebranch carries exactly the risk profile Fix/362 birthdate not future #397 already introduced.env.tzhonours a caller-suppliedcontext['tz']ahead of the user's profile, so an RPC caller can move the bound by up to a day (UTC+14). Inherited from Fix/362 birthdate not future #397's birthdate rule; not security-relevant, recorded as a conscious trade-off.registration_dateis read-only there once defaulted (views/individual_views.xml); the exposure is API/import writes.agecompute still uses the server's now;relativedeltaclamps at 0 so no negative age. Cosmetic, listed in Remaining "not in the future" date bounds compare against the server date, not the user's today (follow-up to #520) #534.Noted, not changed → #534
Same-class server-date bounds elsewhere are filed as #534:
phone_number.pydate_collected(same module, same form),spp_programscyclestart_date,spp_dci_client_crvsevent_date,spp_dci_client_drassessment_date, plus the untranslated / boundary-inaccurate messages in_check_registration_dateand the demo generators'dateto=fields.Date.today()tidy-up.Version ordering: 2.2.5 belongs to the unmerged #522; whichever of #522/#533 lands second renumbers and re-applies CI's README diff.