From 11959515b8a8d693e19d54e73ca25273cf4a44f5 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Tue, 26 Nov 2024 03:48:47 +0500 Subject: [PATCH 1/7] 12993: update the condition to display details --- app/views/producer_mailer/order_cycle_report.text.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index adf77e8eb8..8d566a315f 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -20,7 +20,7 @@ Orders summary \ #{t :total}: #{@total} \ -- if @customer_grouped_line_items +- if @customer_line_items = t :producer_mail_order_customer_text \ - @customer_line_items.each do |line_item| From bbdee7c0f340caf3c3cf2eacb068497413c81ac3 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 2 Dec 2024 18:03:49 +0500 Subject: [PATCH 2/7] 12993: add included tax in text report --- .../order_cycle_report.text.haml | 2 +- spec/mailers/producer_mailer_spec.rb | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index 8d566a315f..af2be22d6f 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -15,7 +15,7 @@ Orders summary = t :producer_mail_order_text \ - @grouped_line_items.each_pair do |product_and_full_name, line_items| - #{line_items.first.variant.sku} - #{raw(line_items.first.variant.supplier.name)} - #{raw(product_and_full_name)} (QTY: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} + #{line_items.first.variant.sku} - #{raw(line_items.first.variant.supplier.name)} - #{raw(product_and_full_name)} (QTY: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} (#{Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency)} tax incl.) \ \ #{t :total}: #{@total} diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index fe1bbe2d8b..61334e2819 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -91,6 +91,9 @@ RSpec.describe ProducerMailer, type: :mailer do # Tax for p1 line items expect(body_as_html(mail).find("table.order-summary tr", text: p1.name)) .to have_selector("td.tax", text: "$2.73") + expect( + product_line_from_order_summary_text(mail, p1.name) + ).to include("($2.73 tax incl.)") end it "does not include incomplete orders" do @@ -149,6 +152,7 @@ RSpec.describe ProducerMailer, type: :mailer do it "adds customer names table" do expect(body_as_html(mail).find(".order-summary.customer-order")).not_to be_nil + expect(customer_details_summary_text(mail)).to be_present end it "displays last name for each order" do @@ -156,6 +160,9 @@ RSpec.describe ProducerMailer, type: :mailer do last_name = order.billing_address.lastname expect(body_as_html(mail).find("table.order-summary.customer-order tr", text: product_name)).to have_selector("td", text: last_name) + expect( + product_line_from_details_summary_text(mail, product_name) + ).to include(last_name) end it "displays first name for each order" do @@ -163,6 +170,9 @@ RSpec.describe ProducerMailer, type: :mailer do first_name = order.billing_address.firstname expect(body_as_html(mail).find("table.order-summary.customer-order tr", text: product_name)).to have_selector("td", text: first_name) + expect( + product_line_from_details_summary_text(mail, product_name) + ).to include(first_name) end it "it orders list via last name" do @@ -171,6 +181,7 @@ RSpec.describe ProducerMailer, type: :mailer do create(:order, :with_line_item, distributor: d1, order_cycle:, state: 'complete', bill_address: FactoryBot.create(:address, last_name: "smith")) expect(mail.body.encoded).to match(/.*Abby.*Doe.*smith/m) + expect(customer_details_summary_text(mail)).to include('Abby', 'Doe', 'smith') end end @@ -183,6 +194,7 @@ RSpec.describe ProducerMailer, type: :mailer do expect { body_as_html(mail).find(".order-summary.customer-order") }.to raise_error(Capybara::ElementNotFound) + expect(customer_details_summary_text(mail)).to be_nil end end @@ -238,4 +250,32 @@ RSpec.describe ProducerMailer, type: :mailer do def body_as_html(mail) Capybara.string(mail.html_part.body.encoded) end + + def body_as_text(mail) + mail.text_part.body.decoded + end + + def customer_details_summary_text(mail) + body_as_text(mail) + .split(I18n.t(:producer_mail_order_customer_text)) + .second + end + + def product_line_from_details_summary_text(mail, product_name) + summary = customer_details_summary_text(mail) + product_line_by_summary(summary, product_name) + end + + def product_line_from_order_summary_text(mail, product_name) + summary = body_as_text(mail) + .split(I18n.t(:producer_mail_order_customer_text)) + .first + product_line_by_summary(summary, product_name) + end + + def product_line_by_summary(summary, product_name) + return '' unless summary + + summary.lines.find { |line| line.include?(product_name) } || '' + end end From 4c6c1eedb1cfa2b8744de737c2e09a5b1dc0ee04 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 2 Dec 2024 18:23:24 +0500 Subject: [PATCH 3/7] 12993: use html safe strings wherever required --- app/views/producer_mailer/order_cycle_report.text.haml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index af2be22d6f..d0ecdc30dd 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -1,13 +1,13 @@ -#{t :producer_mail_greeting} #{@producer.name}, +#{t :producer_mail_greeting} #{raw(@producer.name)}, \ = t :producer_mail_text_before \ - @distributors_pickup_times.each do |distributor_name, pickup_time| - \- #{distributor_name} (#{pickup_time}) + \- #{raw(distributor_name)} (#{pickup_time}) \ - if @receival_instructions = t :producer_mail_delivery_instructions - = @receival_instructions + = raw(@receival_instructions) \ Orders summary ================ @@ -30,7 +30,7 @@ Orders summary = t :producer_mail_text_after #{t :producer_mail_signoff}, -#{@coordinator.name} -#{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} +#{raw(@coordinator.name)} +#{raw(@coordinator.address.address1)}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} #{@coordinator.phone} #{@coordinator.contact.email} From af200ab4a0a3bf7423068cf187643c29953d9d22 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 2 Dec 2024 18:40:18 +0500 Subject: [PATCH 4/7] 12993: fix lint issues --- spec/mailers/producer_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 61334e2819..2f6152b563 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -265,7 +265,7 @@ RSpec.describe ProducerMailer, type: :mailer do summary = customer_details_summary_text(mail) product_line_by_summary(summary, product_name) end - + def product_line_from_order_summary_text(mail, product_name) summary = body_as_text(mail) .split(I18n.t(:producer_mail_order_customer_text)) From f8003b00db053f1670a8bb32dc39b11442fb5bb9 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sun, 8 Dec 2024 01:03:38 +0500 Subject: [PATCH 5/7] 12993: translate tax incl and qty --- app/views/producer_mailer/order_cycle_report.text.haml | 4 ++-- config/locales/en.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index d0ecdc30dd..02a97dace7 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -15,7 +15,7 @@ Orders summary = t :producer_mail_order_text \ - @grouped_line_items.each_pair do |product_and_full_name, line_items| - #{line_items.first.variant.sku} - #{raw(line_items.first.variant.supplier.name)} - #{raw(product_and_full_name)} (QTY: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} (#{Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency)} tax incl.) + #{line_items.first.variant.sku} - #{raw(line_items.first.variant.supplier.name)} - #{raw(product_and_full_name)} (#{t(:producer_mail_qty)}: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} (#{t(:with_tax_incl, amount: Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency))}) \ \ #{t :total}: #{@total} @@ -24,7 +24,7 @@ Orders summary = t :producer_mail_order_customer_text \ - @customer_line_items.each do |line_item| - #{line_item[:sku]} - #{raw(line_item[:supplier_name])} - #{raw(line_item[:product_and_full_name])} (QTY: #{line_item[:quantity]}) - #{raw(line_item[:first_name])} #{raw(line_item[:last_name])} + #{line_item[:sku]} - #{raw(line_item[:supplier_name])} - #{raw(line_item[:product_and_full_name])} (#{t(:producer_mail_qty)}: #{line_item[:quantity]}) - #{raw(line_item[:first_name])} #{raw(line_item[:last_name])} \ \ = t :producer_mail_text_after diff --git a/config/locales/en.yml b/config/locales/en.yml index e033aae510..7a2d30adf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -351,6 +351,8 @@ en: sku: "SKU" subtotal: "Subtotal" tax_rate: "Tax rate" + with_tax_incl: "%{amount} tax incl." + producer_mail_qty: QTY validators: date_time_string_validator: not_string_error: "must be a string" From f2da3bb11c7457c6537cf2f6e12d46f336d6cbdf Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sun, 8 Dec 2024 01:05:02 +0500 Subject: [PATCH 6/7] 12993: html sanitize city and zip --- app/views/producer_mailer/order_cycle_report.text.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index 02a97dace7..eb48670e3b 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -31,6 +31,6 @@ Orders summary #{t :producer_mail_signoff}, #{raw(@coordinator.name)} -#{raw(@coordinator.address.address1)}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} +#{raw(@coordinator.address.address1)}, #{raw(@coordinator.address.city)}, #{raw(@coordinator.address.zipcode)} #{@coordinator.phone} #{@coordinator.contact.email} From 42940f47294792b14422797261b15318741c252d Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sun, 8 Dec 2024 01:05:21 +0500 Subject: [PATCH 7/7] 12993: add total tax incl. --- app/views/producer_mailer/order_cycle_report.text.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index eb48670e3b..ce85b66ea5 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -18,7 +18,7 @@ Orders summary #{line_items.first.variant.sku} - #{raw(line_items.first.variant.supplier.name)} - #{raw(product_and_full_name)} (#{t(:producer_mail_qty)}: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} (#{t(:with_tax_incl, amount: Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency))}) \ \ -#{t :total}: #{@total} +#{t :total}: #{@total} (#{t(:with_tax_incl, amount: @tax_total)}) \ - if @customer_line_items = t :producer_mail_order_customer_text