Fix producer mailer

This commit is contained in:
Gaetan Craig-Riou
2024-05-22 20:23:56 +10:00
parent 34aba72dea
commit b5cf47d306
4 changed files with 15 additions and 13 deletions

View File

@@ -60,11 +60,12 @@ class ProducerMailer < ApplicationMailer
def line_items_from(order_cycle, producer)
@line_items ||= Spree::LineItem.
includes(variant: [:product]).
includes(variant: :product).
joins(variant: :product).
from_order_cycle(order_cycle).
sorted_by_name_and_unit_value.
merge(Spree::Product.with_deleted.in_supplier(producer)).
merge(Spree::Order.by_state(["complete", "resumed"]))
merge(Spree::Variant.with_deleted.where(supplier: producer)).
merge(Spree::Order.by_state(["complete", "resumed"])).
sorted_by_name_and_unit_value
end
def total_from_line_items(line_items)
@@ -81,7 +82,7 @@ class ProducerMailer < ApplicationMailer
line_items.map do |line_item|
{
sku: line_item.variant.sku,
supplier_name: line_item.product.supplier.name,
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,

View File

@@ -40,7 +40,7 @@
= line_items.first.variant.sku
- if @distributors_pickup_times.many?
%td
= line_items.first.product.supplier.name
= line_items.first.variant.supplier.name
%td
= product_and_full_name
%td.text-right

View File

@@ -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.product.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)}
\
\
#{t :total}: #{@total}

View File

@@ -16,13 +16,14 @@ RSpec.describe ProducerMailer, type: :mailer do
let(:d1) { create(:distributor_enterprise, charges_sales_tax: true) }
let(:d2) { create(:distributor_enterprise) }
let(:p1) {
create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category_id: tax_category.id)
create(:product, name: "Zebra", price: 12.34, supplier_id: s1.id,
tax_category_id: tax_category.id)
}
let(:p2) { create(:product, name: "Aardvark", price: 23.45, supplier: s2) }
let(:p3) { create(:product, name: "Banana", price: 34.56, supplier: s1) }
let(:p4) { create(:product, name: "coffee", price: 45.67, supplier: s1) }
let(:p5) { create(:product, name: "Daffodil", price: 56.78, supplier: s1) }
let(:p6) { create(:product, name: "Eggs", price: 67.89, supplier: s1) }
let(:p2) { create(:product, name: "Aardvark", price: 23.45, supplier_id: s2.id) }
let(:p3) { create(:product, name: "Banana", price: 34.56, supplier_id: s1.id) }
let(:p4) { create(:product, name: "coffee", price: 45.67, supplier_id: s1.id) }
let(:p5) { create(:product, name: "Daffodil", price: 56.78, supplier_id: s1.id) }
let(:p6) { create(:product, name: "Eggs", price: 67.89, supplier_id: s1.id) }
let(:order_cycle) { create(:simple_order_cycle) }
let!(:incoming_exchange) {
order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true,