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

a new invoice should refer the latest invoice. #11704

Merged

Conversation

abdellani
Copy link
Member

@abdellani abdellani commented Oct 24, 2023

What? Why?

What should we test?

One possible scenario:

  • Create an order
  • Generate an invoice
  • Check if the invoice is render correctly
  • Update the order (add a new item for example)
  • Generate a new invoice
  • Check if the the new invoice refer to the previous invoice
  • repeat the three last steps to see if the third invoice will refer to the second invoice

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
Copy link
Member Author

this PR is based on #11696

@abdellani abdellani self-assigned this Oct 24, 2023
@abdellani abdellani force-pushed the add-reference-to-previous-invoices branch from 28a9bb6 to 5723644 Compare November 13, 2023 06:37
@abdellani abdellani force-pushed the add-reference-to-previous-invoices branch 2 times, most recently from ca424c4 to ff2fd99 Compare November 28, 2023 15:28
@abdellani abdellani marked this pull request as ready for review November 28, 2023 15:28
@abdellani abdellani force-pushed the add-reference-to-previous-invoices branch from ff2fd99 to 915afd8 Compare December 11, 2023 07:27
@dacook dacook self-requested a review December 11, 2023 23:06
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, a straightforward addition to the invoices template.

I have a few suggestions, but I think they're non-essential so will approve 👍

@@ -30,4 +30,8 @@ def cancel_previous_invoices
def display_number
"#{order.distributor.id}-#{number}"
end

def previous_invoice
order.invoices.where("id < ?", id).first
Copy link
Member

Choose a reason for hiding this comment

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

If an order can have more that one previous invoice, we should use ordering to make sure it's the most recent one.

Copy link
Member

Choose a reason for hiding this comment

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

I'm intrigued to see that the spec does cover this. But it still seems worth making it explicit here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @dacook
Invoices are sorted by default as follows:

default_scope { order(created_at: :desc) }

@@ -46,6 +46,8 @@
%br
= "#{t :invoice_number}:"
= @order.display_number
- if @order.previous_invoice.present?
= "#{t :invoice_cancel_and_replace_invoice} #{ @order.previous_invoice.display_number}"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it will matter in other languages, but just in case I'd suggest using interpolation here, just in case some translations want to write something like
"cancels and replaces number %{canceled_invoice_number} invoice."

context "Order doesn't have previous invoices" do
it "should display the invoice number" do
login_as_admin
visit spree.print_admin_order_path(order, params: {})
Copy link
Member

Choose a reason for hiding this comment

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

probably can leave out params: {} (also below)

@@ -1991,6 +1991,7 @@ en:
invoice_column_price_per_unit_without_taxes: "Price Per unit (Excl. tax)"
invoice_column_tax_rate: "Tax rate"
invoice_tax_total: "GST Total:"
invoice_cancel_and_replace_invoice: "cancels and replaces invoice"
Copy link
Member

Choose a reason for hiding this comment

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

I just realised that these invoice keys could be scoped under a namespace.

Copy link
Collaborator

@rioug rioug 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 👍

@RachL RachL added the pr-staged-fr staging.coopcircuits.fr label Dec 14, 2023
@RachL
Copy link
Contributor

RachL commented Dec 14, 2023

This is looking good! I noticed some other bugs while testing, but not linked to this PR so will open new issues - merging :)

@RachL RachL removed the pr-staged-fr staging.coopcircuits.fr label Dec 14, 2023
@RachL RachL merged commit 9d87449 into openfoodfoundation:master Dec 14, 2023
52 checks passed
@RachL RachL added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Jan 5, 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
Archived in project
Development

Successfully merging this pull request may close these issues.

[Invoice numbers] When a new invoice cancel a previous one, keep a reference to the previous invoice number
4 participants