Skip to content

[FIX] ni_medication: read donor dosage views with sudo - #180

Merged
piruin merged 1 commit into
16.0from
16.0-ni_medication-fix-dosage-view-access
Oct 29, 2026
Merged

piruin merged 1 commit into
16.0from
16.0-ni_medication-fix-dosage-view-access

Conversation

@piruin

@piruin piruin commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

What changed

  • ni.medication.dosage.fields.mixin._get_view reads donor form views with sudo() before using their arch.
  • ni_medication tests run as the lowest group each needs instead of the superuser:
    • TestDosageFieldsMixin → ni_medication.group_viewer, with the registry cache cleared in setUp so _get_view actually runs.
    • TestDosageTiming → ni_medication.group_user (lowest group that can create ni.medication.dosage).
  • Module README notes the sudo() invariant for donor views.

Why

Medication users could not open "เพิ่มประวัติการใช้ยา" (or the request/dispense/suggest line forms): Odoo raised an access error on ir.ui.view, which only base.group_system can read. The mixin's _get_view runs as the requesting user on a view-cache miss, so the error appeared after a restart/upgrade or in a language no admin had loaded the form in yet. The existing tests ran as superuser and could not catch it.

Closes #178

Scope

ni_medication: forms of ni.medication.request, ni.medication.dispense, ni.medication.statement, ni.medication.suggest.line.

Risk / Impact

Low. sudo() only covers reading the shipped donor view arch; record access is unchanged. No migration or config needed. Deploy by updating ni_medication.

How tested

odoo-bin -c odoo.conf -i ni_medication --test-enable --test-tags /ni_medication
  • Unit/integration tests: 10/10 pass. Without the fix, 4 TestDosageFieldsMixin subtests fail with the same ir.ui.view AccessError.
  • Manual check: reproduced the AccessError in an Odoo shell as a non-admin user loading the ni.medication.statement form with caches cleared.
  • Not tested / explain why:

Documentation

  • Module README.md updated
  • Not needed

Notes for reviewer

  • The view cache key has no user in it, so only one cold-cache load per language/view can hit the error. That is why it looked intermittent and depended on the user.

The dosage fields mixin splices fragments from donor form views in
_get_view, which runs as the requesting user on a view-cache miss.
Only base.group_system can read ir.ui.view, so medication users got an
access error opening medication forms whenever no admin had loaded the
form first in the same language (e.g. after a restart or upgrade).

Tests now run as the lowest group each one needs, with the view cache
cleared, so access regressions surface instead of being hidden by the
superuser and the view cache.

Fixes #178
@piruin
piruin merged commit 084fda0 into 16.0 Oct 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant