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

prevent generating invoices when order's distributor can't generate invoices #12219

Conversation

abdellani
Copy link
Member

What? Why?

When I worked on this PR, we accidentally discovered that it's possible to generate invoices while the order's distributor can't generate invoices.
Check the following comments for more details:
#11918 (comment)
#11918 (comment)

What should we test?

  1. open enterprise configuration for a distributor D1
  2. enable taxes
  3. set an ABN
  4. open another tab (let's call it TAB2)
  5. open an order that belongs to D1
  6. open invoices
    image
  7. return to the previous TAB1
  8. remove the ABN and save
  9. return to TAB2
  10. click on ACTIONS/PRINT
  11. you should get a notification saying that "D1 must have a valid ABN before invoices can be used."
    image

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@abdellani abdellani force-pushed the prevent-generate-invoices-when-distributor-cannot-invoice branch from 0ba4fe0 to ee1f608 Compare February 29, 2024 17:57
Comment on lines 22 to 28
authorize! :invoice, @order
OrderInvoiceGenerator.new(@order).generate_or_update_latest_invoice
if @order.distributor.can_invoice?
authorize! :invoice, @order
OrderInvoiceGenerator.new(@order).generate_or_update_latest_invoice
else
flash[:error] = t(:must_have_valid_business_number,
enterprise_name: @order.distributor.name)
end
Copy link
Member

Choose a reason for hiding this comment

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

My first thought was why we don't include that check in the Abilities class to have one source of truth. But that wouldn't provide us with a good error message. I guess that's one downside of CanCan.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

👍 Great

@drummer83 drummer83 self-assigned this Mar 14, 2024
@drummer83 drummer83 added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Mar 14, 2024
@drummer83 drummer83 removed their assignment Mar 18, 2024
@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Mar 18, 2024
@drummer83
Copy link
Contributor

Hi @abdellani,
We have a conflict here now. Probably from merging the previous PR around this topic?
Could you please have a look?
Thanks!

@sigmundpetersen sigmundpetersen added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Mar 22, 2024
@abdellani
Copy link
Member Author

conflict resolved.

@abdellani abdellani requested review from mkllnk and dacook April 22, 2024 10:07
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Thanks

@RachL RachL self-assigned this Apr 24, 2024
@RachL RachL added the pr-staged-fr staging.coopcircuits.fr label Apr 24, 2024
@RachL
Copy link
Contributor

RachL commented Apr 25, 2024

Sorry for taking this long to test this one, I took the time to test other invoices related stuf - will open some issues about them #neverendingstory

This PR is ready to go! The message looks nice in the new v3 style :)

image

@RachL RachL merged commit 09354dc into openfoodfoundation:master Apr 25, 2024
52 checks passed
@RachL RachL removed the pr-staged-fr staging.coopcircuits.fr label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants