Openbravo Issue Tracking System - Retail Modules
View Issue Details
0044217Retail ModulesDiscounts by Totalpublic2020-05-28 08:272020-06-11 18:55
Leyre 
ranjith_qualiantech_com 
highmajoralways
closedfixed 
5
 
RR20Q3 
marvintm
No
0044217: The "Variable Percentage Discount per Total Amount" discount is not calculated correctly.
The "Variable Percentage Discount per Total Amount" discount is not calculated correctly.
Backend:
1) Configure a product:
   1.1. Grouped product = N
   2.2. Price = 149.9
   2.3. UPC/EAN = 1 (simple number, to enter the product in the POS).

2) Configure a discount:
   2.1. Type = Variable Percentage Discount per Total Amount
   2.2. Percentage = 5%

Web POS:
1) Add the previous product 123 times.
2) Add the previous discount.

Expected result:
Total of the receipt without the discount = 149.9 * 123 = 18437.7
Discount amount = 18437.7 * 0.05 = 921.89
Total of the receipt with the discount = 17515.81

Actual result:
Total of the receipt without the discount = 18437.7 see attached image step1.png
Discount amount = 922.5 see attached image step2.png
Total of the receipt with the discount = 17515.20

No tags attached.
png step1.png (242,442) 2020-05-28 08:27
https://issues.openbravo.com/file_download.php?file_id=14545&type=bug
png

png step2.png (526,733) 2020-05-28 08:28
https://issues.openbravo.com/file_download.php?file_id=14546&type=bug
png problem.png (206,813) 2020-06-11 13:45
https://issues.openbravo.com/file_download.php?file_id=14615&type=bug
png
Issue History
2020-05-28 08:27LeyreNew Issue
2020-05-28 08:27LeyreAssigned To => Retail
2020-05-28 08:27LeyreResolution time => 1592431200
2020-05-28 08:27LeyreTriggers an Emergency Pack => No
2020-05-28 08:27LeyreFile Added: step1.png
2020-05-28 08:28LeyreFile Added: step2.png
2020-06-05 10:37ranjith_qualiantech_comAssigned ToRetail => ranjith_qualiantech_com
2020-06-08 07:21ranjith_qualiantech_comStatusnew => scheduled
2020-06-08 07:55hgbotCheckin
2020-06-08 07:55hgbotNote Added: 0120720
2020-06-08 13:53hgbotCheckin
2020-06-08 13:53hgbotNote Added: 0120741
2020-06-09 09:16ranjith_qualiantech_comStatusscheduled => resolved
2020-06-09 09:16ranjith_qualiantech_comResolutionopen => fixed
2020-06-09 19:06marvintmReview Assigned To => marvintm
2020-06-09 19:06marvintmStatusresolved => closed
2020-06-09 19:06marvintmFixed in Version => RR20Q3
2020-06-11 13:45LeyreNote Added: 0120802
2020-06-11 13:45LeyreStatusclosed => new
2020-06-11 13:45LeyreFile Added: problem.png
2020-06-11 18:51marvintmStatusnew => scheduled
2020-06-11 18:55marvintmNote Added: 0120806
2020-06-11 18:55marvintmStatusscheduled => resolved
2020-06-11 18:55marvintmStatusresolved => closed

Notes
(0120720)
hgbot   
2020-06-08 07:55   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 34b16b968acd64d4fbf7eade9959c2f8bbb876d3
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Mon Jun 08 11:25:07 2020 +0530
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/34b16b968acd64d4fbf7eade9959c2f8bbb876d3 [^]

Related to issue-44217 : Updated DiscountsBytotal Percentage calculation

* For bytotal percentage discounts, discount will be calculated on total receipt amount
  After applying discounts for each line, if sum of line discount is not same as total discount,
  then discount for last line should be adjusted.

---
M web/org.openbravo.retail.discounts.bytotal/app/model/business-logic/discounts-engine/engine/rules/by-total-percentage-discount.js
---
(0120741)
hgbot   
2020-06-08 13:53   
Repository: tools/automation/pi-mobile
Changeset: 5bcc0f0b2c82766b8439717a30d6b8f960c6dd60
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Mon Jun 08 17:23:41 2020 +0530
URL: http://code.openbravo.com/tools/automation/pi-mobile/rev/5bcc0f0b2c82766b8439717a30d6b8f960c6dd60 [^]

Verifies issue 44217 : Modified ByTotal Percentage Automated tests

* Multidiscounts_ChangeLineQuantitiesWithByTotal
* Multidiscounts_FixedPercentageByTotal
* Multidiscounts_RemoveMultiDiscountsByTotal
* Multidiscounts_VariablePercentageByTotal

---
M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/multidiscounts/Multidiscounts_ChangeLineQuantitiesWithByTotals.java
M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/multidiscounts/Multidiscounts_FixedPercentageByTotal.java
M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/multidiscounts/Multidiscounts_RemoveMultiDiscountsByTotal.java
M src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/multidiscounts/Multidiscounts_VariablePercentageByTotal.java
---
(0120802)
Leyre   
2020-06-11 13:45   
Testing in pi:
https://livebuilds.openbravo.com/retail_modules_pgsql_pi/ [^]

Web POS:
1) Add a product 149.9 € * 123 times.
2) Add a Variable Percentage Discount per Total Amount = 5%

The discount is calculated correctly, but the lines are not calculated proportionally. Please see attached image "problem.png"
(0120806)
marvintm   
2020-06-11 18:55   
As far as we can see, the result is correct. The discrepancy comes from the fact that, when we calculate the discounts that apply to multiple lines, we try as much as possible to calculate them proportionally to the total amount of the line.

However, the discounts need to be rounded to two decimals, and this means that some precision may be lost. As we anyway need to apply a fixed discount, we always follow the convention of applying the rounding error to the last discounted line.

In the specified case:
Discount: 18437,7*0.05=921.89

Proportional discount for each line: 921,89*149/(149*123) = 7.495, which rounded is 7.5.

Total discount would then be: 7.5*123 = 922,5

Difference with desired discount: 921.89-922,5 = -0.61

This difference is then applied to the last discounted line.