Add code to sort order by supplier when Enterprise user chooses to

This commit is contained in:
Nihal Mohammed
2022-03-15 04:28:52 +05:30
parent cc120aecb6
commit 5f2f5456a0
5 changed files with 30 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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