Issue #1116 open

tiered weight incorrect check against minweight

djmarcin
created an issue

As far as I can tell, the code calculating the tieredweight tier is incorrect. File: apps/shipping/modules/tieredweight/models.py

{{{

!python

tiers_tmp = self.tiers.filter(min_weightgte=weight).order_by('min_weight')
tiers = tiers_tmp.filter(expires
gte=date.today())[:1]
}}}

However, this has the effect of finding the tier that has the closest "min_weight" over weight. To find the closest weight under weight, I believe this should be: {{{

!python

tiers_tmp = self.tiers.filter(min_weightlte=weight).order_by('-min_weight')
tiers = tiers_tmp.filter(expires
gte=date.today())[:1]
}}}

David

Comments (5)

  1. djmarcin reporter

    (Reply via djm...@gmail.com):

    The following tests are broken by the fix. Reading the code indicates that they are indeed broken originally:

    • testNotExpired: A weight of 10 should have price 1.0, as it is a weight greater than tier (1, 1, 0), but less than tier (20, 2, 1). It incorrectly gets 3.0.
    • testBase: There is no reason why a TieredWeightException should be raised for cost(4), it is greater than "min_weight" of 1, and should have cost 11.0.
    • testTwoPrices: A weight of 9 should have price 11.0 for similar reasons to testNotExpired. It incorrectly gets 12.0
    ======================================================================
    FAIL: testNotExpired
    (shipping.modules.tieredweight.tests.TieredWeightExpiringTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/djmarcin/src/git/
    therareorchid.com/project-env/src/satchmo/satchmo/apps/shipping/modules/tieredweight/tests.py",
    line 91, in testNotExpired
        self.assertEqual(self.zone.cost(10), Decimal('3.00'))
    AssertionError: Decimal("1.0") != Decimal("3.00")
    
    ======================================================================
    FAIL: testBase (shipping.modules.tieredweight.tests.TieredWeightTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/djmarcin/src/git/
    therareorchid.com/project-env/src/satchmo/satchmo/apps/shipping/modules/tieredweight/tests.py",
    line 35, in testBase
        self.assertRaises(TieredWeightException, self.zone.cost, 4)
    AssertionError: TieredWeightException not raised
    
    ======================================================================
    FAIL: testTwoPrices (shipping.modules.tieredweight.tests.TieredWeightTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/djmarcin/src/git/
    therareorchid.com/project-env/src/satchmo/satchmo/apps/shipping/modules/tieredweight/tests.py",
    line 45, in testTwoPrices
        self.assertEqual(self.zone.cost(9), Decimal('12.00'))
    AssertionError: Decimal("11.0") != Decimal("12.00")
    
    ----------------------------------------------------------------------
    Ran 6 tests in 0.097s
    

    David

  2. Log in to comment