mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #10257 from rioug/9720-fix-imperial-weight-display-when-using-float-value
Fix decimal display for imperial weight on Cart, Order Confirmation page and Confirmation emails
This commit is contained in:
@@ -56,7 +56,7 @@ module VariantUnits
|
||||
def option_value_value_unit_scaled
|
||||
unit_scale, unit_name = scale_for_unit_value
|
||||
|
||||
value = BigDecimal(@variant.unit_value / unit_scale, 6)
|
||||
value = (@variant.unit_value / unit_scale).to_d.truncate(2)
|
||||
|
||||
[value, unit_name]
|
||||
end
|
||||
|
||||
@@ -145,6 +145,15 @@ module VariantUnits
|
||||
allow(v).to receive(:unit_value) { nil }
|
||||
expect(subject.send(:option_value_value_unit)).to eq [nil, nil]
|
||||
end
|
||||
|
||||
it "truncates value to 2 decimals maximum" do
|
||||
oz_scale = 28.35
|
||||
p = double(:product, variant_unit: 'weight', variant_unit_scale: oz_scale)
|
||||
allow(v).to receive(:product) { p }
|
||||
# The unit_value is stored rounded to 2 decimals
|
||||
allow(v).to receive(:unit_value) { (12.5 * oz_scale).round(2) }
|
||||
expect(subject.send(:option_value_value_unit)).to eq [BigDecimal(12.5, 6), 'oz']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user