Compact Block
Groups contiguous S2S natural-farming Crop Actual tiles from several farmers into a compact block of at least 5 acres. Used by Unit-in-charge / FMT staff.
FactsheetPlanning & tracking
- Who uses it
- Unit-in-charge (unit-incharge)FMT (fmt_l1)
- How you get here
- VO tab (Unit/FMT home) > Compact Block card. Card visible when PORTFOLIO_APP_CONFIG.FF_COMPACT_BLOCK = 1 (defaults to visible if the key is missing).
- Tables
compact_block,compact_block_member,ie_flat_entity- APIs
- 7 calls today, 7 App Service operations
- Offline
- Offline-first: compact_block and compact_block_member rows are written locally and synced via CompactBlockWorker and CompactBlockMemberWorker through ledger entries with dependencies.
Screens
| Screen | What it does | Source |
|---|---|---|
| Compact Block list | Lists active compact blocks with warning chips and search. | app/src/main/java/org/platformcommons/urvi/view/compactblock/CompactBlockListFragment.kt |
| Compact Block container | Header (name, member count, delete) and Farmer/Crop tabs. | app/src/main/java/org/platformcommons/urvi/view/compactblock/CompactBlockContainerFragment.kt |
| Farmer tab | Add-farmer wizard (VO > SHG > tiles) and review of selected tiles. | app/src/main/java/org/platformcommons/urvi/view/compactblock/CompactBlockFarmersFragment.kt |
| Crop tab | Read-only acres per crop and distinct practices across selected tiles. | app/src/main/java/org/platformcommons/urvi/view/compactblock/CompactBlockCropsFragment.kt |
| Searchable multi-select dialog | Shared VO/SHG picker with an "All" option. | app/src/main/java/org/platformcommons/urvi/view/common/SearchableMultiSelectAdapter.kt |
What it captures
| Field | Type | Required | Validation | Options from |
|---|---|---|---|---|
| CB name | Text (Edit name dialog) | Yes | Defaults to "CB <number of CBs stored locally>". On rename, must be unique among local CBs (trimmed); otherwise "A compact block with that name already exists." | User input |
| Select VO | Searchable multi-select with "All" | Yes | Items show "VO name\nVO id". | Distinct VOs in local ie_flat_entity |
| Select SHG | Searchable multi-select with "All" | Yes | Items without an SHG id show just the name (Non-SHG). | SHGs of the chosen VOs from ie_flat_entity |
| Tiles | Checkbox list grouped by farmer | Yes | Checkbox disabled when the tile has no geofence id. Search matches farmer-name words starting with the query. | Eligible Crop Actual tiles of active farmers in the chosen VO/SHG |
| Removal / delete reason | Text | If removing tiles or deleting the CB | Spaces become "_" before sending. | User input |
Rules
Conditions from the code, rewritten as plain decision rules.
| When | Then |
|---|---|
| Showing the CB list | Only active CBs created or updated on or after 2026-09-01 are shown (hard-coded). |
| Total tile acres of a CB < 5 | Card chip "< 5 Acres". |
| Any farmer in the CB is inactive | Card chip "Inactive". |
| Any farmer is C4 or C5 | Card chip "Not Farmer". |
| Any tile's crops lack the S2S practice code (AP-GOV-KAP-100_PERCENT_CHEMICAL_FREE_NATURAL_FARMING) | Card chip "Not S2S". |
| Listing tiles in the wizard | A tile is eligible only if it is current season, the latest version for its titleId, has a geofence, sits on land with both survey number and khata (account) number, and is not in another active CB. Only active farmers are included. |
| Searchable multi-select: "All" is ticked | Every item is ticked, including items hidden by the current search. |
| Searchable multi-select: any item is unticked | "All" is unticked; it re-ticks automatically once every item is ticked. |
| Searchable multi-select: OK pressed with nothing selected | Nothing happens (silently). |
| Computing total acres | Total = sum of proportion.acre over every crop line of every selected tile (crop acres, not land area). |
| New CB and total < 5 acres | Save blocked: "Please select a total asset of above 5 acres." |
| New CB and total >= 5 acres | Saved; ledger COMPACT_BLOCK POST. |
| Edit and total < 5 acres | The whole CB is deleted after a "Delete compact block" dialog with required reason; ledger COMPACT_BLOCK DELETE. |
| Edit, total >= 5 acres, tiles removed | Asks "Reason for Farmer Removal" (required); removed tiles are disabled (COMPACT_BLOCK_MEMBER DELETE), then CB saved (COMPACT_BLOCK PUT). |
| Edit, total >= 5 acres, nothing removed | Saved; ledger COMPACT_BLOCK PUT (depends on earlier POST and PUT). |
| Removing a tile in edit mode would drop the total below 5 acres | Warning "Total Land Below 5 Acres" that submitting will disable the compact block. |
| Tapping a tile on a saved CB | Opens the Crop Actual edit screen for that tile; data refreshes on return. |
| Server refuses a Crop Actual edit because the tile is in a CB | Error ERR_PLATFORM_PART_OF_COMPACT_BLOCK shown on the portfolio card and in the sync log. |
API contracts
Each call opens to its use case, headers, request and response bodies, and errors.
| Today: call | Use | Replaced by |
|---|---|---|
GET /gateway/portfolio-service/api/v1/compact-block/filter?cbmOwningEntityIds= | Download compact blocks that include the given farmers. | |
GET /gateway/portfolio-service/api/v1/compact-block?direction=desc&page&size&voIds= | Download compact blocks for the selected VOs, paged. | |
GET /gateway/portfolio-service/api/v1/portfolios/portfolioLineItems?portfolioLineItems= | Refetch crop line items from the server (overwrite local after a compact-block edit lock, or pick a harvest target). | |
POST /gateway/portfolio-service/api/v1/compact-block | Create a compact block (group of adjacent lands). | |
PUT /gateway/portfolio-service/api/v1/compact-block | Update compact blocks. | |
DELETE /gateway/portfolio-service/api/v1/compact-block?compactBlockId&reason | Delete a compact block. | |
DELETE /gateway/portfolio-service/api/v1/compact-block/{cbId}/compact-block-member?reason&compactBlockMemberId | Remove a member from a compact block. |
| App Service v2: operation | Use |
|---|---|
GET /config | Typed config bundle (ETag) |
GET /farmers/snapshot | Cursor-paged hydrated farmer snapshot |
GET /farmers/changes | Delta sync: upserts and tombstones since a cursor |
GET /farmers/{farmerId}/crop-blocks | A farmer's Crop Actual blocks for a season / month |
GET /compact-blocks | Compact blocks for VOs |
GET /compact-blocks/eligible-tiles | Tiles eligible for a compact block |
POST /sync/batch | Apply an ordered batch of offline mutations |
Behaviour notes
- Crop tab data is passed between screens through SharedPreferences (PRE_CB_CROPS_DATA).
- Possible bug · unverified the "< 5 Acres" chip is wrong because totalSelectedLand is never reset per row in CompactBlockListAdapter and accumulates.
- Possible bug · unverified hard-coded cutoff 2026-09-01 hides all older CBs.
- Possible bug · unverified default name "CB <count>" can collide after deletions; uniqueness is checked only on rename.
- Possible bug · unverified saving an edited CB under 5 acres deletes the whole CB via a dialog that looks like the remove-farmer dialog.
- Possible bug · unverified deleteCompactBlockMember runs database work on the main thread.
- Possible bug · unverified VO/SHG selection passes display strings ("Name\nId") that the repository splits on newline.
- Possible bug · unverified Created/Updated dates on the list show raw millisecond numbers.
- Possible bug · unverified feature flag defaults to enabled when missing, unlike other switches.
Improve in the rewrite
- Make delete an explicit separate action; never delete as a side effect of saving.
- Show a live 5-acre progress bar while selecting tiles.
- Explain why a tile cannot be selected (no geofence, no survey/khata number, already in a CB, wrong season).
- Move the 5-acre minimum and the date cutoff to config.
- Pass ids, not display strings, between pickers and queries.
- Decide whether "All" means all visible items when a search is active.