Stock Management 3.0.0 + esm-stock-management-app 3.2.1: operations/inventory lists always empty, UI cannot save operations (same at_location_id error as thread 49811)

Setup: OpenMRS 3 on Tomcat 9 / Hibernate 5.6 (core 2.x), stockmanagement-3.0.0.omod, esm-stock-management-app 3.2.1. Main Pharmacy and Main Store are tagged stock locations, children of the login location, with stockmgmt_party and stockmgmt_location_tree rows. GET /stockmanagement/userrolescope returns the admin scope correctly (all 9 operation types, facility with descendants + Main Pharmacy + Main Store). 1. Saving an Opening Stock operation from the UI fails: Column ‘at_location_id’ cannot be null (location selected, session at Main Pharmacy). 2. I inserted one completed Opening Stock operation + 131 lines, batches and transactions directly in the database. GET /stockmanagement/stockoperation and /stockiteminventory return an empty list, and GET stockoperation/ returns “Object with given uuid doesn’t exist”. 3. With the MySQL general log on, the module runs only the two stockmgmt_user_role_scope permission queries and never queries stockmgmt_stock_operation or the transaction table. Replaying those permission queries by hand returns the correct parties (1 = Main Pharmacy, 2 = Main Store). This is also true for the first request after a restart, so it is not a cached result. No errors are logged. Which condition makes the module return an empty result after the permission check? Is there a column or row a UI-created operation has that a direct insert lacks? Which esm-stock-management-app version is meant to pair with stockmanagement 3.0.0?

Hi Hamza, thanks for the detailed write-up on this issue.

“Column ‘at_location_id’ cannot be null”

The issue is known and tracked as O3-6137; please check it out. The module relies on StockOperationDTOValidator to derive the operation’s location from the source or destination, and webservices.rest 3.x no longer calls validators from DelegatingCrudResource.create(), so the field reaches Hibernate as null. Backend PR 51 moves the derivation into the service so it no longer depends on the REST framework. Until that is merged and released as 3.1.0, no operation of any type can be saved from the UI or the API on a REST 3.x stack, not even as a draft.

Hey Hamza, regarding 2 and 3, I think I can see why it stops right after the permission queries. When searching stock operations, the module first builds a set of record privilege filters from your role scopes (getRecordPrivilegeFilters in StockManagementServiceImpl), and if that set is empty, it returns an empty list without ever querying stockmgmt_stock_operation. Fetching one operation by UUID goes through the same search, which is why you’re also getting the “doesn’t exist” error.

The filter step doesn’t use the standard OpenMRS privilege check. For each role in the scope, it looks at the privileges of that role and its parent roles, and only keeps the scope if that list explicitly has App: stockmanagement.stockoperations. A superuser role such as System Developer passes the usual checks without that privilege being listed, so its scope is skipped, the set ends up empty, and you get an empty result with no error. It also skips the scope before it looks up the operation types, which would fit with only the two scope queries showing up in your log.

So I’d check which role your admin scope uses and whether that role has App: stockmanagement.stockoperations assigned explicitly. If it doesn’t, assigning it (or pointing the scope at a role that has it) should make the operations show up. For /stockiteminventory, note that it also returns an empty list unless you pass an item filter such as stockItemUuid or stockOperationUuid.

I read this from the code on master and didn’t reproduce it, so treat it as a lead rather than a confirmed answer.