mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
13128: add order number in OC report
- Make Customer Code independant of Customer Names setting
This commit is contained in:
@@ -77,11 +77,12 @@ class ProducerMailer < ApplicationMailer
|
||||
end
|
||||
|
||||
def customer_data(line_items)
|
||||
return unless @coordinator.show_customer_names_to_suppliers?
|
||||
|
||||
@display_customer_names = @coordinator.show_customer_names_to_suppliers?
|
||||
@display_business_name = false
|
||||
|
||||
line_items.map do |line_item|
|
||||
customer_code = line_item.order.customer&.code
|
||||
order = line_item.order
|
||||
customer_code = order.customer&.code
|
||||
@display_business_name = true if customer_code.present?
|
||||
|
||||
{
|
||||
@@ -89,9 +90,10 @@ class ProducerMailer < ApplicationMailer
|
||||
supplier_name: line_item.variant.supplier.name,
|
||||
product_and_full_name: line_item.product_and_full_name,
|
||||
quantity: line_item.quantity,
|
||||
first_name: line_item.order.billing_address.first_name,
|
||||
last_name: line_item.order.billing_address.last_name,
|
||||
first_name: order.billing_address.first_name,
|
||||
last_name: order.billing_address.last_name,
|
||||
business_name: customer_code,
|
||||
order_number: order.number
|
||||
}
|
||||
end.sort_by { |line_item| [line_item[:last_name].downcase, line_item[:first_name].downcase] }
|
||||
end
|
||||
|
||||
@@ -77,13 +77,16 @@
|
||||
= t :product
|
||||
%th.text-right
|
||||
= t :quantity
|
||||
%th.text-right
|
||||
= t :first_name
|
||||
%th.text-right
|
||||
= t :last_name
|
||||
- if @display_customer_names
|
||||
%th.text-right
|
||||
= t :first_name
|
||||
%th.text-right
|
||||
= t :last_name
|
||||
- if @display_business_name
|
||||
%th.text-right
|
||||
= t :business_name
|
||||
%th.text-right
|
||||
= t :oc_report_order_number
|
||||
%tbody
|
||||
- @customer_line_items.each do |line_item|
|
||||
%tr
|
||||
@@ -96,13 +99,16 @@
|
||||
= line_item[:product_and_full_name]
|
||||
%td.text-right
|
||||
= line_item[:quantity]
|
||||
%td
|
||||
= line_item[:first_name]
|
||||
%td
|
||||
= line_item[:last_name]
|
||||
- if @display_customer_names
|
||||
%td
|
||||
= line_item[:first_name]
|
||||
%td
|
||||
= line_item[:last_name]
|
||||
- if @display_business_name
|
||||
%td
|
||||
= line_item[:business_name]
|
||||
%td
|
||||
= line_item[:order_number]
|
||||
%p
|
||||
= t :producer_mail_text_after
|
||||
%p
|
||||
|
||||
@@ -3482,6 +3482,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
pending: Pending
|
||||
shipped: Shipped
|
||||
business_name: Business Name
|
||||
oc_report_order_number: Order Number
|
||||
js:
|
||||
saving: 'Saving...'
|
||||
changes_saved: 'Changes saved.'
|
||||
|
||||
@@ -190,6 +190,28 @@ RSpec.describe ProducerMailer, type: :mailer do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "validate order number" do
|
||||
let(:table_header) do
|
||||
html_body(mail).find("table.order-summary.customer-order thead")
|
||||
end
|
||||
|
||||
it 'displays order number for the customer' do
|
||||
expect(table_header).to have_selector("th", text: 'Order Number')
|
||||
expect(
|
||||
html_body(mail).find("table.order-summary.customer-order tbody tr")
|
||||
).to have_selector("td", text: order.number)
|
||||
expect(customer_details_summary_text(mail)).to include(order.number)
|
||||
end
|
||||
end
|
||||
|
||||
it "adds customer names in the table" do
|
||||
html_body(mail).find(".order-summary.customer-order").tap do |table|
|
||||
expect(table).to have_selector("th", text: "First Name")
|
||||
expect(table).to have_selector("th", text: "Last Name")
|
||||
end
|
||||
expect(customer_details_summary_text(mail)).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when flag show_customer_names_to_suppliers is false' do
|
||||
@@ -197,10 +219,12 @@ RSpec.describe ProducerMailer, type: :mailer do
|
||||
order_cycle.coordinator.show_customer_names_to_suppliers = false
|
||||
end
|
||||
|
||||
it "does not add customer names table" do
|
||||
expect {
|
||||
parsed_email.find(".order-summary.customer-order")
|
||||
}.to raise_error(Capybara::ElementNotFound)
|
||||
it "does not add customer names in the table" do
|
||||
html_body(mail).find(".order-summary.customer-order").tap do |table|
|
||||
expect(table).not_to have_selector("th", text: "First Name")
|
||||
expect(table).not_to have_selector("th", text: "Last Name")
|
||||
end
|
||||
expect(customer_details_summary_text(mail)).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user