mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Variable weights improvements additions
This commit is contained in:
@@ -354,25 +354,44 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
|
||||
it "resets the weight if the weight is set to zero", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 0 }
|
||||
{ units_variant: { unit_value: 100 }, price: 2, quantity: 1, final_weight_volume: 0 }
|
||||
]
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], 100)).toEqual scope.filteredLineItems[0].price
|
||||
|
||||
it "updates the price if the weight is changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 200 }
|
||||
{ units_variant: { unit_value: 100 }, price: 2, final_weight_volume: 200 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].units_variant.unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
new_value = scope.filteredLineItems[0].final_weight_volume
|
||||
sp = scope.filteredLineItems[0].price * new_value / old_value
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
it "updates the weight if the quantity is changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 150 }, price: 1, final_weight_volume: 100, quantity: 2 }
|
||||
]
|
||||
old_value = 1
|
||||
nw = scope.filteredLineItems[0].units_variant.unit_value * scope.filteredLineItems[0].quantity
|
||||
scope.updateOnQuantity(scope.filteredLineItems[0], old_value)
|
||||
expect(scope.filteredLineItems[0].final_weight_volume).toEqual nw
|
||||
|
||||
it "updates the price if the quantity is changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 150 }, price: 21, final_weight_volume: 100, quantity: 2 }
|
||||
]
|
||||
old_value = 1
|
||||
np = scope.filteredLineItems[0].price * (old_value * scope.filteredLineItems[0].units_variant.unit_value) / scope.filteredLineItems[0].final_weight_volume
|
||||
scope.updateOnQuantity(scope.filteredLineItems[0], old_value)
|
||||
expect(scope.filteredLineItems[0].price).toEqual np
|
||||
|
||||
|
||||
it "doesn't update the price if the weight is not changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 100 }
|
||||
{ units_variant: { unit_value: 100 }, price: 2, final_weight_volume: 100 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
old_value = scope.filteredLineItems[0].final_weight_volume
|
||||
new_value = scope.filteredLineItems[0].final_weight_volume
|
||||
sp = scope.filteredLineItems[0].price
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user