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

spree 4.7 #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/spree/bookkeeping_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def storage_path
#
def render_pdf
ApplicationController.render(
template: "#{template_name}.pdf.prawn",
template: template_name,
formats: [:pdf],
assigns: { doc: self }
)
end
Expand Down
50 changes: 0 additions & 50 deletions app/models/spree/order_decorator.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module SpreePrintInvoice

Choose a reason for hiding this comment

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

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

module Admin
module MainMenu
class PrintInvoiceBuilder

Choose a reason for hiding this comment

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

Style/Documentation: Missing top-level class documentation comment.

include ::Spree::Core::Engine.routes.url_helpers

def build

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for build is too high. [21.02/15]
Metrics/MethodLength: Method has too many lines. [17/10]

items = [
::Spree::Admin::MainMenu::ItemBuilder.new('invoices', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'invoice' })).

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [172/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

with_label_translation_key('admin.invoices').

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_manage_ability_check(::Spree::BookkeepingDocument).

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=invoice').

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [83/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

build,
::Spree::Admin::MainMenu::ItemBuilder.new('packaging_slips', ::Spree::Core::Engine.routes.url_helpers.admin_bookkeeping_documents_path(q: { template_eq: 'packaging_slip' })).

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [186/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

with_label_translation_key('admin.packaging_slips').

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_manage_ability_check(::Spree::BookkeepingDocument).

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_match_path('/bookkeeping_documents?q%5Btemplate_eq%5D=packaging_slip').

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [90/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

build
]

::Spree::Admin::MainMenu::SectionBuilder.new('documents', 'file.svg').

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_manage_ability_check(::Spree::BookkeepingDocument).

Choose a reason for hiding this comment

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

Layout/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.
Layout/DotPosition: Place the . on the next line, together with the method name.

with_label_translation_key('admin.documents').

Choose a reason for hiding this comment

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

Layout/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.
Layout/DotPosition: Place the . on the next line, together with the method name.

with_items(items).

Choose a reason for hiding this comment

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

Layout/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.
Layout/DotPosition: Place the . on the next line, together with the method name.

build

Choose a reason for hiding this comment

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

Layout/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

end
end
end
end
end
51 changes: 51 additions & 0 deletions app/models/spree_print_invoice/spree/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module SpreePrintInvoice

Choose a reason for hiding this comment

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

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

module Spree
module OrderDecorator

Choose a reason for hiding this comment

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

Style/Documentation: Missing top-level module documentation comment.

def self.prepended(base)
base.has_many :bookkeeping_documents, as: :printable, dependent: :destroy

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [81/80]

base.has_one :invoice, -> { where(template: 'invoice') },
class_name: 'Spree::BookkeepingDocument',
as: :printable
base.has_one :packaging_slip, -> { where(template: 'packaging_slip') },
class_name: 'Spree::BookkeepingDocument',
as: :printable

base.delegate :number, :date, to: :invoice, prefix: true

# Create a new invoice before transitioning to complete
#
base.state_machine.before_transition to: :complete, do: :invoice_for_order

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [82/80]

end

# Backwards compatibility stuff. Please don't use these methods, rather use the

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [85/80]

# ones on Spree::BookkeepingDocument
#
def pdf_file
ActiveSupport::Deprecation.warn('This API has changed: Please use order.invoice.pdf instead')

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [101/80]

invoice.pdf
end

def pdf_filename
ActiveSupport::Deprecation.warn('This API has changed: Please use order.invoice.file_name instead')

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [107/80]

invoice.file_name
end

def pdf_file_path
ActiveSupport::Deprecation.warn('This API has changed: Please use order.invoice.pdf_file_path instead')

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [111/80]

invoice.pdf_file_path
end

def pdf_storage_path(template)
ActiveSupport::Deprecation.warn('This API has changed: Please use order.{packaging_slip, invoice}.pdf_file_path instead')

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [129/80]

bookkeeping_documents.find_by!(template: template).file_path
end

def invoice_for_order
bookkeeping_documents.create(template: 'invoice')
bookkeeping_documents.create(template: 'packaging_slip')
end
end
end
end

::Spree::Order.prepend ::SpreePrintInvoice::Spree::OrderDecorator
17 changes: 0 additions & 17 deletions app/overrides/add_documents_to_main_navigation.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/overrides/add_print_invoice_links_to_admin_order_tabs.rb

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/spree/admin/print_invoice_settings/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<fieldset class="no-border-bottom">
<legend><%= Spree.t(:pdf_legend, scope: :print_invoice) %></legend>

<div class="form-group">
<div class="form-group ml-4">
<div class="checkbox">
<%= label_tag :use_footer do %>
<%= preference_field_tag(:use_footer, Spree::PrintInvoice::Config[:use_footer], type: :boolean) %>
Expand Down Expand Up @@ -61,7 +61,7 @@
<%= number_field_tag(:logo_scale, Spree::PrintInvoice::Config[:logo_scale], in: 1...101, class: 'form-control') %>
</div>

<div class="form-group">
<div class="form-group ml-4">
<div class="checkbox">
<%= label_tag :store_pdf do %>
<%= preference_field_tag(:store_pdf, Spree::PrintInvoice::Config[:store_pdf], type: :boolean) %>
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/spree/printables/shared/_header.pdf.prawn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
im = (Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application)).find_asset(Spree::PrintInvoice::Config[:logo_path])

if im && File.exist?(im.pathname)
if im && File.exist?(im.filename)
pdf.image im.filename, vposition: :top, height: 40, scale: Spree::PrintInvoice::Config[:logo_scale]
end

Expand Down
18 changes: 18 additions & 0 deletions config/initializers/print_invoice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Rails.application.config.after_initialize do
if Spree::Core::Engine.backend_available?
Rails.application.config.spree_backend.main_menu.insert_after('dashboard', ::SpreePrintInvoice::Admin::MainMenu::PrintInvoiceBuilder.new.build)

Rails.application.config.spree_backend.tabs[:order].add(
::Spree::Admin::Tabs::TabBuilder.new(::Spree.t(:documents, scope: [:print_invoice]), ->(resource) { ::Spree::Core::Engine.routes.url_helpers.admin_order_bookkeeping_documents_path(resource) }).

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [199/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

with_icon_key('file.svg').

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

with_active_check.

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

build
)

Rails.application.config.spree_backend.main_menu.add_to_section('settings',

Choose a reason for hiding this comment

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

Layout/IndentationConsistency: Inconsistent indentation detected.

::Spree::Admin::MainMenu::ItemBuilder.new('print_invoice.settings', ::Spree::Core::Engine.routes.url_helpers.edit_admin_print_invoice_settings_path).

Choose a reason for hiding this comment

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

Layout/AlignParameters: Align the parameters of a method call if they span more than one line.
Metrics/LineLength: Line is too long. [155/80]
Layout/DotPosition: Place the . on the next line, together with the method name.

with_manage_ability_check(::Spree::BookkeepingDocument).

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the next line, together with the method name.

build
)

Choose a reason for hiding this comment

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

Layout/ClosingParenthesisIndentation: Align ) with (.
Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the same line as the last argument when opening brace is on the same line as the first argument.

end
end
2 changes: 2 additions & 0 deletions lib/spree_print_invoice/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../spree/print_invoice_setting'

module SpreePrintInvoice
class Engine < Rails::Engine
require 'spree/core'
Expand Down