Merge pull request #13213 from chahmedejaz/task/13128-add-order-number-to-notify-producer-email

Add order number to notify producer emails and make customer code available for everyone
This commit is contained in:
Filipe
2025-04-29 18:22:06 +01:00
committed by GitHub
4 changed files with 50 additions and 20 deletions

View File

@@ -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

View File

@@ -15,7 +15,7 @@
= @receival_instructions
%p
= t :producer_mail_order_text
%table.order-summary
%table.order-summary.line-items
%thead
%tr
%th
@@ -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 '.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

View File

@@ -418,6 +418,8 @@ en:
producer_mailer:
order_cycle:
subject: "Order cycle report for %{producer}"
order_cycle_report:
order_number: "Order Number"
provider_settings: "Provider settings"
report_mailer:
report_ready:

View File

@@ -79,7 +79,7 @@ RSpec.describe ProducerMailer, type: :mailer do
end
it "contains an aggregated list of produce in alphabetical order" do
rows = parsed_email.all('table.order-summary tbody tr:not(.total-row)')
rows = parsed_email.all('table.order-summary.line-items tbody tr:not(.total-row)')
actual = rows.map do |row|
row.all('td').map { |td| td.text.strip }
end
@@ -153,7 +153,6 @@ RSpec.describe ProducerMailer, type: :mailer do
end
it "displays last name and first name for each order" do
product_name = order.line_items.first.product.name
last_name = order.billing_address.lastname
first_name = order.billing_address.firstname
row = parsed_email.find("table.order-summary.customer-order tbody tr")
@@ -190,6 +189,26 @@ RSpec.describe ProducerMailer, type: :mailer do
end
end
end
context "validate order number" do
let(:table_header) do
parsed_email.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(
parsed_email.find("table.order-summary.customer-order tbody tr")
).to have_selector("td", text: order.number)
end
end
it "adds customer names in the table" do
parsed_email.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
end
end
context 'when flag show_customer_names_to_suppliers is false' do
@@ -197,10 +216,11 @@ 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
parsed_email.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
end
end