mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-19 00:27:25 +00:00
We're now handling these values on the frontend, so can keep this simple. fixes up: Add numericality validation for * Add translation for Active Record error message
21 lines
501 B
Ruby
21 lines
501 B
Ruby
# frozen_string_literal: false
|
|
|
|
module Calculator
|
|
class FlatPercentItemTotal < Spree::Calculator
|
|
preference :flat_percent, :decimal, default: 0
|
|
|
|
validates :preferred_flat_percent,
|
|
numericality: true
|
|
|
|
def self.description
|
|
Spree.t(:flat_percent)
|
|
end
|
|
|
|
def compute(object)
|
|
item_total = line_items_for(object).map(&:amount).sum
|
|
value = item_total * BigDecimal(preferred_flat_percent.to_s) / 100.0
|
|
(value * 100).round.to_f / 100
|
|
end
|
|
end
|
|
end
|