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

IN PROGRESS Barcode ajax #119

Merged
merged 14 commits into from Aug 11, 2017
Merged

IN PROGRESS Barcode ajax #119

merged 14 commits into from Aug 11, 2017

Conversation

armahillo
Copy link
Collaborator

To test it:

Go to /donations/new - put the mouse in the really wide field and enter a barcode string (a bunch of numbers) and press enter. Alternately just use an actual barcode reader.

Watch the console log for output.

Weird behavior:
The first time you try using it, it won't do anything, but the second time (when it shows error messages) it will work. Not sure why it's doing this.

the data object that gets returned should have the @barcode_item.to_json in it, but I don't see that coming up in the inspector.

TODO:
wire up success / failure functions to hook into the workflow. Ideally, this whole process should be generalized enough that we can drop it in for Donation, Distribution, Transfer, Adjustments

…ng). Adds .combine! method to the line_items association in Donation, that combines all line_items with the same item_id. There's spec coverage for it too, at both model and feature levels. Barcode entry now works a lot more as you would expect!
@armahillo
Copy link
Collaborator Author

Fixes #21

This is ready to be reviewed, @seanmarcia @cattywampus

@armahillo armahillo requested review from cattywampus and seanmarcia and removed request for cattywampus August 9, 2017 19:52
@seanmarcia
Copy link
Member

I'll review tonight unless someone else beats me to it!

@armahillo
Copy link
Collaborator Author

armahillo commented Aug 9, 2017 via email

…emove if there is an empty line item. This way if they are scanning in things they dont have to make sure to remove the empty created one from the bar code scanner.
@seanmarcia
Copy link
Member

LGTM! I added in a couple tweaks for bar code scanning so it doesn't error out if there is an empty line item at the end. (The line item that would be create from the bar code scanner.

@seanmarcia
Copy link
Member

Also, I commented out a test that I don't think we need anymore. By adding in the proc to reject line_items before they are even created I don't think we need this anymore:

scenario "items dropdown is still repopulated even if initial submission doesn't validate" do
  item_count = @organization.items.count + 1  # Adds 1 for the "choose an item" option
  expect(page).to have_xpath("//select[@id='donation_line_items_attributes_0_item_id']/option", count: item_count)
  click_button "Create Donation"

  expect(page).to have_content("error")
  expect(page).to have_xpath("//select[@id='donation_line_items_attributes_0_item_id']/option", count: item_count)
end

The proc on accepts_nested_attributes I'm talking about is:

  accepts_nested_attributes_for :line_items,
    allow_destroy: true,
    :reject_if => proc { |li| li[:item_id].blank? && li[:quantity].blank? }

@seanmarcia
Copy link
Member

Now that I think about it, maybe it should be:
:reject_if => proc { |li| li[:item_id].blank? || li[:quantity].blank? }

@armahillo
Copy link
Collaborator Author

I re-added the spec -- it was failing because when the line item is rejected, the resulting form has zero line items while still displaying an error message.

I just re-added a "line_items.build" to the error block if it has no line_items and that fixed the problem.

@armahillo armahillo merged commit f5c1dde into master Aug 11, 2017
@armahillo armahillo deleted the barcode-ajax branch August 11, 2017 02:43
@seanmarcia
Copy link
Member

👍

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.

None yet

2 participants