spree-contrib / spree_print_invoice

Create a PDF invoice for Spree orders.
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
91 stars 239 forks source link

New Model: Spree::BookkeepingDocuments #87

Closed mamhoff closed 9 years ago

mamhoff commented 9 years ago

This has turned into this massive exercise of trying to make spree_print_invoice more flexible by allowing it to print not only invoices for Orders, but also for other models like Reimbursements. The architecture really allows for any object to be made printable - a notable candidate would be packaging slips for Spree::Shipments.

At the moment, the views and templates for other things than order-invoices and order-packagingslips are not provided as they're not fully tested. They'll come at a later stage. OK? :)

tvdeyen commented 9 years ago

Unfortunately Travis realized there's been a change :)

Could you please look into the error and push again?

Thanks

tvdeyen commented 9 years ago

Besides that 👍

futhr commented 9 years ago

+1

tvdeyen commented 9 years ago

@mamhoff I just saw, that you added the switch to prawn-rails into this PR as well. I think it would be better to separate this from the rest. What do you think?

mamhoff commented 9 years ago

@tvdeyen No - I need prawn-rails for refactoring the views, and without that, the new model doesn't really have that much of a point (I need invoices for different kinds of things, and for that I need clean, maintainable views). So I'd rather make a PR that's actually a complete feature.

mamhoff commented 9 years ago

This has turned into a massive exercise. The API now definitely has changed, and the behaviour of the Gem as well. I've been debating with myself (and with @tvdeyen) whether this still makes sense as a PR, or whether it actually constitutes a fork and thus should be named differently.

What has changed in a Nutshell?

@alepore, @futhr, @lucaferri what do you think?

futhr commented 9 years ago

@mamhoff :+1: Everything has to move on and adapt to production active use cases (like the speech dhh made about Rails 5 at RailsConf Atlanta), the only important part when it comes to new features and refactor is to make it migratable.

alepore commented 9 years ago

@mamhoff very good stuff, thanks for this. i see this is now more than just "spree print invoice" , maybe some code could become a separate "spree pdf" gem?

lucaferri commented 9 years ago

I agree with @alepore because when I read

A Spree::Pdf is a new model that leverages view objects to make PDFs of arbitrary Spree objects (Order, Reimbursement, Shipment, you name it).

I thought that it's not a _spree_printinvoice gem anymore but it's evolving to something else, something more generic.

futhr commented 9 years ago

Well it still does the same thing as before just better and more dynamic. spree_print_invoice has always been a confusing name because it evolved from just handle invoices years ago. Continue on a cloned superseded repo as spree_pdf could ofc make it more declarative.

mamhoff commented 9 years ago

I'll push more yak-shaving tomorrow (so good!), which will do the following:

I'm also providing - albeit deprecated - methods on Spree::Order that will mimic class spree_print_invoice behaviour, so the upgrade path is as painless as possible.

@futhr absolutely, same thing as before, just more dynamic (thank you for the "better"). Also, the whole thing clearly owes a lot of history to spree_print_invoice. I would not mind keeping the name, but I would find spree_bookkeeping_documents quite declarative (albeit long)

tvdeyen commented 9 years ago

:+1: * :100: from me :cake:

mamhoff commented 9 years ago

@futhr ready to merge.

futhr commented 9 years ago

@mamhoff Interesting that Travis CI returns green specs even if I clear Travis cache, I try to run this locally and get dependencies issues with sass_rails that currently use ~> 4.0.0 https://github.com/spree-contrib/spree_print_invoice/blob/master/spree-print-invoice.gemspec#L36 while Spree use ~> 5.0.0 https://github.com/spree/spree/blob/5c6d69dfed60722b89f5d42d63707ad00e3db1c2/common_spree_dependencies.rb#L7 resolving the dependency issues gives 2-5 failed specs that occur randomly. The most common failures are:

1) Admin print invoice feature with Config.store_pdf set to true with pdf file not yet present sends the stored file.
     Failure/Error: visit spree.admin_bookkeeping_document_path(id: order.invoice.id, format: :pdf)
     ActionView::Template::Error:
       no implicit conversion of Sprockets::Asset into String

2) Admin print invoice feature with Config.store_pdf set to false sends rendered pdf.
     Failure/Error: visit spree.admin_bookkeeping_document_path(id: order.invoice.id, format: :pdf)
     ActionView::Template::Error:
       no implicit conversion of Sprockets::Asset into String
mamhoff commented 9 years ago

Nice find - I should've run bundle update first. Turns out the preferences cache is not cleared between tests, which is why you were having spurious tests. And: Whenever the logo was valid, the interface for Sprockets::Asset seems to have changed.

mamhoff commented 9 years ago

I increased the scale on the total column to allow for values > 999,99 and rebased.

futhr commented 9 years ago

@mamhoff Merged to master branch, nice work.

tvdeyen commented 9 years ago

🍻

catalin88 commented 7 years ago

So, where can I find an example with a Pdf generated when a Reimbursement is issued ? Seems like the current version of the gem doesn't provide this, yet, in this discussion, it's said numerous times it does produce Pdf for Reimbursements