diff --git a/app/controllers/spree/admin/bookkeeping_documents_controller.rb b/app/controllers/spree/admin/bookkeeping_documents_controller.rb index fd074f83..5f8ef9a6 100644 --- a/app/controllers/spree/admin/bookkeeping_documents_controller.rb +++ b/app/controllers/spree/admin/bookkeeping_documents_controller.rb @@ -8,7 +8,10 @@ class BookkeepingDocumentsController < ResourceController def show respond_with(@bookkeeping_document) do |format| format.pdf do - send_data @bookkeeping_document.pdf, type: 'application/pdf', disposition: 'inline' + send_data @bookkeeping_document.pdf, + type: 'application/pdf', + disposition: 'inline', + filename: pdf_filename end end end @@ -39,6 +42,10 @@ def order_focused? def load_order @order = Spree::Order.find_by(number: params[:order_id]) end + + def pdf_filename + "#{@bookkeeping_document.template}_#{@bookkeeping_document.number}_#{@bookkeeping_document.printable.bill_address.firstname}_#{@bookkeeping_document.printable.completed_at.to_i}.pdf" + end end end end diff --git a/app/models/spree/bookkeeping_document.rb b/app/models/spree/bookkeeping_document.rb index bbe3c76e..b839920d 100644 --- a/app/models/spree/bookkeeping_document.rb +++ b/app/models/spree/bookkeeping_document.rb @@ -8,6 +8,10 @@ class BookkeepingDocument < ActiveRecord::Base :number ] + def self.ransackable_attributes(auth_object = nil) + ["created_at", "email", "firstname", "id", "id_value", "lastname", "number", "printable_id", "printable_type", "template", "total", "updated_at"] + end + # Spree::BookkeepingDocument cares about creating PDFs. Whenever it needs to know # anything about the document to send to the view, it asks a view object. # @@ -108,7 +112,8 @@ def storage_path # def render_pdf ApplicationController.render( - template: "#{template_name}.pdf.prawn", + template: template_name, + formats: [:pdf], assigns: { doc: self } ) end diff --git a/app/models/spree_print_invoice/admin/main_menu/print_invoice_builder.rb b/app/models/spree_print_invoice/admin/main_menu/print_invoice_builder.rb new file mode 100644 index 00000000..5bd633eb --- /dev/null +++ b/app/models/spree_print_invoice/admin/main_menu/print_invoice_builder.rb @@ -0,0 +1,30 @@ +module SpreePrintInvoice + module Admin + module MainMenu + class PrintInvoiceBuilder + include ::Spree::Core::Engine.routes.url_helpers + + def build + items = [ + ::Spree::Admin::MainMenu::ItemBuilder.new('invoices', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'invoice' })). + with_label_translation_key('admin.tab.invoices'). + with_manage_ability_check(::Spree::BookkeepingDocument). + with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=invoice'). + build, + ::Spree::Admin::MainMenu::ItemBuilder.new('packaging_slips', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'packaging_slip' })). + with_label_translation_key('admin.tab.packaging_slips'). + with_manage_ability_check(::Spree::BookkeepingDocument). + with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=packaging_slip'). + build + ] + + ::Spree::Admin::MainMenu::SectionBuilder.new('documents', 'file.svg'). + with_manage_ability_check(::Spree::BookkeepingDocument). + with_label_translation_key('admin.documents'). + with_items(items). + build + end + end + end + end +end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree_print_invoice/order_decorator.rb similarity index 89% rename from app/models/spree/order_decorator.rb rename to app/models/spree_print_invoice/order_decorator.rb index e6bed8d1..bc5e65cb 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree_print_invoice/order_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Spree +module SpreePrintInvoice module OrderDecorator def self.prepended(base) base.has_many :bookkeeping_documents, as: :printable, dependent: :destroy @@ -42,9 +42,11 @@ def pdf_storage_path(template) end def invoice_for_order + return if bookkeeping_documents.exists?(template: 'invoice') && bookkeeping_documents.exists?(template: 'packaging_slip') bookkeeping_documents.create(template: 'invoice') bookkeeping_documents.create(template: 'packaging_slip') end end end -::Spree::Order.prepend Spree::OrderDecorator \ No newline at end of file + +::Spree::Order.prepend SpreePrintInvoice::OrderDecorator diff --git a/app/overrides/add_documents_to_main_navigation.rb b/app/overrides/add_documents_to_main_navigation.rb deleted file mode 100644 index cc514835..00000000 --- a/app/overrides/add_documents_to_main_navigation.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -if Spree.version.to_f < 4.0 - Deface::Override.new( - virtual_path: 'spree/layouts/admin', - insert_bottom: '#main-sidebar', - partial: 'spree/admin/shared/menu/documents_tab', - name: 'documents_tab' - ) -else - Deface::Override.new( - virtual_path: 'spree/admin/shared/_main_menu', - insert_bottom: 'nav', - partial: 'spree/admin/shared/menu/documents_tab', - name: 'documents_tab' - ) -end diff --git a/app/overrides/add_print_invoice_links_to_admin_order_tabs.rb b/app/overrides/add_print_invoice_links_to_admin_order_tabs.rb deleted file mode 100644 index cf7382df..00000000 --- a/app/overrides/add_print_invoice_links_to_admin_order_tabs.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -Deface::Override.new( - virtual_path: 'spree/admin/shared/_order_tabs', - name: 'print_invoice_order_tab_links', - insert_bottom: '[data-hook="admin_order_tabs"]', - partial: 'spree/admin/orders/print_invoice_order_tab_links' -) diff --git a/app/overrides/add_print_invoice_to_admin_configuration_sidebar.rb b/app/overrides/add_print_invoice_to_admin_configuration_sidebar.rb deleted file mode 100644 index 9c143549..00000000 --- a/app/overrides/add_print_invoice_to_admin_configuration_sidebar.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -Deface::Override.new( - virtual_path: 'spree/admin/shared/sub_menu/_configuration', - name: 'print_invoice_admin_configurations_menu', - insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]', - text: '<%= configurations_sidebar_menu_item Spree.t(:settings, scope: :print_invoice), - spree.edit_admin_print_invoice_settings_path %>' -) diff --git a/app/views/spree/admin/orders/_print_invoice_order_tab_links.html.erb b/app/views/spree/admin/orders/_print_invoice_order_tab_links.html.erb deleted file mode 100755 index ccc6a9d2..00000000 --- a/app/views/spree/admin/orders/_print_invoice_order_tab_links.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% if can? :show, Spree::Order %> - <% if @order && @order.completed_at? %> -