diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index 982ef43f59..74e626d77d 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -29,16 +29,21 @@ %td{width: "10%" }   %td{ :align => "right" } - %strong= "#{t('.to')}: #{@order.ship_address.full_name}" + %strong= "#{t('.to')}: #{@order.bill_address.full_name}" - if @order.andand.customer.andand.code.present? %br = "#{t('.code')}: #{@order.customer.code}" %br - = @order.ship_address.full_address + = @order.bill_address.full_address %br - if @order.andand.customer.andand.email.present? = "#{@order.customer.email}," = "#{@order.bill_address.phone}" + %br + %strong= "#{t('.shipping')}: #{@order.shipping_method&.name}" + - if @order.shipping_method&.require_ship_address && @order.ship_address != @order.bill_address + %br + = @order.ship_address.full_address = render 'spree/admin/orders/invoice_table' diff --git a/config/locales/en.yml b/config/locales/en.yml index 804ccbbcef..edbc0de299 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3190,6 +3190,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using code: "Code" from: "From" to: "To" + shipping: "Shipping" form: distribution_fields: title: "Distribution" diff --git a/spec/views/spree/admin/orders/invoice.html.haml_spec.rb b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb new file mode 100644 index 0000000000..b6bea69c67 --- /dev/null +++ b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb @@ -0,0 +1,67 @@ +require "spec_helper" + +describe "spree/admin/orders/invoice.html.haml" do + let(:shop) { create(:distributor_enterprise) } + let(:order) { create(:completed_order_with_totals, distributor: shop) } + let(:adas_address) do + Spree::Address.new( + firstname: "Ada", + lastname: "Lovelace", + phone: "0404 123 456", + address1: "2 Mahome St", + city: "Thornbury", + zipcode: "3071", + state_id: 1, + state_name: "Victoria", + ) + end + let(:adas_address_display) { "2 Mahome St, Thornbury, 3071, Victoria" } + + before do + assign(:order, order) + end + + it "displays the customer code" do + order.customer = Customer.create!( + user: order.user, + email: order.user.email, + enterprise: order.distributor, + code: "Money Penny", + ) + render + expect(rendered).to have_content "Code: Money Penny" + end + + it "displays the billing and shipping address" do + order.bill_address = adas_address + render + expect(rendered).to have_content "To: Ada Lovelace" + expect(rendered).to have_content adas_address.phone + expect(rendered).to have_content adas_address_display + end + + it "displays shipping info" do + order.shipping_method.update_attributes!( + name: "Home delivery", + require_ship_address: true, + ) + order.ship_address = adas_address + + render + expect(rendered).to have_content "Shipping: Home delivery" + expect(rendered).to have_content adas_address_display + end + + it "prints address once if billing and shipping address are the same" do + order.bill_address = adas_address + order.ship_address = Spree::Address.new(order.bill_address.attributes) + order.shipping_method.update_attributes!( + name: "Home delivery", + require_ship_address: true, + ) + + render + expect(rendered).to have_content "Shipping: Home delivery" + expect(rendered.scan(/2 Mahome St, Thornbury, 3071/).count).to eq 1 + end +end