Openbravo Issue Tracking System - Retail Modules
View Issue Details
0053919Retail ModulesDiscounts and Promotionspublic2023-11-13 13:332023-12-15 11:22
sofidossant 
ramprakash 
highmajoralways
closedunable to reproduce 
5
 
 
No
0053919: Error with the API - in NORAUTO
Error when using the API, and we apply a manual discount, and a Price Adjustment by product type discount should also be applied, but if we use "discountsFromUser" with the manual, the price adjustment by product type is not applied.
If applicable, if any other type of discount.

I was debugging and the strange thing is that it works with any type of discount, that is, if I change the discount type of the first case to Price Adjustment, it works, it gives me both discounts.
The bug is only with the Price Adjustment by Product discount type.
I was also able to identify where the error occurred, but I could not debug the code.

In the JAVA GraalDiscountsExecutor.java
      Value discountFunction = context.eval(applyDiscountsFunction);
      tr = System.currentTimeMillis();
      Value applicableRules = jsonUtils.jsonToGraal(rules);
      Value applicableBPSets = jsonUtils.jsonToGraal(bpSets);
      Value graalTicket = jsonUtils.jsonToGraal(ticket.toJSON());
      t0 = System.currentTimeMillis();
      Value discounts = discountFunction.execute(graalTicket, applicableRules, applicableBPSets);


The rules are sent well (the manual discount and Price Adjustment by Product rules), but when the apply discount function is executed it only brings the manual one.
Norauto is in version PR20Q3.5. The cases are the following: if we use this json:
{
  "ticket": {
    "organization": {
      "searchKey": "9902"
    },
    "businessPartner": {
      "referenceNo": ""
    },
    "orderDate": "2023-10-31T11:54:21",
    "priceIncludesTax": true,
    "discountsFromUser": {},
    "lines": [
      {
        "id": "1",
        "product": {
          "searchKey": "666964"
        },
        "qty": 2,
        "baseGrossUnitPrice": 15.99
      }
    ]
  }
}

The result is
{
    "ticket": {
        "id": "",
        "discountengine": {
            "lines": [
                {
                    "id": "1",
                    "grossUnitAmount": 22.38,
                    "grossUnitPrice": 11.19,
                    "discounts": [
                        {
                            "ruleId": "B81EF458CFA5470E84723091B44533D1",
                            "discountType": "98C687D2404F454F91B5DD26C67112D9",
                            "name": "008393",
                            "applyNext": true,
                            "incompatibleDiscounts": [],
                            "amt": 9.6,
                            "qtyOffer": 2,
                            "discountTypeName": "Price Adjustment by Product"
                        }
                    ],
                    "totalDiscounts": 9.6,
                    "totalDiscountsWithoutVouchers": 9.6,
                    "totalDiscountsVouchers": 0
                }
            ],
            "totalDiscounts": 9.6,
            "totalDiscountsWithoutVouchers": 9.6,
            "totalDiscountsVouchers": 0
        }
    }
}

As we see, the Price Adjustment by Product discount is applied, now if we use the following JSON, it only changes that we add discounts discountFromUser

{
  "ticket": {
    "organization": {
      "searchKey": "9902"
    },
    "businessPartner": {
      "referenceNo": ""
    },
    "orderDate": "2023-10-31T11:54:21",
    "priceIncludesTax": true,
    "discountsFromUser": {
      "bytotalManualPromotions": [
        {
          "applyNext": true,
          "disctTotalamountdisc": 2,
          "discountType": "00535FB65D9941AE9575546FBAF11B95",
          "name": "LOYALTYFR",
          "products": [],
          "productCategories": [],
          "productCharacteristics": []
        }
      ]
    },
    "lines": [
      {
        "id": "1",
        "product": {
          "searchKey": "666964 "
        },
        "qty": 1,
        "baseGrossUnitPrice": 15.99
      }
    ]
  }
}

Basically you should add the discount that is seen in the json and then the one that we saw in the first example, since the two discounts have the apply next discount.
But the following error occurs:

{
    "ticket": {
        "id": "",
        "discountengine": {
            "lines": [
                {
                    "id": "1",
                    "grossUnitAmount": 13.99,
                    "grossUnitPrice": 13.99,
                    "discounts": [
                        {
                            "ruleId": "3657531F1CAD478382ED34B4C7D22C37",
                            "discountType": "00535FB65D9941AE9575546FBAF11B95",
                            "name": "LOYALTYFR",
                            "applyNext": true,
                            "amt": 2,
                            "qtyOffer": 1,
                            "printedName": "LOYALTYFR",
                            "description": "LOYALTYFR",
                            "discountTypeName": "Variable Discount per Total Amount"
                        }
                    ],
                    "totalDiscounts": 2,
                    "totalDiscountsWithoutVouchers": 2,
                    "totalDiscountsVouchers": 0
                }
            ],
            "totalDiscounts": 2,
            "totalDiscountsWithoutVouchers": 2,
            "totalDiscountsVouchers": 0
        }
    }
}
 As we see, only the manual is applied and not the Price Adjustment by product.
No tags attached.
Issue History
2023-11-13 13:33sofidossantNew Issue
2023-11-13 13:33sofidossantAssigned To => Retail
2023-11-13 13:33sofidossantTriggers an Emergency Pack => No
2023-11-27 17:29aaroncaleroAssigned ToRetail => Triage Omni OMS
2023-11-30 11:32sofidossantNote Added: 0157841
2023-12-04 12:25sofidossantNote Added: 0157937
2023-12-05 11:50aferrazAssigned ToTriage Omni OMS => ramprakash
2023-12-15 11:22ramprakashNote Added: 0158259
2023-12-15 11:22ramprakashStatusnew => closed
2023-12-15 11:22ramprakashResolutionopen => unable to reproduce

Notes
(0157841)
sofidossant   
2023-11-30 11:32   
any news?
(0157937)
sofidossant   
2023-12-04 12:25   
any news?
(0158259)
ramprakash   
2023-12-15 11:22   
The Manual Discount ID was missing in the Input Json so Discount is not applied
After Including ID and on Checking with correct Json the Output is Fine and the API works Perfect.