11923: add voucher to OC customer total report

This commit is contained in:
Ahmed Ejaz
2023-12-30 14:35:37 +05:00
parent 263f68f927
commit 862edbe55b
2 changed files with 24 additions and 1 deletions

View File

@@ -3156,6 +3156,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_transaction_fee: Transaction Fee (no tax)
report_header_total_untaxable_admin: Total untaxable admin adjustments (no tax)
report_header_total_taxable_admin: Total taxable admin adjustments (tax inclusive)
report_header_voucher_label: Voucher Label
report_header_voucher_amount: "Voucher Amount (%{currency_symbol})"
report_line_cost_of_produce: Cost of produce
report_line_line_items: line items
report_header_last_completed_order_date: Last completed order date

View File

@@ -29,6 +29,8 @@ module Reporting
admin_handling_fees: proc { |_line_items| "" },
ship_price: proc { |_line_items| "" },
pay_fee_price: proc { |_line_items| "" },
voucher_label: proc { |_line_items| "" },
voucher_amount: proc { |_line_items| "" },
total_price: proc { |_line_items| "" },
paid: proc { |line_items| line_items.all? { |li| li.order.paid? } },
@@ -105,7 +107,7 @@ module Reporting
def default_params
super.merge(
{
fields_to_hide: [:final_weight_volume]
fields_to_hide: %i[final_weight_volume voucher_label voucher_amount]
}
)
end
@@ -129,6 +131,8 @@ module Reporting
admin_handling_fees: order.admin_and_handling_total,
ship_price: order.ship_total,
pay_fee_price: order.payment_fee,
voucher_label: voucher_label(order),
voucher_amount: voucher_amount(order),
total_price: order.total,
paid: order.paid?,
comments: order.special_instructions,
@@ -163,6 +167,23 @@ module Reporting
user = line_items.first.order.user
user&.customer_of(distributor)
end
def voucher_label(order)
return '' unless voucher_applicable?(order)
voucher = order.voucher_adjustments.take.originator
voucher&.code.to_s # in case if we don't get the voucher, return ""
end
def voucher_amount(order)
return '' unless voucher_applicable?(order)
(order.total - order.pre_discount_total).abs
end
def voucher_applicable?(order)
order.voucher_adjustments.present?
end
end
end
end