mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #2030 from lin-d-hop/uk/1663variant-order-emails
Uk/1663variant order emails
This commit is contained in:
@@ -32,8 +32,8 @@ class ProducerMailer < Spree::BaseMailer
|
||||
|
||||
def line_items_from(order_cycle, producer)
|
||||
Spree::LineItem.
|
||||
joins(order: :order_cycle, variant: :product).
|
||||
where('order_cycles.id = ?', order_cycle).
|
||||
from_order_cycle(order_cycle).
|
||||
sorted_by_name_and_unit_value.
|
||||
merge(Spree::Product.in_supplier(producer)).
|
||||
merge(Spree::Order.by_state('complete'))
|
||||
end
|
||||
|
||||
@@ -32,6 +32,15 @@ Spree::LineItem.class_eval do
|
||||
end
|
||||
}
|
||||
|
||||
# Find line items that are from order sorted by variant name and unit value
|
||||
scope :sorted_by_name_and_unit_value, joins(variant: :product).
|
||||
reorder('lower(spree_products.name) asc, lower(spree_variants.display_name) asc, spree_variants.unit_value asc')
|
||||
|
||||
scope :from_order_cycle, lambda { |order_cycle|
|
||||
joins(order: :order_cycle).
|
||||
where('order_cycles.id = ?', order_cycle)
|
||||
}
|
||||
|
||||
scope :supplied_by, lambda { |enterprise|
|
||||
joins(:product).
|
||||
where('spree_products.supplier_id = ?', enterprise)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%h4
|
||||
= t :email_order_summary_price
|
||||
%tbody
|
||||
- @order.line_items.each do |item|
|
||||
- @order.line_items.sorted_by_name_and_unit_value.each do |item|
|
||||
%tr
|
||||
%td
|
||||
= render 'spree/shared/line_item_name', line_item: item
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%th.text-right.total
|
||||
%span= t(:total)
|
||||
%tbody{"data-hook" => ""}
|
||||
- order.line_items.each do |item|
|
||||
- order.line_items.sorted_by_name_and_unit_value.each do |item|
|
||||
%tr.line_item{"data-hook" => "order_details_line_item_row", class: "variant-#{item.variant.id}" }
|
||||
%td(data-hook = "order_item_description")
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ describe ProducerMailer do
|
||||
let(:s3) { create(:supplier_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
let(:p1) { create(:product, price: 12.34, supplier: s1, tax_category: tax_category) }
|
||||
let(:p2) { create(:product, price: 23.45, supplier: s2) }
|
||||
let(:p3) { create(:product, price: 34.56, supplier: s1) }
|
||||
let(:p4) { create(:product, price: 45.67, supplier: s1) }
|
||||
let(:p5) { create(:product, price: 56.78, supplier: s1) }
|
||||
let(:p1) { create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category: tax_category) }
|
||||
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(:order_cycle) { create(:simple_order_cycle) }
|
||||
let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_instructions: 'Outside shed.' }
|
||||
|
||||
@@ -71,7 +71,8 @@ describe ProducerMailer do
|
||||
expect(mail.cc).to eq [order_cycle.coordinator.contact.email]
|
||||
end
|
||||
|
||||
it "contains an aggregated list of produce" do
|
||||
it "contains an aggregated list of produce in alphabetical order" do
|
||||
expect(mail.body.encoded).to match(/coffee.+\n.+Zebra/)
|
||||
body_lines_including(mail, p1.name).each do |line|
|
||||
line.should include 'QTY: 3'
|
||||
line.should include '@ $10.00 = $30.00'
|
||||
@@ -80,6 +81,7 @@ describe ProducerMailer do
|
||||
.should have_selector("td", text: "$30.00")
|
||||
end
|
||||
|
||||
|
||||
it "displays tax totals for each product" do
|
||||
# Tax for p1 line items
|
||||
body_as_html(mail).find("table.order-summary tr", text: p1.name)
|
||||
|
||||
@@ -14,6 +14,20 @@ module Spree
|
||||
let(:li1) { create(:line_item, order: o, product: p1) }
|
||||
let(:li2) { create(:line_item, order: o, product: p2) }
|
||||
|
||||
|
||||
let(:p3) {create(:product, name: 'Clear Honey') }
|
||||
let(:p4) {create(:product, name: 'Apricots') }
|
||||
let(:v1) {create(:variant, product: p3, unit_value: 500) }
|
||||
let(:v2) {create(:variant, product: p3, unit_value: 250) }
|
||||
let(:v3) {create(:variant, product: p4, unit_value: 500, display_name: "ZZ") }
|
||||
let(:v4) {create(:variant, product: p4, unit_value: 500, display_name: "aa") }
|
||||
let(:li3) { create(:line_item, order: o, product: p3, variant: v1) }
|
||||
let(:li4) { create(:line_item, order: o, product: p3, variant: v2) }
|
||||
let(:li5) { create(:line_item, order: o, product: p4, variant: v3) }
|
||||
let(:li6) { create(:line_item, order: o, product: p4, variant: v4) }
|
||||
|
||||
let(:oc_order) { create :order_with_totals_and_distribution }
|
||||
|
||||
it "finds line items for products supplied by a particular enterprise" do
|
||||
LineItem.supplied_by(s1).should == [li1]
|
||||
LineItem.supplied_by(s2).should == [li2]
|
||||
@@ -40,6 +54,14 @@ module Spree
|
||||
LineItem.without_tax.should == [li2]
|
||||
end
|
||||
end
|
||||
|
||||
it "finds line items sorted by name and unit_value" do
|
||||
expect(o.line_items.sorted_by_name_and_unit_value).to eq([li6,li5,li4,li3])
|
||||
end
|
||||
|
||||
it "finds line items from a given order cycle" do
|
||||
expect(LineItem.from_order_cycle(oc_order.order_cycle).first.id).to eq oc_order.line_items.first.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "capping quantity at stock level" do
|
||||
|
||||
Reference in New Issue
Block a user