diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index d4aea36453..e24d37fc1a 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -20,8 +20,9 @@ %tr %th = t :sku - %th - = t :supplier + - if @distributors_pickup_times.many? + %th + = t :supplier %th = t :product %th.text-right @@ -37,8 +38,9 @@ %tr %td #{line_items.first.variant.sku} - %td - #{raw(line_items.first.product.supplier.name)} + - if @distributors_pickup_times.many? + %td + #{raw(line_items.first.product.supplier.name)} %td #{raw(product_and_full_name)} %td.text-right @@ -51,7 +53,8 @@ #{Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency) } %tr.total-row %td - %td + - if @distributors_pickup_times.many? + %td %td %td %td @@ -67,8 +70,9 @@ %tr %th = t :sku - %th - = t :supplier + - if @distributors_pickup_times.many? + %th + = t :supplier %th = t :product %th.text-right @@ -82,8 +86,9 @@ %tr %td #{line_item[:sku]} - %td - #{raw(line_item[:supplier_name])} + - if @distributors_pickup_times.many? + %td + #{raw(line_item[:supplier_name])} %td #{raw(line_item[:product_and_full_name])} %td.text-right diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 5de4e2869b..bdb8d9ec73 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -185,6 +185,49 @@ describe ProducerMailer, type: :mailer do end end + context "products from multiple suppliers" do + before do + order_cycle.exchanges.create! sender: s1, receiver: d2, incoming: true, + receival_instructions: 'Community hall' + order_cycle.exchanges.create! sender: d2, receiver: d2, incoming: false, + pickup_time: 'Mon, 22nd Dec' + order = create(:order, distributor: d2, order_cycle:, state: 'complete') + order.line_items << create(:line_item, quantity: 3, variant: p1.variants.first) + order.finalize! + order.save + end + + it "displays a supplier column" do + expect(body_as_html(mail).find(".order-summary")) + .to have_selector("th", text: "Supplier") + end + + context "when the show customer names to suppliers setting is enabled" do + before { order_cycle.coordinator.update!(show_customer_names_to_suppliers: true) } + + it "displays a supplier column in the summary of orders grouped by customer" do + expect(body_as_html(mail).find(".customer-order")) + .to have_selector("th", text: "Supplier") + end + end + end + + context "products from only one supplier" do + it "doesn't display a supplier column" do + expect(body_as_html(mail).find(".order-summary")) + .to have_no_selector("th", text: "Supplier") + end + + context "when the show customer names to suppliers setting is enabled" do + before { order_cycle.coordinator.update!(show_customer_names_to_suppliers: true) } + + it "doesn't display a supplier column in the summary of orders grouped by customer" do + expect(body_as_html(mail).find(".customer-order")) + .to have_no_selector("th", text: "Supplier") + end + end + end + private def body_lines_including(mail, str)