Openbravo Issue Tracking System - Retail Modules
View Issue Details
0056894Retail ModulesGift cards and gift voucherspublic2024-10-24 18:092024-10-25 14:22
sofidossant 
guilleaer 
normalmajoralways
newopen 
5
pi 
 
No
0056894: API Consume Gift cards
Error when using the API
https://livebuilds.openbravo.com/context/retail_pos2_modules_pgsql/ws/org.openbravo.retail.api.giftcards.ImportService/ConsumeGiftCard [^]

When you consume the points partially, you can consume more than the value of the gift card, that is, if I have one that is worth 50, I can make 2 consumptions of 40 and this is an ERROR.

The response of the api is 10 (in the second time I consume it), but the transaction that is created is of 40
1- Creation of the GIFTCARD

With this
https://livebuilds.openbravo.com/context/retail_pos2_modules_pgsql/ws/org.openbravo.api.ImportService/GiftCard [^]

  {
    "client":"The White Valley Group",
    "organization":"The White Valley Group",
    "searchKey": "TEST-SOFISSA",
    "active": true,
    "dateOrdered": "2024-10-22",
    "businessPartner": "VBS/C0001",
    "product": "GC/001",
    "amount": 50,
    "currentAmount": 50,
    "type": "BasedOnCreditNote",
    "expirationDate": "2025-09-23"
  }

I attached the image

2- And then I try to consume:
https://livebuilds.openbravo.com/context/retail_pos2_modules_pgsql/ws/org.openbravo.retail.api.giftcards.ImportService/ConsumeGiftCard [^]

{
  "client": "The White Valley Group",
  "organization": "The White Valley Group",
  "giftCardIdentifier": "TEST-SOFISSA",
  "amount": 40,
}

Response

{
    "data": {
        "id": "9BF85FA64B114A16A9C1185D0E3BF9EE",
        "amount": 40,
        "gcnvGiftcardInst": "E16782A0E46D4BB69131B7B139F3CA70"
    },
    "links": null
}

And then again
consume:
https://livebuilds.openbravo.com/context/retail_pos2_modules_pgsql/ws/org.openbravo.retail.api.giftcards.ImportService/ConsumeGiftCard [^]

{
  "client": "The White Valley Group",
  "organization": "The White Valley Group",
  "giftCardIdentifier": "TEST-SOFISSA",
  "amount": 40,
}

{
    "data": {
        "id": "40041B28F59345DCA056C315E8780077",
        "amount": 10,
        "gcnvGiftcardInst": "E16782A0E46D4BB69131B7B139F3CA70"
    },
    "links": null
}

But if you see the transaction is for 40, I attached the images
IMPORTANT when you login, use a default one organization with currency
The error is in this JAVA
src/org/openbravo/retail/giftcards/ConsumeGiftCardAmount.java

BigDecimal realamount = amount;
      if (!isReturn && amount.compareTo(BigDecimal.ZERO) > 0) {
        if (giftcard.getCurrentamount().compareTo(amount) < 0) {
          realamount = giftcard.getCurrentamount();
        }
      }

      String newTrxId;
      try {
        newTrxId = jsonsent.getString("newTransactionId");
      } catch (Exception e) {
        newTrxId = SequenceIdData.getUUID();
      }

      final boolean isCancelled = jsonsent.optBoolean("reimburseGiftCard", false);
      String transactionId = jsonsent.has("transaction") ? jsonsent.getString("transaction") : null;
      GiftCardTrans transaction = model.consumeAmountGiftCard(newTrxId, giftcard, new Date(),
          OBDal.getInstance().get(Order.class, jsonsent.optString("order")),
          OBDal.getInstance().get(OrderLine.class, jsonsent.optString("orderline")), amount,
          isReturn, transactionId == null || "null".equals(transactionId) ? null : transactionId,
          jsonsent.has("hasPaymentMethod") ? jsonsent.getBoolean("hasPaymentMethod") : false,
          isCancelled);



When it generates the transaction, it doesn't do it with the realamount, but with the amount and that's why it can consume more.
No tags attached.
png Captura de pantalla -2024-10-24 13-10-24.png (133,010) 2024-10-24 18:10
https://issues.openbravo.com/file_download.php?file_id=20374&type=bug
png

png Captura de pantalla -2024-10-23 15-25-43.png (153,301) 2024-10-24 18:10
https://issues.openbravo.com/file_download.php?file_id=20375&type=bug
png
Issue History
2024-10-24 18:09sofidossantNew Issue
2024-10-24 18:09sofidossantAssigned To => Retail
2024-10-24 18:09sofidossantTriggers an Emergency Pack => No
2024-10-24 18:10sofidossantFile Added: Captura de pantalla -2024-10-24 13-10-24.png
2024-10-24 18:10sofidossantFile Added: Captura de pantalla -2024-10-23 15-25-43.png
2024-10-24 18:20sofidossantSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=28669#r28669
2024-10-25 06:21guillermogilAssigned ToRetail => guilleaer
2024-10-25 14:22PracticsIssue Monitored: Practics

There are no notes attached to this issue.