mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Merge pull request #12996 from chahmedejaz/bugfix/12993-fix-order-cycle-report-text-version
Order cycle mail reports to producers display different data in html and txt versions
This commit is contained in:
@@ -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
|
||||
================
|
||||
@@ -15,22 +15,22 @@ 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)} (#{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_grouped_line_items
|
||||
- if @customer_line_items
|
||||
= 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
|
||||
|
||||
#{t :producer_mail_signoff},
|
||||
#{@coordinator.name}
|
||||
#{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode}
|
||||
#{raw(@coordinator.name)}
|
||||
#{raw(@coordinator.address.address1)}, #{raw(@coordinator.address.city)}, #{raw(@coordinator.address.zipcode)}
|
||||
#{@coordinator.phone}
|
||||
#{@coordinator.contact.email}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user