Merge pull request #10420 from anansilva/9311-remove-code-generating-receipts

Remove code generating receipts
This commit is contained in:
Filipe
2023-02-20 12:44:13 +00:00
committed by GitHub
21 changed files with 11 additions and 9485 deletions

View File

@@ -839,7 +839,6 @@ Rails/OutputSafety:
- 'lib/reporting/queries/query_builder.rb'
- 'lib/reporting/queries/query_interface.rb'
- 'lib/spree/money.rb'
- 'spec/system/admin/order_print_ticket_spec.rb'
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).

View File

@@ -125,8 +125,6 @@ gem 'jquery-rails', '4.4.0'
gem 'jquery-ui-rails', '~> 4.2'
gem "select2-rails", github: "openfoodfoundation/select2-rails", branch: "v349_with_thor_v1"
gem 'ofn-qz', github: 'openfoodfoundation/ofn-qz', branch: 'ofn-rails-4'
gem 'good_migrations'
gem 'flipper'

View File

@@ -8,13 +8,6 @@ GIT
fog-core (~> 1.0)
rails (>= 3.2.0, < 7.0)
GIT
remote: https://github.com/openfoodfoundation/ofn-qz.git
revision: 467f6ea1c44529c7c91cac4c8211bbd863588c0b
branch: ofn-rails-4
specs:
ofn-qz (0.1.0)
GIT
remote: https://github.com/openfoodfoundation/select2-rails.git
revision: fc240e85fbdf1878ff3c39d972c0cd9a312f5ed4
@@ -840,7 +833,6 @@ DEPENDENCIES
mini_racer
monetize (~> 1.11)
oauth2 (~> 1.4.7)
ofn-qz!
omniauth-rails_csrf_protection
omniauth_openid_connect
openid_connect (~> 1.3)

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,6 @@ module Admin
params.require(:preferences).permit(
:enable_invoices?,
:invoice_style2?,
:enable_receipt_printing?,
:enterprise_number_required_on_invoices?,
)
end

View File

@@ -9,15 +9,13 @@ module Spree
helper CheckoutHelper
before_action :load_order, only: [:edit, :update, :fire, :resend,
:invoice, :print, :print_ticket]
:invoice, :print]
before_action :load_distribution_choices, only: [:new, :edit, :update]
# Ensure that the distributor is set for an order when
before_action :ensure_distribution, only: :new
before_action :require_distributor_abn, only: :invoice
content_security_policy false, only: :print_ticket
respond_to :html, :json
def new
@@ -117,10 +115,6 @@ module Spree
render_with_wicked_pdf InvoiceRenderer.new.args(@order)
end
def print_ticket
render template: "spree/admin/orders/ticket", layout: false
end
private
def order_params

View File

@@ -27,7 +27,7 @@ module Spree
private
def complete_order_links
[resend_confirmation_link] + invoice_links + ticket_links
[resend_confirmation_link] + invoice_links
end
def invoice_links
@@ -52,12 +52,6 @@ module Spree
end
end
def ticket_links
return [] unless Spree::Config[:enable_receipt_printing?]
[print_ticket_link, select_ticket_printer_link]
end
def edit_order_link
{ name: t(:edit_order),
url: spree.edit_admin_order_path(@order),
@@ -100,20 +94,6 @@ module Spree
confirm: t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) }
end
def print_ticket_link
{ name: t(:print_ticket),
url: print_ticket_admin_order_path(@order),
icon: 'icon-print',
target: "_blank" }
end
def select_ticket_printer_link
{ name: t(:select_ticket_printer),
url: "#{print_ticket_admin_order_path(@order)}#select-printer",
icon: 'icon-print',
target: "_blank" }
end
def ship_order_link
{ name: t(:ship_order),
url: spree.fire_admin_order_path(@order, e: 'ship'),

View File

@@ -263,7 +263,7 @@ module Spree
def add_order_management_abilities(user)
can [:index, :create], Spree::Order
can [:read, :update, :fire, :resend, :invoice, :print, :print_ticket], Spree::Order do |order|
can [:read, :update, :fire, :resend, :invoice, :print], Spree::Order do |order|
# We allow editing orders with a nil distributor as this state occurs
# during the order creation process from the admin backend
order.distributor.nil? ||

View File

@@ -123,10 +123,9 @@ module Spree
preference :matomo_site_id, :string, default: nil
preference :matomo_tag_manager_url, :string, default: nil
# Invoices & Receipts
# Invoices
preference :enable_invoices?, :boolean, default: true
preference :invoice_style2?, :boolean, default: false
preference :enable_receipt_printing?, :boolean, default: false
preference :enterprise_number_required_on_invoices?, :boolean, default: true
# Stripe payments

View File

@@ -15,11 +15,6 @@
= check_box_tag 'preferences[invoice_style2?]', '1', Spree::Config[:invoice_style2?]
= label_tag nil, t('.invoice_style2?')
.field.align-center
= hidden_field_tag 'preferences[enable_receipt_printing?]', '0'
= check_box_tag 'preferences[enable_receipt_printing?]', '1', Spree::Config[:enable_receipt_printing?]
= label_tag nil, t('.enable_receipt_printing?')
.field.align-center
= hidden_field_tag 'preferences[enterprise_number_required_on_invoices?]', '0'
= check_box_tag 'preferences[enterprise_number_required_on_invoices?]', '1', Spree::Config[:enterprise_number_required_on_invoices?]

View File

@@ -1,75 +0,0 @@
!!! Basic
%html
%head
<meta content="text/html;charset=ansi" http-equiv="Content-Type">
= javascript_include_tag "shared/jquery-1.8.0.js"
= javascript_include_tag "qz/qz-tray.js"
= javascript_include_tag "qz/sha-256.min.js"
= javascript_include_tag "qz/rsvp-3.1.0.min.js"
= javascript_include_tag "qz/jsrsasign-latest-all-min.js"
:javascript
var printData = [
'\x1B' + '\x40', // init
'\x1B' + '\x74' + '\x10',
'\x1B' + '\x61' + '\x31', // center align
'\x1B' + '\x21' + '\x30', // em mode on
'#{j(@order.distributor.name)}' + '\x0A',
'\x1B' + '\x21' + '\x0A' + '\x1B' + '\x45' + '\x0A', // em mode off
'\x0A',
'#{j(@order.distributor.address.address_part1)}' + '\x0A', // text and line break
'#{j(@order.distributor.address.address_part2)}' + '\x0A',
'#{j(@order.distributor.contact.email)}' + '\x0A',
'\x0A', // line break
'\x1B' + '\x61' + '\x32', // right align
'#{j(l(Time.zone.now.to_date))}' + '\x0A',
'#{j(@order.number)}' + '\x0A',
'\x1B' + '\x61' + '\x30', // left align
'\x0A',
'\x1B' + '\x4D' + '\x31', // small text
"#{'%6s %-26s%10s%10s' %
[j(t(:ticket_column_qty)),
j(t(:ticket_column_item)),
j(t(:ticket_column_unit_price)),
j(t(:ticket_column_total_price))]}",
'\x0A',
'\x1B' + '\x4D' + '\x30', // normal text
'__________________________________________' + '\x0A',
"#{@order.line_items
.sort_by{ |line_item| line_item.product.name }
.map { |line_item| '%5d %-19.19s%8.8s%8.8s' %
[line_item.quantity,
j(line_item.product.name),
j(line_item.single_display_amount_with_adjustments.format(symbol: false, with_currency: false)),
j(line_item.display_amount_with_adjustments.format(symbol: false, with_currency: false))] }
.join('" + \'\x0A\' + "')}",
'\x0A',
"#{checkout_adjustments_for(@order, exclude: [:line_item], reject_zero_amount: false)
.reject{ |a| a.amount == 0 }
.reverse.map { |adjustment| '%5s %-27.27s%8.8s' %
["",
j(raw(adjustment.label)),
j(display_adjustment_amount(adjustment).format(symbol: false, with_currency: false))] +
'" + \'\x0A\' + "'}.join }",
'__________________________________________' + '\x0A',
'\x0A',
'\x1B' + '\x45' + '\x0D', // bold on
"#{'%31s%10s' %
[j(t(:total_incl_tax)),
j(@order.display_total.format(with_currency: false))]}",
'\x1B' + '\x45' + '\x0A', // bold off
'\x0A',
"#{display_checkout_taxes_hash(@order).map { |tax|
'%31s%10s' %
[j(t(:tax_total, rate: tax[:percentage])),
j(tax[:amount].format(with_currency: false))] +
'" + \'\x0A\' + "'}.join }",
"#{'%31s%10s' %
[j(t(:total_excl_tax)),
j(display_checkout_total_less_tax(@order).format(with_currency: false))]}",
'\x0A',
'\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
'\x1B' + '\x69', // cut paper
];
= javascript_include_tag "qz/ticket-popup.js"
%body
%div#printer-list

View File

@@ -219,7 +219,6 @@ module Openfoodnetwork
config.assets.precompile += ['web/all.js']
config.assets.precompile += ['darkswarm/all.js']
config.assets.precompile += ['shared/*']
config.assets.precompile += ['qz/*']
config.assets.precompile += ['*.jpg', '*.jpeg', '*.png', '*.gif' '*.svg']
# Apply framework defaults. New recommended defaults are successively added with each Rails version and

View File

@@ -612,7 +612,6 @@ en:
title: "Invoice Settings"
enable_invoices?: "Enable Invoices?"
invoice_style2?: "Use the alternative invoice model that includes total tax breakdown per rate and tax rate info per item (not yet suitable for countries displaying prices excluding tax)"
enable_receipt_printing?: "Show options for printing receipts using thermal printers in order dropdown?"
enterprise_number_required_on_invoices?: "Require an ABN to generate an invoice?"
stripe_connect_settings:
@@ -1728,11 +1727,6 @@ en:
order_number: "Invoice number:"
date_of_transaction: "Date of transaction:"
ticket_column_qty: "Qty"
ticket_column_item: "Item"
ticket_column_unit_price: "Unit Price"
ticket_column_total_price: "Total Price"
menu_1_title: "Shops"
menu_1_url: "/shops"
menu_2_title: "Map"

View File

@@ -6,7 +6,6 @@ module.exports = function(config) {
files: [
APPLICATION_SPEC,
'app/assets/javascripts/shared/jquery-1.8.0.js', // TODO: Can we link to Rails' jquery?
'app/assets/javascripts/shared/angular-local-storage.js',
'app/assets/javascripts/shared/ng-infinite-scroll.min.js',
'app/assets/javascripts/shared/angular-slideables.js',

View File

@@ -88,7 +88,6 @@ Spree::Core::Engine.routes.draw do
post :resend
get :invoice
get :print
get :print_ticket
end
collection do

View File

@@ -0,0 +1,5 @@
class DeleteReceiptPrintingFromPreferences < ActiveRecord::Migration[6.1]
def up
execute("DELETE FROM spree_preferences WHERE key = '/spree/app_configuration/enable_receipt_printing?'")
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_02_13_060209) do
ActiveRecord::Schema.define(version: 2023_02_13_160135) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"

View File

@@ -9,7 +9,6 @@ describe Admin::InvoiceSettingsController, type: :controller do
preferences: {
enable_invoices?: 0,
invoice_style2?: 1,
enable_receipt_printing?: 1,
}
}
}
@@ -33,13 +32,5 @@ describe Admin::InvoiceSettingsController, type: :controller do
Spree::Config[:invoice_style2?]
}.to(true)
end
it "disables receipt printing" do
expect {
post :update, params: params
}.to change {
Spree::Config[:enable_receipt_printing?]
}.to(true)
end
end
end

View File

@@ -9,10 +9,8 @@ describe Spree::Admin::OrdersHelper, type: :helper do
around do |example|
original_invoices_setting = Spree::Config[:enable_invoices?]
original_tickets_setting = Spree::Config[:enable_receipt_printing?]
example.run
Spree::Config[:enable_invoices?] = original_invoices_setting
Spree::Config[:enable_receipt_printing?] = original_tickets_setting
end
before do
@@ -21,7 +19,6 @@ describe Spree::Admin::OrdersHelper, type: :helper do
allow(order).to receive(:can_cancel?) { false }
allow(order).to receive(:resumed?) { false }
Spree::Config[:enable_invoices?] = false
Spree::Config[:enable_receipt_printing?] = false
end
it "returns only edit order link when all conditions are set to false" do
@@ -82,20 +79,6 @@ describe Spree::Admin::OrdersHelper, type: :helper do
expect(links[3][:name]).to eq "Print Invoice"
end
end
context "with tickets enabled" do
before do
Spree::Config[:enable_receipt_printing?] = true
end
it "adds print and select ticket links" do
links = helper.order_links(order)
expect(links.size).to eq 4
expect(links[2][:name]).to eq "Print Ticket"
expect(links[3][:name]).to eq "Select printer for tickets"
end
end
end
context "resumed order" do

View File

@@ -14,6 +14,7 @@
//= require moment/min/moment.min.js
//= require i18n
//= require handlebars
//= require jquery2
angular.module('templates', [])
angular.module('uiGmapgoogle-maps', []);

View File

@@ -1,99 +0,0 @@
# frozen_string_literal: true
require "system_helper"
describe '
As an administrator
I want to print a ticket for an order
' do
include CheckoutHelper
include AuthenticationHelper
include ActionView::Helpers::NumberHelper
include WebHelper
context "as an enterprise manager" do
let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) }
let!(:distributor) { create(:distributor_enterprise) }
let!(:order) do
create(:order_with_taxes, distributor: distributor, ship_address: create(:address),
product_price: 110, tax_rate_amount: 0.1,
tax_rate_name: "Tax 1").tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end
before do
@enterprise_user = create(:user)
@enterprise_user.enterprise_roles.build(enterprise: distributor).save
login_as @enterprise_user
Spree::Config[:enable_receipt_printing?] = true
end
describe "viewing the edit page" do
it "can print an order's ticket" do
visit spree.edit_admin_order_path(order)
find("#links-dropdown .ofn-drop-down").click
ticket_window = window_opened_by do
within('#links-dropdown') do
click_link('Print Ticket')
end
end
within_window ticket_window do
accept_alert do
# The JS code needs time to load but there's no visual indicator
# we can wait for.
print_data = nil
wait_until do
print_data = page.evaluate_script('printData')
rescue Ferrum::JavaScriptError
false
end
elements_in_print_data = [
order.distributor.name,
order.distributor.address.address_part1,
order.distributor.address.address_part2,
order.distributor.contact.email, order.number,
line_items_in_print_data,
adjustments_in_print_data,
order.display_total.format(with_currency: false),
taxes_in_print_data,
display_checkout_total_less_tax(order).format(with_currency: false)
]
expect(print_data.join).to include(*elements_in_print_data.flatten)
end
end
end
def line_items_in_print_data
order.line_items.map { |line_item|
[line_item.quantity.to_s,
line_item.product.name,
line_item.single_display_amount_with_adjustments.format(symbol: false,
with_currency: false),
line_item.display_amount_with_adjustments.format(symbol: false, with_currency: false)]
}
end
def adjustments_in_print_data
checkout_adjustments_for(order, exclude: [:line_item]).
reject { |a| a.amount.zero? }.
map do |adjustment|
[raw(adjustment.label),
display_adjustment_amount(adjustment).format(symbol: false, with_currency: false)]
end
end
def taxes_in_print_data
[["10.0%", "$11.00"]]
end
end
end
end