Openbravo Issue Tracking System - Retail Modules
View Issue Details
0056894Retail ModulesGift cards and gift voucherspublic2024-10-24 18:092024-11-05 23:32
sofidossant 
sreehari 
normalmajoralways
closedfixed 
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
2024-10-29 08:16guilleaerStatusnew => acknowledged
2024-11-02 05:54sreehariAssigned Toguilleaer => sreehari
2024-11-02 05:54sreehariStatusacknowledged => scheduled
2024-11-05 05:47hgbotNote Added: 0171356
2024-11-05 23:32hgbotNote Added: 0171459
2024-11-05 23:32hgbotResolutionopen => fixed
2024-11-05 23:32hgbotStatusscheduled => closed
2024-11-05 23:32hgbotNote Added: 0171460

Notes
(0171356)
hgbot   
2024-11-05 05:47   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.api.giftcards/-/merge_requests/45 [^]
(0171459)
hgbot   
2024-11-05 23:32   
Merge request merged: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.api.giftcards/-/merge_requests/45 [^]
(0171460)
hgbot   
2024-11-05 23:32   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.api.giftcards [^]
Changeset: dd2f5b28a325b2c0ba02025c2d35a3dfebed68c7
Author: Sreehari Venkataraman <s.venkataraman@external.orisha.com>
Date: 05-11-2024 22:32:20
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.api.giftcards/-/commit/dd2f5b28a325b2c0ba02025c2d35a3dfebed68c7 [^]

Fixes ISSUE-56894: Consume Giftcard from API response contains correct gifcard amount

---
M src/org/openbravo/retail/api/giftcards/service/ConsumeGiftCardApiImportWebService.java
---