Files
openfoodnetwork/app/models/calculator/weight.rb
Maikel Linke 1ea2f37c18 Support international decimals in weight calculator
A previous pull request added support for flexible decimal characters
when editing money amounts.
https://github.com/openfoodfoundation/openfoodnetwork/pull/1831

This pull request applies the same principle to the weight calculator
which was missed in the previous pull request.
2019-03-21 12:49:19 +11:00

21 lines
522 B
Ruby

require 'spree/localized_number'
module Calculator
class Weight < Spree::Calculator
extend Spree::LocalizedNumber
preference :per_kg, :decimal, default: 0.0
attr_accessible :preferred_per_kg
localize_number :preferred_per_kg
def self.description
I18n.t('spree.weight')
end
def compute(object)
line_items = line_items_for object
total_weight = line_items.sum { |li| ((li.variant.andand.weight || 0) * li.quantity) }
total_weight * preferred_per_kg
end
end
end