Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-6988

Estimated shipping cost resolution with breaks on price and quantity

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Done
    • Trunk
    • None
    • product

    Description

      On the service calcShipmentCostEstimate, each estimated shipment cost is analysed to resolve which ones should be applied on the order.

      During the breakQtys block analysis, OFBiz checks if the estimate match the quantity with their breaks and validates if one is good

                          if (qv != null) {
                              useQty = true;
                              BigDecimal min = BigDecimal.ONE.movePointLeft(4);
                              BigDecimal max = BigDecimal.ONE.movePointLeft(4);
      
                              try {
                                  min = qv.getBigDecimal("fromQuantity");
                                  max = qv.getBigDecimal("thruQuantity");
                              } catch (Exception e) {
                              }
                              if (shippableQuantity.compareTo(min) >= 0 && (max.compareTo(BigDecimal.ZERO) == 0 || shippableQuantity.compareTo(max) <= 0)) {
                                  qtyValid = true;
                              }
                              if (Debug.infoOn()) Debug.logInfo(" # QUANTITY SHIP min : " + min + ", max : " + max + ", value " + shippableQuantity + " qtyValid " + qtyValid, module);
                          }
                          if (pv != null) {
                              usePrice = true;
                              BigDecimal min = BigDecimal.ONE.movePointLeft(4);
                              BigDecimal max = BigDecimal.ONE.movePointLeft(4);
      
                              try {
                                  min = pv.getBigDecimal("fromQuantity");
                                  max = pv.getBigDecimal("thruQuantity");
                              } catch (Exception e) {
                              }
                              if (shippableTotal.compareTo(min) >= 0 && (max.compareTo(BigDecimal.ZERO) == 0 || shippableTotal.compareTo(max) <= 0)) {
                                  priceValid = true;
                              }
                              if (Debug.infoOn()) Debug.logInfo(" # PRICE TOT SHIP min : " + min + ", max : " + max + ", value " + shippableTotal+ " qtyValid " + priceValid, module);
                          }
                          // Now check the tests.
                          if ((useWeight && weightValid)  || (useQty && qtyValid) || (usePrice && priceValid)) {
                              estimateList.add(thisEstimate);
                          }
      

      I didn't understand why an estimated shippping cost that contains a no valid break can be applied on the order.

      On a customer project I have these rules:

        Quantity Break Id Price Break Id Flat Price Order Price Percent
      FR000   0 - 1000 [FRP4]  25 0
      FR001 0 - 500,000 [FRB01] 1000 - 0 [FRP3]   15
      FR004 2,000,000 - 0 [FRB04] 1000 - 0 [FRP3]   2
      FR003 1,000,001 - 1,999,999 [FRB03] 1000 - 0 [FRP3]     5
      FR002 500,001 - 1,000,000 [FRB02] 1000 - 0 [FRP3]     8

      The problem with the previous code is that for a total price more than 300€ OFBiz gives me a random rule between FR00[1-4] and it's wrong because I have also a break on total quantity shipped

      I propose to change the check like this

      @@ -406,7 +410,9 @@
                               }
                           }
                           // Now check the tests.
      -                    if ((useWeight && weightValid) || (useQty && qtyValid) || (usePrice && priceValid)) {
      +                    if ((!useWeight || useWeight && weightValid)
      +                            && (!useQty || useQty && qtyValid)
      +                            && (!usePrice || usePrice && priceValid)) {
                               estimateList.add(thisEstimate);
                           }
                       }
      

      To ensure that if a break is defined on the estimated shipping cost, we enable it only if all defined breaks are valid.

      Any suggestion ?

      Attachments

        1. OFBIZ-6988.patch
          59 kB
          Nicolas Malin
        2. OFBIZ-6988-1.patch
          39 kB
          Gil Portenseigne

        Activity

          People

            nmalin Nicolas Malin
            nmalin Nicolas Malin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: