Openbravo Issue Tracking System - Retail Modules
View Issue Details
0039103Retail ModulesWeb POSpublic2018-08-08 12:422019-01-28 18:33
gorkaion 
rqueralta 
urgentmajoralways
closedfixed 
5
 
RR18Q4 
marvintm
No
0039103: Wrong payment amoutns when there are payments in different currencies
On an order with 3 different payments:

1st non cash payment (credit card for example)
2nd foreign cash payment.
3rd store currency cash payment.

The third payment generates a change amount.
If the change amount converted to the foreign cash is zero the original amount of the 2nd cash payments is reduced by the change amount.

This results on payments for less amount of the order gross.

When the payment is synchronized to the backend the difference in the amount is added to the 1st payment.
Create a store using AED currency. Ensure that credit card and cash financial accounts are in AED.
Set a conversion rate to USD so 3.6USD are 1EUR.
Ensure that there is cash to return change in AED.

Create a ticket for a total amount of 552.78AED.
Add a card payment of 100AED
Add a USD Cash payment of 100 USD -> converted to 360AED
Add a cash payment of 92.79AED
The total amount paid is 552.79AED so a change of 0.01AED is required.

Click on Done button.

Notice that the amounts of the payments are changed to:
USD Cash payment -> 100USD (359.99AED)
Cash Payment -> 92.78

Go to backend and check the payment details of the order, the amounts are:
Credit card: 100.01
USD Cash 359.99
Cash: 92.78

The credit card and USD cash amounts are wrong.
The issue is in the following lines of hte adjustPayments:

p.set('origAmount', OB.DEC.mul(p.get('amount'), p.get('rate')));
//Here we are trying to know if the current payment is making the pending to pay 0.
//to know that we are suming up every payments except the current one (getSumOfOrigAmounts)
//then we substract this amount from the total (getDifferenceBetweenPaymentsAndTotal)
//and finally we transform this difference to the foreign amount
//if the payment in the foreign amount makes pending to pay zero, then we will ensure that the payment
//in the default currency is satisfied
if (OB.DEC.compare(OB.DEC.sub(this.getDifferenceRemovingSpecificPayment(p), OB.DEC.abs(p.get('amount')))) === OB.DEC.Zero) {
  multiCurrencyDifference = this.getDifferenceBetweenPaymentsAndTotal(p);
  if (OB.DEC.abs(p.get('origAmount')) !== OB.DEC.abs(multiCurrencyDifference)) {
    p.set('origAmount', multiCurrencyDifference);
  }
}

The this.getDifferenceRemovingSpecificPayment(p) method for the USD cash is returning 100USD as it is the rounded conversion of 359.99 to USD. If the change amount is higher the method does not return 100 and the payment is not modified.
No tags attached.
? wrong-payments.json (18,692) 2018-08-08 12:43
https://issues.openbravo.com/file_download.php?file_id=12039&type=bug
Issue History
2018-08-08 12:42gorkaionNew Issue
2018-08-08 12:42gorkaionAssigned To => Retail
2018-08-08 12:42gorkaionResolution time => 1535493600
2018-08-08 12:42gorkaionTriggers an Emergency Pack => No
2018-08-08 12:43gorkaionFile Added: wrong-payments.json
2018-08-08 12:45gorkaionNote Added: 0106193
2018-08-09 14:45rqueraltaAssigned ToRetail => rqueralta
2018-08-09 14:46rqueraltaStatusnew => scheduled
2018-08-15 21:12hgbotCheckin
2018-08-15 21:12hgbotNote Added: 0106356
2018-08-15 21:12hgbotStatusscheduled => resolved
2018-08-15 21:12hgbotResolutionopen => fixed
2018-08-15 21:12hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/8374a14c75162946681011922a7bcc6557014f0b [^]
2018-08-23 11:55marvintmReview Assigned To => marvintm
2018-08-23 11:55marvintmStatusresolved => closed
2018-08-23 11:55marvintmFixed in Version => RR18Q4
2018-11-13 15:54hgbotCheckin
2018-11-13 15:54hgbotNote Added: 0107888
2019-01-10 14:00hgbotCheckin
2019-01-10 14:00hgbotNote Added: 0108894
2019-01-28 18:33hgbotCheckin
2019-01-28 18:33hgbotNote Added: 0109285

Notes
(0106193)
gorkaion   
2018-08-08 12:45   
Attached the json generated with the amounts of the steps to reproduce.

You can check how the payments sum 552.77 instead of 552.78 because the USD Cash payment is reduced to 359.99

Later the OrderLoader adds the 0.01 missing to the first payment.
(0106356)
hgbot   
2018-08-15 21:12   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: 8374a14c75162946681011922a7bcc6557014f0b
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Wed Aug 15 11:39:07 2018 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/8374a14c75162946681011922a7bcc6557014f0b [^]

Fixed issue 39103: Wrong payment amoutns when there are payments in different
currencies

- Into getDifferenceBetweenPaymentsAndTotal function was taked into account the
change if exist.

---
M web/org.openbravo.retail.posterminal/js/model/order.js
---
(0107888)
hgbot   
2018-11-13 15:54   
Repository: tools/automation/pi-mobile
Changeset: 2a0b9df1dcea610a9f8ae0c9823245a5ca90bc56
Author: Alejandro <alekosmp86 <at> gmail.com>
Date: Tue Nov 13 09:44:22 2018 -0500
URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/2a0b9df1dcea610a9f8ae0c9823245a5ca90bc56 [^]

Related to issue 39103: added automated test

---
M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I33898_VerifyRoundingWhenPayingInForeignCurrency.java
A src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39103_VerifyPaymentAmountsInDifferentCurrencies.java
---
(0108894)
hgbot   
2019-01-10 14:00   
Repository: erp/pmods/org.openbravo.retail.sampledata
Changeset: 5fea2a6c56faafb1eff0dc93c4353bdf1c88bc90
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Thu Jan 10 18:30:14 2019 +0530
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.sampledata/rev/5fea2a6c56faafb1eff0dc93c4353bdf1c88bc90 [^]

Fixed issue 39874 : Added Sample data for Currency Conversion

* Added Sample data for Currency Conversion for the issue 39103
* Added Sample data for Currency Conversion for the issue 33059

---
M referencedata/sampledata/The_White_Valley_Group/C_CONVERSION_RATE.xml
---
(0109285)
hgbot   
2019-01-28 18:33   
Repository: tools/automation/pi-mobile
Changeset: 74e8b350af0917d685e42dadade009729a373252
Author: Alejandro <alekosmp86 <at> gmail.com>
Date: Wed Jan 23 14:50:41 2019 -0500
URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/74e8b350af0917d685e42dadade009729a373252 [^]

Related to issue 39103: test has been refactored due it no longer creates its
own sampledata

---
M src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39103_VerifyPaymentAmountsInDifferentCurrencies.java
---