Further improve weight calculator code

This commit is contained in:
luisramos0
2019-06-18 13:28:16 +01:00
parent 4551149532
commit e8eeb3d5dc

View File

@@ -18,11 +18,16 @@ module Calculator
def total_weight(line_items)
line_items.sum do |line_item|
if line_item.final_weight_volume.present?
line_item.final_weight_volume / 1000
else
(line_item.variant.andand.weight || 0) * line_item.quantity
end
line_item_weight(line_item)
end
end
def line_item_weight(line_item)
if line_item.final_weight_volume.present?
# Divided by 1000 because grams is the base weight unit and the calculator price is per_kg
line_item.final_weight_volume / 1000
else
(line_item.variant.andand.weight || 0) * line_item.quantity
end
end
end