Skip to content

Commit 74a091a

Browse files
apply_discounts_to_lines was too complicated
Experimenting with smaller methods
1 parent 3401f83 commit 74a091a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

rails_application/app/processes/processes/invoice_generation.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,15 @@ def placed?
108108
end
109109

110110
def apply_discounts_to_lines
111-
total_discount_percentage = self.total_discount_percentage
112-
final_discount_percentage = [total_discount_percentage, 100].min
113-
discount_multiplier = (1 - final_discount_percentage / 100.0)
114-
115-
updated_lines = lines.map do |line|
116-
base_price = line.fetch(:base_price)
117-
discounted_price = base_price * discount_multiplier
118-
line.merge(price: discounted_price)
119-
end
120-
121-
with(lines: updated_lines)
111+
with(lines: lines.map { |line| apply_discount_to_line(line) })
112+
end
113+
114+
def apply_discount_to_line(line)
115+
line.merge(price: line.fetch(:base_price) * discount_multiplier)
116+
end
117+
118+
def discount_multiplier
119+
1 - (final_discount_percentage / 100.0)
122120
end
123121

124122
def sub_amounts_total

0 commit comments

Comments
 (0)