OBPIH-6931 filter cycle count candidates by cycle count status#5030
OBPIH-6931 filter cycle count candidates by cycle count status#5030
Conversation
| </TableHeaderCell> | ||
| ), | ||
| cell: ({ getValue }) => ( | ||
| // TODO: Use variant fetched from the API https://pihemr.atlassian.net/browse/OBPIH-6931 |
There was a problem hiding this comment.
I removed the TODO here since I don't think this is something that the backend should be returning. Variant is only used for display purposes. The backend has no concept of what that field means (it's used as an html class), so it'd feel weird for the backend to decide on behalf of the frontend how it should be displaying rows of a certain status.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5030 +/- ##
=========================================
Coverage 7.76% 7.76%
Complexity 860 860
=========================================
Files 620 621 +1
Lines 42760 42758 -2
Branches 10373 10374 +1
=========================================
+ Hits 3321 3322 +1
+ Misses 38945 38942 -3
Partials 494 494 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| * maintain an accurate list of items (which it uses to compute its status). Still, the disadvantage is | ||
| * important to note, and we should strive to replace this hasMany with a better option in the future. | ||
| */ | ||
| cycleCountItems: CycleCountItem, |
There was a problem hiding this comment.
@kchelstowski don't hate me for this 😅 I really tried to get it to work without the hasMany but no matter what I tried I couldn't get a simple solution for updating the cycle count status when an item's status is changed.
I tried doing it in the afterInsert/Update in CycleCountItem, but that didn't work due to transaction weirdness (it called save on the cycle count, but the status in the db didn't change, not even when I add flush: true).
I also tried adding a method like this in CycleCount:
CycleCount saveCountAndItems(List<CycleCountItem> items) {
// Save the count first so that the item save doesn't fail validation
this.save()
for (item in items) {
item.save()
}
// Now that the items are saved, fetch them from the db (inside the recomputeStatus method) and recompute status
status = recomputeStatus()
this.save()
return this
}
CycleCountStatus recomputeStatus() {
// This doesn't work! The "items" from the saveCountAndItems call aren't in the db yet and so aren't fetched here...
List<CycleCountItems> items = CycleCountItem.findAllByCycleCount(this)
...
}
We can discuss options for a better solution if you want but as much as I dislike hasMany, I think this is fine for now (for the reasons I mention in the comment).
There was a problem hiding this comment.
@ewaterman that's weird, I might take a look if I find time, in my opinion if it's happening in the same session and transaction (I mean you update a few items, or add new), those should be immediately accessible via CycleCountItem.findAllByCycleCount(this).
Anyway, I'm fine with having the bidirectional association, but I would lie if I didn't have in mind "why not a few tickets before??" 😆
There was a problem hiding this comment.
if you have time to look at it, that'd be awesome. I was also assuming that they'd be accessible because it should be the same transaction, but I couldn't get it to work. You can see some of my older commits for references to what I was testing.
|
|
||
| <addColumn tableName="cycle_count"> | ||
| <column name="status" type="VARCHAR(100)"> | ||
| <constraints nullable="false" /> |
There was a problem hiding this comment.
TODO: set a default value for existing data! Or just truncate obdev3 and 5 because this isn't live yet??
There was a problem hiding this comment.
We've run once recently into a similar issue. We've just cleared the data (via the script I've sent on Slack for you some time ago). I'm fine with doing the same again.
|
|
||
| def beforeUpdate() { | ||
| updatedBy = AuthService.currentUser | ||
| status = recomputeStatus() |
There was a problem hiding this comment.
Is it updated after related items change as well? Have you considered using a formula for it (see point 8.2.11 here https://grails.github.io/legacy-gorm-doc/6.0.x/hibernate/manual/index.html#ormdsl) instead of recomputing here? Perhaps it would be a good/suiting approach as well?
There was a problem hiding this comment.
The problem with having it be derived was that it was inaccessible when building the session view in cycle-count-session.sql. I didn't try it the way you suggest but I feel like that would have the same issue. I can test though
There was a problem hiding this comment.
Ok, I think this makes sense then.
kchelstowski
left a comment
There was a problem hiding this comment.
I would like to either do another round of review tomorrow
| * maintain an accurate list of items (which it uses to compute its status). Still, the disadvantage is | ||
| * important to note, and we should strive to replace this hasMany with a better option in the future. | ||
| */ | ||
| cycleCountItems: CycleCountItem, |
There was a problem hiding this comment.
@ewaterman that's weird, I might take a look if I find time, in my opinion if it's happening in the same session and transaction (I mean you update a few items, or add new), those should be immediately accessible via CycleCountItem.findAllByCycleCount(this).
Anyway, I'm fine with having the bidirectional association, but I would lie if I didn't have in mind "why not a few tickets before??" 😆
| ] | ||
|
|
||
| static mapping = { | ||
| cycleCountItems cascade: 'all-delete-orphan' |
There was a problem hiding this comment.
I would like to have a convention around the cascading. There are pros and cons of having/not having cascade behavior. Due to the cascading we have sometimes run into unexpected issues difficult to spot. It's better to have some of the operations being done explicitly (in this case deleting).
There was a problem hiding this comment.
yeah I agree. We don't ever delete cycle counts so I can change this to only cascade updates if we want, but I figured if we ever did need to delete a cycle count, we'd also want to delete the items (otherwise we'll get constraint violations)
grails-app/i18n/messages.properties
Outdated
| locale.es.label=Español (España) | ||
| locale.es_MX.label=Español (México) | ||
| locale.es.label=EspanÌol (EspanÌa) | ||
| locale.es_MX.label=Español (México) |
There was a problem hiding this comment.
hm weird. I think it happened when I merged develop into the PR. I'll revert
|
|
||
| <addColumn tableName="cycle_count"> | ||
| <column name="status" type="VARCHAR(100)"> | ||
| <constraints nullable="false" /> |
There was a problem hiding this comment.
We've run once recently into a similar issue. We've just cleared the data (via the script I've sent on Slack for you some time ago). I'm fine with doing the same again.
| } | ||
| } | ||
| return CycleCountDto.createFromCycleCountItems(cycleCountItems) | ||
| return CycleCountDto.asDto(cycleCount) |
There was a problem hiding this comment.
wouldn't toDto sound better?
| } | ||
| return CycleCountDto.createFromCycleCountItems(cycleCountItems) | ||
|
|
||
| if(!newCycleCount.save()) { |
There was a problem hiding this comment.
nitpicky: missing space between if and (
| ) | ||
|
|
||
| List<AvailableItem> itemsToSave = determineCycleCountItemsToSave(facility, request.cycleCountRequest.product) | ||
| newCycleCount.save() |
There was a problem hiding this comment.
have you made sure it can be removed? I was running into error that "Not-null property references a transient value - transient instance must be saved before current operation", but I assume the cascading now makes it work, since you introduced the bidirectional association
There was a problem hiding this comment.
yup with the bidirectional + cascade save it's not needed anymore
|
I'm merging this as-is after our tech huddle discussion but we can (and should) revisit the "hasMany" and cascade behaviour conversation as we get more of the feature implemented |
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-6931
Description:
We need to be able to filter the results in the TO COUNT and TO RESOLVE tabs by cycle count status (before it was being done on cycle count request status which doesn't have enough info for us to distinguish between the tabs). However it seems that the criteria doesn't support filtering by transient fields so the current code doesn't work. I'll try to think more about what to do here but maybe we can brainstorm together.