12776: fix missing order numbers

This commit is contained in:
Ahmed Ejaz
2024-10-09 02:18:19 +05:00
committed by Rachel Arnould
parent ec0d2d346b
commit 1fbdf25296
3 changed files with 58 additions and 59 deletions

View File

@@ -20,9 +20,7 @@ module Reporting
end
def query_result
report_line_items.list(line_item_includes).group_by { |e|
[e.variant_id, e.price, e.order.distributor_id]
}.values
report_line_items.list(line_item_includes)
end
def columns
@@ -56,17 +54,19 @@ module Reporting
{
group_by: :producer,
header: true,
summary_row: proc do |_key, items|
line_items = items.flatten
summary_row: proc do |_key, line_items|
summary_hash = Hash.new(0)
{
total_excl_vat_and_fees: total_excl_vat_and_fees.call(line_items),
total_excl_vat: total_excl_vat.call(line_items),
total_fees_excl_vat: total_fees_excl_vat.call(line_items),
total_vat_on_fees: total_vat_on_fees.call(line_items),
total_tax: total_tax.call(line_items),
total: total.call(line_items),
}
line_items.each do |line_item|
summary_hash[:total_excl_vat_and_fees] += total_excl_vat_and_fees.call(line_item)
summary_hash[:total_excl_vat] += total_excl_vat.call(line_item)
summary_hash[:total_fees_excl_vat] += total_fees_excl_vat.call(line_item)
summary_hash[:total_vat_on_fees] += total_vat_on_fees.call(line_item)
summary_hash[:total_tax] += total_tax.call(line_item)
summary_hash[:total] += total.call(line_item)
end
summary_hash
end
}
]

View File

@@ -8,11 +8,11 @@ module Reporting
include LineItemsAccessHelper
def producer
proc { |line_items| supplier(line_items).name }
proc { |line_item| supplier(line_item).name }
end
def producer_address
proc { |line_items| supplier(line_items).address&.full_address }
proc { |line_item| supplier(line_item).address&.full_address }
end
def producer_abn_acn
@@ -24,92 +24,92 @@ module Reporting
end
def email
proc { |line_items| supplier(line_items).email_address }
proc { |line_item| supplier(line_item).email_address }
end
def hub
proc { |line_items| distributor(line_items).name }
proc { |line_item| distributor(line_item).name }
end
def hub_address
proc { |line_items| distributor(line_items).address&.full_address }
proc { |line_item| distributor(line_item).address&.full_address }
end
def hub_contact_email
proc { |line_items| distributor(line_items).email_address }
proc { |line_item| distributor(line_item).email_address }
end
def order_number
proc { |line_items| order(line_items).number }
proc { |line_item| order(line_item).number }
end
def order_date
proc { |line_items| order(line_items).completed_at.to_date }
proc { |line_item| order(line_item).completed_at.to_date }
end
def order_cycle
proc { |line_items| item_order_cycle(line_items).name }
proc { |line_item| item_order_cycle(line_item).name }
end
def order_cycle_start_date
proc { |line_items| item_order_cycle(line_items).orders_open_at.to_date }
proc { |line_item| item_order_cycle(line_item).orders_open_at.to_date }
end
def order_cycle_end_date
proc { |line_items| item_order_cycle(line_items).orders_close_at.to_date }
proc { |line_item| item_order_cycle(line_item).orders_close_at.to_date }
end
def product
proc { |line_items| variant(line_items).product.name }
proc { |line_item| variant(line_item).product.name }
end
def variant_unit_name
proc { |line_items| variant(line_items).full_name }
proc { |line_item| variant(line_item).full_name }
end
def quantity
proc { |line_items| line_items.to_a.sum(&:quantity) }
proc { |line_item| line_item.quantity }
end
def total_excl_vat_and_fees
proc do |line_items|
included_tax = adjustments_by_type(line_items, :tax, included: true)
line_items.sum(&:amount) - included_tax
proc do |line_item|
included_tax = adjustments_by_type(line_item, :tax, included: true)
line_item.amount - included_tax
end
end
def total_excl_vat
proc do |line_items|
total_fees = adjustments_by_type(line_items, :fees)
total_excl_vat_and_fees.call(line_items) + total_fees
proc do |line_item|
total_fees = adjustments_by_type(line_item, :fees)
total_excl_vat_and_fees.call(line_item) + total_fees
end
end
def total_fees_excl_vat
proc do |line_items|
included_tax = tax_on_fees(line_items, included: true)
adjustments_by_type(line_items, :fees) - included_tax
proc do |line_item|
included_tax = tax_on_fees(line_item, included: true)
adjustments_by_type(line_item, :fees) - included_tax
end
end
def total_vat_on_fees
proc { |line_items| tax_on_fees(line_items) }
proc { |line_item| tax_on_fees(line_item) }
end
def total_tax
proc do |line_items|
excluded_tax = adjustments_by_type(line_items, :tax)
included_tax = adjustments_by_type(line_items, :tax, included: true)
proc do |line_item|
excluded_tax = adjustments_by_type(line_item, :tax)
included_tax = adjustments_by_type(line_item, :tax, included: true)
excluded_tax + included_tax
end
end
def total
proc do |line_items|
total_price = total_excl_vat_and_fees.call(line_items)
total_fees = total_fees_excl_vat.call(line_items)
tax = total_tax.call(line_items)
proc do |line_item|
total_price = total_excl_vat_and_fees.call(line_item)
total_fees = total_fees_excl_vat.call(line_item)
tax = total_tax.call(line_item)
total_price + total_fees + tax
end

View File

@@ -5,31 +5,30 @@ module Reporting
module Suppliers
module Helpers
module LineItemsAccessHelper
def variant(line_items)
line_items.first.variant
def variant(line_item)
line_item.variant
end
def order(line_items)
line_items.first.order
def order(line_item)
line_item.order
end
def supplier(line_items)
variant(line_items).supplier
def supplier(line_item)
variant(line_item).supplier
end
def distributor(line_items)
order(line_items).distributor
def distributor(line_item)
order(line_item).distributor
end
def item_order_cycle(line_items)
line_items.first.order_cycle
def item_order_cycle(line_item)
line_item.order_cycle
end
def adjustments_by_type(line_items, type, included: false)
def adjustments_by_type(line_item, type, included: false)
total_amount = 0.0
adjustment_type = type == :tax ? 'Spree::TaxRate' : 'EnterpriseFee'
adjustments = line_items.flat_map(&:adjustments)
adjustments = line_item.adjustments
adjustments.each do |adjustment|
if adjustment.originator_type == adjustment_type
amount = included == adjustment.included ? adjustment.amount : 0.0
@@ -40,9 +39,9 @@ module Reporting
total_amount
end
def tax_on_fees(line_items, included: false)
def tax_on_fees(line_item, included: false)
total_amount = 0.0
adjustments = line_items.flat_map(&:adjustments)
adjustments = line_item.adjustments
adjustments.each do |adjustment|
next unless adjustment.originator_type == 'EnterpriseFee'