Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bank Org Request Export - Include Custom Units #4608

Merged
merged 24 commits into from
Nov 27, 2024
Merged

Conversation

awwaiid
Copy link
Collaborator

@awwaiid awwaiid commented Aug 24, 2024

Implements #4405, adding custom units to request export.

  • This does not change the general output, which only includes items that are part of some exported request
  • If any item is configured to have custom units, we now include a column for each custom unit and no-unit, whether any requests made use of those or not
  • Also, if the item's custom-unit was deleted but it is referenced, go ahead and add a column for it anyway
  • Significantly dumbed down the corresponding spec

@awwaiid awwaiid requested review from dorner and cielf August 24, 2024 22:04
@awwaiid awwaiid marked this pull request as draft August 24, 2024 22:05
@awwaiid awwaiid linked an issue Aug 24, 2024 that may be closed by this pull request
3 tasks
@awwaiid awwaiid marked this pull request as ready for review August 24, 2024 22:42
@awwaiid awwaiid added this to the Request Units (Packs) milestone Aug 25, 2024
@cielf
Copy link
Collaborator

cielf commented Aug 27, 2024

Hrm. I did an export that looked clean, but then I added a request that just had pads with 233 units. I got a "no implicit conversion from nil to integer" on line 99 of export_request_service. (Note: I made partner group 1 have all the categories, and gave pads a category of Period Supplies first).

@awwaiid
Copy link
Collaborator Author

awwaiid commented Sep 1, 2024

@cielf Fixed! The issue was similar to the one in another PR, where "some item -" was being used instead of "some item" when the default-unit was selected.


# It's possible that the unit is no longer valid, so we'd
# add that individually
if item_request.request_unit.present? && !item.request_units.pluck(:name).include?(item_request.request_unit)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we grab all the request_units at the top rather than doing a separate DB query per item here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed another alternative of switching to a set and adding rather than re-testing; avoids the extra DB call.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused - this avoids an extra DB call per item, but you're still doing a DB call per item. I think you might be missing an includes somewhere? Or am I reading this wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorner ok -- I followed some log/bullet.log advice and also watched the logs as I loaded this page. From that I sprinkled a few .includes around to pre load things. What do you think?

app/services/exports/export_request_service.rb Outdated Show resolved Hide resolved
spec/services/exports/export_request_service_spec.rb Outdated Show resolved Hide resolved
spec/services/exports/export_request_service_spec.rb Outdated Show resolved Hide resolved
@awwaiid awwaiid requested a review from dorner November 3, 2024 18:13
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last question.

cielf
cielf previously requested changes Nov 7, 2024
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran an export that seemed to work, then added a request for 1 box of pads. Then I exported again, and got a Type Error no implicit conversion from nil to integer. It failed at export_request_service.rb line 99, and it does look like it failed on the newly added item. I think headers_with_indexes might be to blame -- that there was a new item/unit combo, but headers_with_indexes was already defined, hence the boxes column header not defined, hence boom.

@awwaiid
Copy link
Collaborator Author

awwaiid commented Nov 25, 2024

@cielf Fixed the issue you ran into -- it was a case of qty 1 having a different pluralization than the header. I added a spec and fixed it.

@awwaiid awwaiid requested review from cielf and dorner November 25, 2024 03:21
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good on my end too!

@dorner dorner dismissed cielf’s stale review November 27, 2024 01:27

approved via comment

@dorner dorner merged commit 884b73a into main Nov 27, 2024
22 checks passed
@dorner dorner deleted the request-export-units branch November 27, 2024 01:28
Sukhpreet-s pushed a commit to Sukhpreet-s/human-essentials that referenced this pull request Nov 29, 2024
* Modify exporter to use real item_requests

* Include the units of the requested items

* Rename to more correct item_requests

* Reorganize and stupify spec

Use fixes specific values instead of calculated ones in most places

* Use dash to separate unit

* Re-arrange factory create a bit

* Create item_requests for realistic mock data

* Only add new export units when custom-units feature is enabled

* Handle the case where the item custom-unit was deleted later

* Fix request export for default-unit

* Use empty string for request unit in spec

* Extract common name_with_unit for request items

* Use set in item header calc to simplify duplicates

Also pluralize consistently

* Remove old commented out code

* Specify exact expected values

* Deal with pluralization conflict and update spec [rubyforgood#4405]

* Prefetch some data and clarify all_item_requests name [rubyforgood#4405]

* Change spec to send AR relation
Copy link
Contributor

github-actions bot commented Dec 1, 2024

@awwaiid: Your PR Bank Org Request Export - Include Custom Units is part of today's Human Essentials production release: 2024.12.01.
Thank you very much for your contribution!

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.

[PACKS] #10 Add custom request units to Request export
3 participants