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

Add payment details to invoice #5712

Merged
merged 10 commits into from
Aug 27, 2020
Merged

Conversation

mbudm
Copy link

@mbudm mbudm commented Jul 1, 2020

What? Why?

Closes #5208

Add more detail on payment history to invoices. This helps to clarify the invoice when the status is balance due or credit owing.

Concerns/possible changes are:

  • the payment partial is in the order_mailer view. The change will apply to other templates using this partial (emailed invoices?) I need to clarify if this expected/desired.
  • I added the css for the payments table to the same scss file where the invoice table is defined, app/assets/stylesheets/mail/email.scss which feels a bit like a dumping ground - should we create a separate scss file for the invoice styles?
  • I'm not sure about the column alignment, I've suggested in the issue that the amount column is moved to the right of the payment method column, for better balance and easier scanning of the figures
  • If there are no payments, should the info currently added to the invoice be shown? Also I'm unsure if there are ever orders without payments, as a checkout must occur for an order to appear?

What should we test?

Detailed steps to recreate are in the issue: #5208

  • create an order that is balance due or credit owing
  • print the invoice
  • the balance due or credit owing state is shown, including the amount. the payment history is also shown

Screen Shot 2020-07-01 at 10 46 35 am

A paid (completed) order - with a failed credit card attempt:
Screen Shot 2020-07-01 at 12 16 28 pm

Release notes

  • Changed order invoices where balance owing or credit due, with details on payment history

Changelog Category: Changed

@mbudm mbudm changed the title Add more details on payments to invoice. Add payment details to invoice Jul 1, 2020
@sigmundpetersen
Copy link
Contributor

sigmundpetersen commented Jul 1, 2020

FYI those failing enterprise_controller specs are also in master and will be fixed by #5706 , so you shouldn't worry about them 👍

@mbudm
Copy link
Author

mbudm commented Jul 1, 2020

Thanks @sigmundpetersen - I think the failing ./spec/mailers/subscription_mailer_spec.rb are on this change though so will review that tomorrow

Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

Nice one!

I think it's messy that the invoice templates are under orders, they should be a separate controller and views folder. And then it would be ok to have a dependency to the order_mailer... but this is not in scope for this PR.

I leave some comments below.

app/views/spree/admin/orders/_list.html.haml Outdated Show resolved Hide resolved
app/views/spree/admin/orders/_list.html.haml Outdated Show resolved Hide resolved
app/views/spree/admin/orders/_list.html.haml Outdated Show resolved Hide resolved
app/views/spree/admin/orders/_list.html.haml Outdated Show resolved Hide resolved
app/views/spree/order_mailer/_payment.html.haml Outdated Show resolved Hide resolved
app/views/spree/order_mailer/_payment.html.haml Outdated Show resolved Hide resolved
app/views/spree/order_mailer/_payment.html.haml Outdated Show resolved Hide resolved
@mbudm
Copy link
Author

mbudm commented Jul 7, 2020

Updated screenshots - changed the column order as discussed in the issue #5208 - invoice PDF:

Screen Shot 2020-07-07 at 10 29 54 pm

Confirmation email:
Screen Shot 2020-07-07 at 9 59 35 pm

And as it is affected by the addition of a helper, checking that the payments page is unchanged:
Screen Shot 2020-07-07 at 10 01 40 pm

@@ -4,4 +4,8 @@ module OrderHelper
def last_payment_method(order)
OrderPaymentFinder.new(order).last_payment&.payment_method
end

def outstanding_balance_label(order)
Copy link
Author

Choose a reason for hiding this comment

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

@luisramos0 you mentioned extracting this logic to a service but it looked to me like it's more a helper type of thing...?

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand if you call it a label, I think this is more like a state. This the balance state of the order. This is something that will/could be needed in different places (the api for example) not just views. I see it as business logic that belongs in the service layer.
I think it's important we move all logic to services out of the MVC. This is something we have been doing lately in OFN and it's really good that we have thinner helpers/controllers/models and an organized service layer.
Anyway, I think this is an acceptable solution!

@@ -3,6 +3,7 @@
helper CheckoutHelper
helper SpreeCurrencyHelper
helper OrderHelper
helper Spree::Admin::PaymentsHelper
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if there's an issue with bringing in yet more helpers here

@mbudm
Copy link
Author

mbudm commented Jul 7, 2020

Almost forgot invoice2:

Screen Shot 2020-07-07 at 10 46 33 pm

Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

Great!

Should I move this partial to app/views/spree/admin/shared?

app/views/spree/shared is fine 👍 ideally I'd prefer to see it outside the spree space, app/views/shared or app/views/admin/shared. Anyway, it's good as is 👍

I'm pretty sure we don't want the Spree based pretty_time method in more places, is there an alternate time formatter/technique we prefer that doesn't depend on Spree?

I dont know what's the best way to format a time BUT I dont see a problem of using spree code, as part of "bye bye spree" we will bring all the code we need from spree. base_helper is still on the spree side with a decorator on our side but we can definitely bring pretty_time to OFN and even improve it. I'd say let's use pretty time and improve it.

why is the order_mailer outside the admin dir anyway? Isn't it part of the orders admin form?

I am not sure why but all the spree mailers are outside admin. They are part of spree_core not spree_backend (which really is spree/admin).

@@ -4,4 +4,8 @@ module OrderHelper
def last_payment_method(order)
OrderPaymentFinder.new(order).last_payment&.payment_method
end

def outstanding_balance_label(order)
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand if you call it a label, I think this is more like a state. This the balance state of the order. This is something that will/could be needed in different places (the api for example) not just views. I see it as business logic that belongs in the service layer.
I think it's important we move all logic to services out of the MVC. This is something we have been doing lately in OFN and it's really good that we have thinner helpers/controllers/models and an organized service layer.
Anyway, I think this is an acceptable solution!

app/assets/stylesheets/mail/payment_list.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

oh, the build still has some relevant broken specs.

@mbudm
Copy link
Author

mbudm commented Jul 7, 2020

oh, the build still has some relevant broken specs.

OK cool - I let them all run last night after doing some adhoc test runs locally, wasn't sure if the /spec/mailers/subscription_mailer_spec.rb was correlation or causation, i.e it was the right area but I wasn't clear how these changes had affected it - will investigate more deeply today.

EDIT: Yay for tests. The change moving payments partial to shared has wider impact that I first realised, so this is something we'd need to add in the test plan.

Impacted emails are:

  • app/views/subscription_mailer/confirmation_email.html.haml
  • app/views/subscription_mailer/placement_email.html.haml
  • app/views/spree/order_mailer/confirm_email_for_shop.html.haml
  • app/views/spree/order_mailer/confirm_email_for_customer.html.haml

Impacted invoice pdfs are:

  • app/views/spree/admin/orders/invoice2.html.haml
  • app/views/spree/admin/orders/invoice.html.haml

@mbudm
Copy link
Author

mbudm commented Jul 8, 2020

One remaining failure on semaphore passes locally: spec/models/variant_override_spec.rb

Reran the build and it failed again. Locally it works reliably - not sure what to do here.

Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

yeah, that's it, well done!
We need to fix these flaky specs, not on this PR....

@filipefurtad0 filipefurtad0 self-assigned this Jul 19, 2020
@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Jul 19, 2020
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Jul 19, 2020

Hi @mbudm ,

I verified the issue described and used the steps described in #5208 to test the PR.

I checked 4 cases, in which this information should be visible:

  • Bulk printing an invoice (pdf), on the Orders page (/admin/orders?q[s]=completed_at+desc)
  • the functions under order edit page, (/admin/orders/R422624534/edit)
    - Print invoice (pdf)
    - Send the invoice (pdf per email)
    - Resend (order confirmation) (email, no pdf)

Verified that the generated pdf documents above were identical in all cases.

  1. By printing/sending an invoice of a complete/paid order: we can that the PR introduces information about the payment history:
  • Order confirmation per email:

image

  • PDF-invoice:

image

An issue not introduced by this PR: It's noticeable from the pics above, that shipping instructions appear on the email with the order confirmation, but are missing from the PDF file.

  1. Removing an item from an order which is paid for (left side, before this PR, right side after this PR)

image

From the changes introduced by this PR, I would expected that "Credit Owed (£-12.00)" information would appear, somewhere in the area marked above. This is also not appearing in the order confirmation (email).

  1. Adding further items, and a second (insufficient) payment now appears as well:

image

This looks good for merging, thank you for these improvements!

Regarding the issues found:

  • Missing shipping instructions on PDF-invoices (an issue will be opened)
  • Missing Credit Owed (£-xx.xx) information on Email (order confirmation) and PDF-invoices: does this need a separate issue? Would it be papercut-size?

@filipefurtad0 filipefurtad0 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Jul 19, 2020
@luisramos0
Copy link
Contributor

Re the 2 issues:

Missing shipping instructions on PDF-invoices (an issue will be opened)

Why do you think this is an issue? is it not a feature request? are the delivery instructions necessary on the invoice? why?

Missing Credit Owed (£-xx.xx) information on Email (order confirmation) and PDF-invoices: does this need a separate issue? Would it be papercut-size?

I think this is a bug in this PR. I think it could be the translation label :credit_owner missing from the en.yml file.
I think we could let @mbudm had a quick look at this second point and if it's easy fix it in this PR. What do you think @filipefurtad0 ?

@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Jul 21, 2020

Hey @luisramos0,

Re the 2 issues:

        Missing shipping instructions on PDF-invoices (an issue will be opened)

Why do you think this is an issue? is it not a feature request? are the delivery instructions necessary on the invoice? why?

That's correct, that would be a feature request - not a bug. Invoice and order confirmation don't necessarily need the same info. Thanks!

    Missing Credit Owed (£-xx.xx) information on Email (order confirmation) and PDF-invoices: does this need a separate issue? Would it be papercut-size?

I think this is a bug in this PR. I think it could be the translation label :credit_owner missing from the en.yml file.
I think we could let @mbudm had a quick look at this second point and if it's easy fix it in this PR. What do you think @filipefurtad0 ?

Sounds good to me, especially knowing it's an easy fix. Moving back to In Dev 👍

Thanks again Luis!

@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Jul 21, 2020

Hey @luisramos0,

Re the 2 issues:

        Missing shipping instructions on PDF-invoices (an issue will be opened)

Why do you think this is an issue? is it not a feature request? are the delivery instructions necessary on the invoice? why?

That's correct, that would be a feature request - not a bug. Invoice and order confirmation don't necessarily need the same info. Thanks!

    Missing Credit Owed (£-xx.xx) information on Email (order confirmation) and PDF-invoices: does this need a separate issue? Would it be papercut-size?

I think this is a bug in this PR. I think it could be the translation label :credit_owner missing from the en.yml file.
I think we could let @mbudm had a quick look at this second point and if it's easy fix it in this PR. What do you think @filipefurtad0 ?

Sounds good to me, especially if looks like an easy fix. Would have a second look on it @mbudm? Moving back to In Dev 👍
Thanks again Luis!

@Matt-Yorkley
Copy link
Contributor

Rebased, resolved conflicts, and the missing "credit owed" display should now be fixed.

Steve Roberts and others added 9 commits August 20, 2020 17:16
- Partial is used by both the invoice pdf and the order confirmation email
- separate scss file for new payment list table
- extracted outstanding balance logic (also changed in payments view.. admin/orders/RXXX/payments)
- translations in shared.payments_list and lazy loaded
The `Spree::Order#paid?` method actually includes orders with `payment_state == "credit_owed"`, which was breaking the desired display logic here.
@luisramos0
Copy link
Contributor

I am moving to In Dev, I think it's worth doing the simple change I suggest now, ok Matt?
I think you can move to Test Ready directly afterwards 👍

@filipefurtad0 filipefurtad0 self-assigned this Aug 27, 2020
@filipefurtad0 filipefurtad0 added pr-staged-au staging.openfoodnetwork.org.au pr-staged-uk staging.openfoodnetwork.org.uk and removed pr-staged-au staging.openfoodnetwork.org.au labels Aug 27, 2020
@filipefurtad0
Copy link
Contributor

Thanks @Matt-Yorkley
the PR adds the "Credit Owed" info to the invoice:

image

Ready to go.

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.

Invoices display incorrect information about payments if order has been edited
6 participants