From 58ffd00f4abf7fcca7436227977b2df3bb731a7f Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 15 Feb 2021 12:49:31 +0100 Subject: [PATCH] Extract private method This was initially intended to cache the result of the `#map` and `#uniq` calls but we're not confident enough and don't want to scopecreep this. It's still worth to point out that this is what we need, line items' `unique orders`. Hopefully, next time we find a way to optimize it. --- .../reports/bulk_coop/bulk_coop_report.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb b/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb index a826407179..ac318c00dc 100644 --- a/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb +++ b/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb @@ -159,15 +159,19 @@ module OrderManagement end def customer_payments_total_cost(line_items) - line_items.map(&:order).uniq.sum(&:total) + unique_orders(line_items).sum(&:total) end def customer_payments_amount_owed(line_items) - line_items.map(&:order).uniq.sum(&:outstanding_balance) + unique_orders(line_items).sum(&:outstanding_balance) end def customer_payments_amount_paid(line_items) - line_items.map(&:order).uniq.sum(&:payment_total) + unique_orders(line_items).sum(&:payment_total) + end + + def unique_orders(line_items) + line_items.map(&:order).uniq end def empty_cell(_line_items)