Skip to content

refactor(farm_base): extract farm.rank.mixin from observation + fence#10

Open
dnplkndll wants to merge 1 commit into
19.0from
refactor/farm-base-rank-mixin
Open

refactor(farm_base): extract farm.rank.mixin from observation + fence#10
dnplkndll wants to merge 1 commit into
19.0from
refactor/farm-base-rank-mixin

Conversation

@dnplkndll

Copy link
Copy Markdown
Contributor

What changed

Both farm_observation.urgency_rank and farm_fence.condition_rank implemented the same pattern: a Selection field whose alphabetical order doesn't match priority order, paired with a stored-computed Integer mirror used as the sort key in _order.

This PR extracts that mechanism into farm.rank.mixin (in farm_base). Subclasses now declare just:

class FarmObservation(models.Model):
    _inherit = ["mail.thread", "farm.rank.mixin"]
    _order = "rank desc, observation_date desc"
    _rank_selection_field = "urgency"
    _rank_value_map = {"low": 0, "med": 1, "high": 2}

…and pick up the stored, indexed rank integer the mixin contributes. The two consumers each drop ~10 lines.

Migration

Renaming urgency_rankrank and condition_rankrank is a column rename. farm-pack just shipped these models at 19.0.1.0.0 and no production installs exist yet, so this PR bumps to 19.0.1.1.0 and accepts the rename without a migration script.

Tests

  • farm_base/tests/test_rank_mixin.py — new — confirms the abstract model registers and the rank field declares store=True, index=True, readonly=True.
  • Existing regression tests in farm_observation + farm_fence (test_urgency_sort_priority_not_alphabetical, test_condition_sort_priority_not_alphabetical) keep passing — they assert search-result order, which doesn't care which field holds the rank.

Test plan

  • CI green on 19.0
  • Smoke install on local doodba: install farm_observation + farm_fence, confirm the rank column is created and grouped kanbans put high-urgency / repair items on top

Both farm_observation.urgency_rank and farm_fence.condition_rank
implement the same pattern: a Selection field whose alphabetical
order doesn't match priority order, paired with a stored computed
Integer that mirrors it so `_order` produces a real priority sort.

Extract the shared mechanism into farm.rank.mixin (in farm_base):
subclasses set _rank_selection_field + _rank_value_map class attrs
and use `_order = "rank desc, ..."` to pick up the rank column the
mixin contributes.

Migration concern: renaming `urgency_rank` → `rank` and
`condition_rank` → `rank` is a schema change. farm-pack just
shipped these models at 19.0.1.0.0 and no production installs
exist yet, so no migration script is needed — bump to 19.0.1.1.0
and accept the column rename.

Version bumps: farm_base, farm_observation, farm_fence
→ 19.0.1.1.0.
@dnplkndll dnplkndll closed this May 19, 2026
@dnplkndll dnplkndll reopened this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant