From 1d88510b7b9352673fe4766ad89ceb3bcd4c10a7 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 10 Nov 2023 15:51:21 +0000 Subject: [PATCH 1/3] Only display Supplier column in Order Cycle Report email if there is more than one supplier --- .../order_cycle_report.html.haml | 10 +++++--- spec/mailers/producer_mailer_spec.rb | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index d4aea36453..d379c1499e 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 diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 5de4e2869b..bb31a25d21 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -185,6 +185,31 @@ 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 + 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 + end + private def body_lines_including(mail, str) From c3a62e53fcb2c953c07735e1cb8741467d6fcdbf Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Thu, 30 Nov 2023 20:29:15 +0000 Subject: [PATCH 2/3] If not display supplier column in the order cycle report, reduce number of columns in totals row by one too to keep columns aligned --- app/views/producer_mailer/order_cycle_report.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index d379c1499e..889f7fedf4 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -53,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 From b96110ec6c23385ac80563101b434c1781900d3a Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Thu, 30 Nov 2023 20:31:28 +0000 Subject: [PATCH 3/3] Don't display a supplier column if there is only one supplier in the orders grouped by customer part of the order cycle report --- .../order_cycle_report.html.haml | 10 ++++++---- spec/mailers/producer_mailer_spec.rb | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index 889f7fedf4..e24d37fc1a 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -70,8 +70,9 @@ %tr %th = t :sku - %th - = t :supplier + - if @distributors_pickup_times.many? + %th + = t :supplier %th = t :product %th.text-right @@ -85,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 bb31a25d21..bdb8d9ec73 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -201,6 +201,15 @@ describe ProducerMailer, type: :mailer 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 @@ -208,6 +217,15 @@ describe ProducerMailer, type: :mailer 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