From 862edbe55b45fdfa5c39e2b13d769d8f2e7107c6 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sat, 30 Dec 2023 14:35:37 +0500 Subject: [PATCH] 11923: add voucher to OC customer total report --- config/locales/en.yml | 2 ++ .../order_cycle_customer_totals.rb | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index ef94e36501..b1790bc705 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb index caf65c8165..e1a6fbd845 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb @@ -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