Repository navigation
fix(spp_base_common): keep canCreate on the form New button (#582) - #588
Conversation
…rd (#582) Apply the web.FormView extension to the stock template with Odoo's own template_inheritance engine and assert the control-panel New button still reads canCreate. Fails today: the extension replaces the condition with !hideFormCreateButton, so forms opened with create disabled by action context, arch, ACL or preventCreate render a live New button.
The web.FormView extension behind hideFormCreateButton replaced the button's t-if instead of extending it, so Odoo's canCreate guard was dropped and every form opened with create disabled (action context, create="0" on the arch, no create ACL, preventCreate) rendered a live New button. The condition is now canCreate and !hideFormCreateButton: the flag can still only hide the button. Dialog forms use the separate web.FormView.Buttons template and were never affected. spp_base_common 19.0.2.0.3.
…d for read-only roles (#582) Spec 01, test 20, as the HQ validator: an approval review form (the role has no create ACL on reviews) and the CR detail form (opened with context create: false). Both assert .o_form_button_create has DOM count 0 rather than being hidden, because spp_programs' FormController patch hides the same button with display:none and would mask a template that renders it anyway.
- Python test asserts the exact condition (a token check accepted 'canCreate or !hideFormCreateButton'). - e2e: open the My Approvals dropdown before Pending Approvals; the review-form comment names the real reason (create="0" on the arch and no create ACL); drop the CR-form assertion, which was vacuous (that form already sets hideFormCreateButton and has create="0"); assert the context case where it really applies, on the detail form the create wizard opens with create: False (test 16). - HISTORY: say where the button was visible.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 19.0 #588 +/- ##
==========================================
- Coverage 77.09% 77.08% -0.02%
==========================================
Files 727 736 +9
Lines 46864 47835 +971
==========================================
+ Hits 36131 36874 +743
- Misses 10733 10961 +228
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
reichie020212
left a comment
There was a problem hiding this comment.
Approve. No blocking findings. Hostile review at head cf398db9597f37ae315ba79c05cf229f86e05188 (0 commits behind 19.0).
The one-line fix restores stock behaviour. Stock Odoo 19 renders the control-panel button as t-if="canCreate" (web/static/src/views/form/form_controller.xml:9). canCreate = create && !this.props.preventCreate (form_controller.js:170). canCreate and !hideFormCreateButton therefore can only hide the button relative to stock, never show it.
Checked and cleared
- The regression test runs, and it fails on the old code. The
test (spp_base_common)CI job logs bothTestFormCreateButtonTemplatecases starting, then0 failed, 0 error(s) of 9 tests. The exact-equality assertion rejects both the old!hideFormCreateButtonand anorre-spelling.apply_inheritance_specsaccepts a list of specs (template_inheritance.py:specs = specs_tree if isinstance(specs_tree, list) else [specs_tree]).hasclassis registered globally byir_ui_view.py(xpath_utils['hasclass']), so the plain lxml.xpath()in the test resolves. - The cited e2e run still describes this head. Run 37724359788 ran on
8f0bf8445(both specs green).git diff --stat 8f0bf8445 cf398db95touches onlyREADME.rstandstatic/description/index.html, so no runtime file changed since. - The e2e assertions would fail on the old code.
- Test 16:
open_cr_close_modalopens the detail model (change_request.detail_res_model, notspp.change.request) withcontext: {create: False}(create_wizard.py). The onlyhideFormCreateButtonpatches are keyed tospp.change.request,spp.programand the DRIMS dispatch model, so before the fix the button rendered on that form. - Test 20:
spp.approval.review's form declares<form create="0">(approval_review_views.xml:53). - Both tests assert
toHaveCount(0)rather than visibility, sospp_programs'display:noneworkaround cannot hide a failure.
- Test 16:
- Blast radius.
custom_list_create_template.xmlis the only OpenSPP template that toucheso_form_button_create. The dialog-footer copy (web.FormView.Buttons) was never extended. The threehideFormCreateButtonusers only ever set it totrue, soand-ing incanCreatechanges nothing for them. - Manifest and changelog.
19.0.2.0.2→19.0.2.0.3is above base. The HISTORY fragment is present and the README was regenerated.Closeslinks #582. Thespp_programsDOM workaround and its comment wrongly blaming Odoo are tracked in #589, which is fine to defer: with this fix the workaround is redundant but harmless.
Note (not a finding)
- The
pre-commitcheck is stillpending(since 04:00Z), somergeStateStatusreadsUNSTABLE. It is worth letting that finish before merging.
…he template is shipped (#582) Second review round: preventCreate reaches FormController only through FormViewDialog, which disables the control panel, so that path never rendered the button. Drop it from the list of affected cases in HISTORY, the template comment and the test docstring. Add a test that the manifest still lists the template in web.assets_backend, so removing the asset cannot leave the inheritance test green.
Fixes #582.
Problem
spp_base_commonextendsweb.FormViewso a module can hide the form's control-panel New button by settingthis.hideFormCreateButton = true. The extension replaced the button'st-ifinstead of extending it, so Odoo's owncanCreateguard was dropped.canCreateis the single switch behind every way a form is opened without create:{'create': False}in the action context,create="0"on the form arch, and a role without create access. In all three cases the form still rendered a live, keyboard-reachable New that opened a blank editable record, or failed with an access error on save.Only the control-panel button was affected. Stock Odoo has a second
o_form_button_createin the separateweb.FormView.Buttonstemplate (dialog footers); the extension never touched it, so forms in dialogs always behaved. For the same reason the fourth input tocanCreate,preventCreate, was never exposed: it is only passed byFormViewDialog, which also turns the control panel off.On stacks with
spp_programsthe defect was masked byspp_programs/static/src/js/form_controller_create.js, which hides the rendered button withdisplay: none; its comment blames Odoo 19, but stock Odoo hides the button correctly. Stacks withoutspp_programsshowed New on every read-only form.Fix
spp_base_common/static/src/xml/custom_list_create_template.xml: the condition is nowcanCreate and !hideFormCreateButton. The flag can only hide the button, never show it; the three modules that set it (spp_programs,spp_change_request_v2,spp_drims) keep working unchanged.spp_base_common→19.0.2.0.3, HISTORY fragment added.Impact on other modules
The new condition can only hide the button in more cases. No module forces it on. Screens that lose New are exactly the ones that declared they should not have it: 19 form archs with
create="0"(logs, audit, approval reviews, entitlements, memberships, payment batches, scoring, studio), the threespp_programsactions with{'create': False}that reach a form (in-kind entitlements, cash entitlements, program memberships; thespp_consentexpired-consents action is list-only) and about 45 Python-returned action dicts across 12 modules that passcreate: False, each judged a read-only "view X" screen or a dialog, CR detail forms opened from the Change Requests list, and every read-only ACL. Thespp_programsDOM workaround and the.o_form_button_createselector inspp_farmer_registry's restriction patch become redundant (follow-up issue, not changed here). The e2e suite's six New clicks are all by admin where create is allowed.Tests
spp_base_common/tests/test_form_create_button_template.pyapplies the extension to the real stockweb.FormViewtemplate with Odoo's ownodoo.tools.template_inheritanceand asserts the resulting button condition keepscanCreate(and still!hideFormCreateButton); a second test asserts the dialog-button template is untouched. Before the fix:Regex didn't match: '\bcanCreate\b' not found in '!hideFormCreateButton', 1 failed of 9. After: 0 failed of 9..o_form_button_createhas DOM count 0 on the change-request detail form the create wizard opens withcontext: {create: False}(test 16, admin; nothing on that arch or in a FormController patch hides the button, so this is the pure context path) and on an approval review form as the HQ validator (test 20;create="0"on the arch and no create ACL for the role). Count rather than visibility, because thespp_programsworkaround only setsdisplay:none. Not run locally (port 8069 is taken on my machine); dispatched on this branch: run 37724359788 is green (spec 01: 24 passed, spec 02: 1 passed; both new assertions executed) — https://github.com/OpenSPP/OpenSPP2/actions/runs/37724359788HttpCasebrowser tests are skipped silently in CI and would be green before and after.spp_programs): before, a form opened with{'create': False}had the button in the DOM withdisplay:noneand the live template condition read!hideFormCreateButton; after, count 0 and the condition readscanCreate and !hideFormCreateButton. A normal registrant form as admin still shows New; a hazard incident form as the demo CR HQ validator (read, no create; arch has nocreate="0") renders none.Follow-ups
spp_programsworkaround and the stale comments: spp_programs: retire the DOM workaround for the form "New" button now that #582 keeps canCreate #589.