Repository navigation
[19.0][FIX] ni_patient, ni_observation, ni_questionnaire: forward-port of the 16.0 fixes - #184
Merged
Merged
Conversation
…ntry check_origin_date raised the translated message itself, a plain string, so setting a transfer date without a transfer source failed with "exceptions must derive from BaseException" instead of a validation error. It also compared the transfer date (a Date) with the encounter start (a Datetime), which fails with a TypeError on every encounter that has both, and on encounters without a start. Raise ValidationError, and compare the transfer date with the start date in the user's timezone, skipping the check when the encounter has no start. The encounter search filter "Until" filtered on period_start; use period_end. action_entered_in_error() wrote active=False. ni.encounter has no active field of its own and inherits ni.patient.active through _inherits, so marking an encounter as an error entry archived the patient. The state alone already marks the encounter inactive (ENCOUNTER_INACTIVE_STATE). Tests cover the transfer date and Error Entry. Refs: nirun-life#135 (cherry picked from commit 95ba2b1)
…ondelete ni.observation.report._compute_observation browsed self.id inside the loop, so reading observation_id or the history of several latest rows at once (a list, an export) raised "Expected singleton". Use rec.id. The test reads two rows of the patient's latest observations together. ni.observation.category.parent_id had ondelete="", which is not a valid value. Set "set null", Odoo's default for a nullable Many2one and what the column already used, so the database does not change. Refs: nirun-life#135 (cherry picked from commit d6e53ef)
PostgreSQL pushes a WHERE clause into a DISTINCT ON subquery only when it uses the DISTINCT ON columns. The ORM reads these views by id and searches them by survey_response_id, so every call rebuilt the view from the whole ni_observation table (up to ~100 s per read on production). The NOT EXISTS form lets the planner start from the primary key and anti-join through the (key, type_id, occurrence DESC, id) indexes. The anti-join cannot group NULLs the way DISTINCT ON does, so rows without type_id or occurrence are left out, and the encounter view leaves out observations without an encounter. Every caller filters the encounter view by encounter_id, and the report model already requires type_id. Fixes nirun-life#175 (cherry picked from commit c8b6aff)
The latest-observation views are searched by survey_response_id about a thousand times per tuning window. The index name matches the one already created on production, so the upgrade leaves it in place. Fixes nirun-life#175 (cherry picked from commit 1307860) Forward-port: the README names the index as Odoo generates it, ni_observation__survey_response_id_index. Refs: nirun-life#181
Deleting an ir.attachment checks every ON DELETE SET NULL foreign key that points at it. Without an index on message_main_attachment_id (ni.patient, res.partner) and ir.attachment.original_id, each check scans the whole table, which made a single delete take ~141 s on production. The btree_not_null field indexes generate the same names as the indexes already created by hand on production, so -u is a no-op there. Part of nirun-life#174 (cherry picked from commit 4ce4039) Forward-port: only the ir.attachment.original_id index. Since 17.0, message_main_attachment_id is defined by mail.thread.main.attachment, which ni.patient and res.partner do not inherit, so the field does not exist on these models. Refs: nirun-life#181
Closed
7 tasks done
_compute_history searched with self.patient_id and self.type_id inside the loop, so reading the history of several observations at once (the latest-observation list, an export) gave every row the history of all their types together. On 17.0 and later the domain also compared type_id with a list using "=", which logs a warning that fails the test run. Use rec and "in". The same bug is on 16.0. Refs: nirun-life#181
3 tasks done
piruin
approved these changes
Oct 30, 2026
39 tasks
7 of 8 tasks
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.
Refs #181 · Forward-port of #166, #176, #177 (16.0) · Epic #131
Summary (TH)
forward-port fix และ PERF ของ 16.0 ที่ merge หลัง stack Phase 1 มาที่ 19.0 สำหรับ
ni_patient,ni_observation,ni_questionnaire(5 commits, cherry-pick จาก 16.0) ส่วน indexmessage_main_attachment_id(item 5 บางส่วน และ item 6 ทั้งหมด) ไม่ได้ port เพราะตั้งแต่ 17.0 field นี้ไม่มีบนni.patient,res.partner,survey.user_inputแล้วChanges
95ba2b1bni_patientcheck_origin_dateraisesValidationError, compares dates in the user's timezone; "Until" filter onperiod_end; Error Entry no longer archives the patient; 2 new test filesd6e53ef3ni_observation_compute_observationusesrec.id; categoryparent_idondelete="set null"c8b6aff5ni_observationNOT EXISTS; README; tests13078601ni_questionnaireindex=Trueonsurvey_response_id4ce40396ni_patientbtree_not_nullindex onir.attachment.original_idonlye7d9c3d4ni_questionnairesurvey.user_inputhas nomessage_main_attachment_idsince 17.0ni_observation_compute_historyusesrecandin: reading several observations gave each one the history of all their types; on 17+ the=-with-list domain logs a warning that fails CI. Newtest_observation_history.py. Same bug on 16.0Each commit keeps the 16.0 subject and body plus
(cherry picked from commit …).Adapted for 19.0:
ni_observation/report/*: the NOT EXISTS views keep theSQL(...)/SQL.identifierform.ni_patientcheck_origin_date:ValidationError(self.env._(...))(no_import on 19.0).Decisions to review
original_idindex; see the decision record on [MIG 19.0][P1-8] Forward-port the 16.0 fixes merged after the Phase 1 stacks to 17.0/18.0/19.0 #181. The orphanmessage_main_attachment_idcolumns stay on production after OpenUpgrade (with their FK and the hand-made indexes), so attachment deletes stay fast; dropping them is P6 cleanup.ni_questionnaireREADME names the indexni_observation__survey_response_id_index(the name Odoo generates), notni_observation_survey_response_id_indexas on 16.0.How tested
-i ni_patient,ni_observation,ni_questionnaire --test-tags /ni_patient,/ni_observation,/ni_questionnaire: 0 failed, 0 errors of 113 tests (includestest_ni_encounter_entered_in_error.py,test_ni_encounter_origin_date.py,test_latest_observation.py).ir_attachment__original_id_indexandni_observation__survey_response_id_indexexist after install.pre-commitclean on the changed files.