mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add code to sort order by supplier when Enterprise user chooses to
This commit is contained in:
@@ -57,4 +57,20 @@ module ApplicationHelper
|
||||
wicked_pdf_stylesheet_pack_tag(source)
|
||||
end
|
||||
end
|
||||
|
||||
def line_items_for_invoice(order)
|
||||
if @order.distributor.preferred_invoice_order_by_supplier
|
||||
order.line_items.sort do |a, b|
|
||||
if a.supplier == b.supplier
|
||||
a.product.name <=> b.product.name
|
||||
else
|
||||
a.supplier.name <=> b.supplier.name
|
||||
end
|
||||
end
|
||||
else
|
||||
order.line_items.sort do |a, b|
|
||||
a.product.name <=> b.product.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -226,7 +226,7 @@ module Spree
|
||||
|
||||
def update_inventory
|
||||
return unless changed?
|
||||
|
||||
|
||||
scoper.scope(variant)
|
||||
Spree::OrderInventory.new(order).verify(self, target_shipment)
|
||||
end
|
||||
@@ -234,7 +234,7 @@ module Spree
|
||||
def update_order
|
||||
return unless saved_changes.present? || destroyed?
|
||||
|
||||
# update the order totals, etc.
|
||||
# update the order totals, etc.
|
||||
order.create_tax_charge!
|
||||
end
|
||||
|
||||
|
||||
@@ -608,6 +608,14 @@ module Spree
|
||||
address
|
||||
end
|
||||
|
||||
def sorted_line_items
|
||||
if distributor.preferred_invoice_order_by_supplier
|
||||
line_items.sort_by { |li| [li.supplier.name, li.product.name] }
|
||||
else
|
||||
line_items.sort_by { |li| [li.product.name]}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fee_handler
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h4= t(:invoice_column_price)
|
||||
%tbody
|
||||
- @order.line_items.sort_by{ |li| li.product.name }.each do |item|
|
||||
- @order.sorted_line_items.each do |item|
|
||||
%tr
|
||||
%td
|
||||
= render 'spree/shared/line_item_name', line_item: item
|
||||
@@ -23,6 +23,7 @@
|
||||
= item.included_tax > 0 ? item.display_included_tax : ""
|
||||
%td{:align => "right"}
|
||||
= item.display_amount_with_adjustments
|
||||
|
||||
- checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
|
||||
- taxable = adjustment.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment
|
||||
%tr
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h5= t(:invoice_column_tax_rate)
|
||||
%tbody
|
||||
- @order.line_items.sort_by{ |li| li.product.name }.each do |item|
|
||||
- @order.sorted_line_items.each do |item|
|
||||
%tr
|
||||
%td
|
||||
= render 'spree/shared/line_item_name', line_item: item
|
||||
@@ -29,6 +29,7 @@
|
||||
- if @order.total_tax > 0
|
||||
%td{:align => "right"}
|
||||
= display_line_item_tax_rates(item)
|
||||
|
||||
- checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
|
||||
%tr
|
||||
%td
|
||||
|
||||
Reference in New Issue
Block a user