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.
This commit is contained in:
Pau Perez
2021-02-15 12:49:31 +01:00
parent 49dfccfb51
commit 58ffd00f4a

View File

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