Fix bug where shipments by LP provider with wrong size received discounts
This commit is contained in:
parent
a9dc75a695
commit
91e271186e
@ -6,6 +6,7 @@ module PlanetExpress
|
|||||||
|
|
||||||
def applicable_to?(shipment)
|
def applicable_to?(shipment)
|
||||||
lp_provider_shipment?(shipment) &&
|
lp_provider_shipment?(shipment) &&
|
||||||
|
l_shipment?(shipment) &&
|
||||||
third_l_shipment_in_month?(shipment) &&
|
third_l_shipment_in_month?(shipment) &&
|
||||||
rule_not_applied_in_month_already?(shipment)
|
rule_not_applied_in_month_already?(shipment)
|
||||||
end
|
end
|
||||||
@ -16,6 +17,10 @@ module PlanetExpress
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def l_shipment?(shipment)
|
||||||
|
shipment.l_shipment?
|
||||||
|
end
|
||||||
|
|
||||||
def lp_provider_shipment?(shipment)
|
def lp_provider_shipment?(shipment)
|
||||||
shipment.lp_provider?
|
shipment.lp_provider?
|
||||||
end
|
end
|
||||||
@ -26,7 +31,7 @@ module PlanetExpress
|
|||||||
|
|
||||||
count = shipment_repository.l_shipment_count_for_provider_and_month(provider,
|
count = shipment_repository.l_shipment_count_for_provider_and_month(provider,
|
||||||
month)
|
month)
|
||||||
(count % 3) == 2
|
count == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
def rule_not_applied_in_month_already?(shipment)
|
def rule_not_applied_in_month_already?(shipment)
|
||||||
|
@ -73,6 +73,25 @@ RSpec.describe PlanetExpress::LShipmentDiscountRule do
|
|||||||
end.to_not(change { shipment.discounts })
|
end.to_not(change { shipment.discounts })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'non L shipment' do
|
||||||
|
before(:each) do
|
||||||
|
shipment_repo.add(applicable_shipment)
|
||||||
|
shipment_repo.add(applicable_shipment)
|
||||||
|
end
|
||||||
|
let(:shipping_option) do
|
||||||
|
shipping_option_repo.find_by_provider_and_package_size('LP', 'M')
|
||||||
|
end
|
||||||
|
let(:shipment) do
|
||||||
|
PlanetExpress::Shipment.new(Date.today, shipping_option)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not update the discounts' do
|
||||||
|
expect do
|
||||||
|
subject.apply_to(shipment)
|
||||||
|
end.to_not(change { shipment.discounts })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user