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

Make edit order page work even if inventory_items dont have a corresponding line_item in the order #5253

Merged
merged 9 commits into from Apr 23, 2020
2 changes: 0 additions & 2 deletions .rubocop_manual_todo.yml
Expand Up @@ -181,7 +181,6 @@ Layout/LineLength:
- spec/features/admin/image_settings_spec.rb
- spec/features/admin/multilingual_spec.rb
- spec/features/admin/order_cycles_spec.rb
- spec/features/admin/orders_spec.rb
- spec/features/admin/overview_spec.rb
- spec/features/admin/payment_method_spec.rb
- spec/features/admin/product_import_spec.rb
Expand Down Expand Up @@ -468,7 +467,6 @@ Metrics/BlockLength:
- spec/factories/shipping_method_factory.rb
- spec/factories/subscription_factory.rb
- spec/factories/variant_factory.rb
- spec/features/admin/orders_spec.rb
- spec/features/consumer/shopping/embedded_shopfronts_spec.rb
- spec/lib/open_food_network/group_buy_report_spec.rb
- spec/models/tag_rule/discount_order_spec.rb
Expand Down
1 change: 1 addition & 0 deletions app/views/spree/admin/orders/_shipment_manifest.html.haml
@@ -1,5 +1,6 @@
- shipment.manifest.each do |item|
- line_item = order.find_line_item_by_variant(item.variant)
- break if line_item.blank?

%tr.stock-item{ "data-item-quantity" => "#{item.quantity}" }
%td.item-image
Expand Down
93 changes: 93 additions & 0 deletions spec/features/admin/order_print_ticket_spec.rb
@@ -0,0 +1,93 @@
# frozen_string_literal: true

require "spec_helper"

feature '
As an administrator
I want to print a ticket for an order
', js: true do
include AuthenticationWorkflow
include CheckoutHelper
include ActionView::Helpers::NumberHelper

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 |record|
Spree::TaxRate.adjust(record)
record.update_shipping_fees!
end
end

before do
@enterprise_user = create_enterprise_user
@enterprise_user.enterprise_roles.build(enterprise: distributor).save

quick_login_as @enterprise_user

Spree::Config[:enable_receipt_printing?] = true
end

feature "viewing the edit page" do
scenario "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
print_data = page.evaluate_script('printData');
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 == 0 }.
map do |adjustment|
[raw(adjustment.label),
display_adjustment_amount(adjustment).format(symbol: false, with_currency: false)]
end
end

def taxes_in_print_data
display_checkout_taxes_hash(order).map { |tax_rate, tax_value|
[tax_rate,
tax_value.format(with_currency: false)]
}
end
end
end
end