Openbravo Issue Tracking System - Retail Modules
View Issue Details
0041887Retail ModulesDiscounts by Totalpublic2019-09-26 10:092020-02-25 11:53
Leyre 
rqueralta 
highmajoralways
closedfixed 
5
 
RR20Q1 
marvintm
Gold
11959
No
0041887: The "By Total" discount does not apply correctly the discounted qty. on the receipt lines, since it does review other discounts
The "By Total" discount does not apply correctly the discounted qty. on the receipt lines, since it does review other discounts
Backend:
Set "Web POS Use advanced discounts engine" = N

Web POS:
1. Add two lines of the same non-grouped product with price = 100:
   Line 1 - P1 100
   Line 2 - P1 100
2. Add a discount type = User Defined Amount of 40 to the first line
   Line 1 - P1 100-40=60
   Line 2 - P1 100

3. Add a discount type = Variable Discount per Total Amount of 20 to the receipt

Verify that the second discount should be applied proportionally on the lines of quantity:
   P1 60
   P1 100

But it applies without the first discount:
   P1 = 100
   P1 = 100
No tags attached.
related to defect 0043322 closed rqueralta The "By Total" discount does not apply correctly the discounted qty. on the receipt lines 
png test.png (101,275) 2019-10-15 08:53
https://issues.openbravo.com/file_download.php?file_id=13389&type=bug
png
Issue History
2019-09-26 10:09LeyreNew Issue
2019-09-26 10:09LeyreAssigned To => Retail
2019-09-26 10:09LeyreOBNetwork customer => No
2019-09-26 10:09LeyreSupport ticket => 11959
2019-09-26 10:09LeyreResolution time => 1571263200
2019-09-26 10:09LeyreTriggers an Emergency Pack => No
2019-09-27 19:24rqueraltaAssigned ToRetail => rqueralta
2019-09-27 19:24rqueraltaStatusnew => scheduled
2019-09-30 14:16LeyreOBNetwork customerNo => Gold
2019-10-15 08:53LeyreFile Added: test.png
2019-10-21 20:33hgbotCheckin
2019-10-21 20:33hgbotNote Added: 0115193
2019-10-21 20:33hgbotStatusscheduled => resolved
2019-10-21 20:33hgbotResolutionopen => fixed
2019-10-21 20:33hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/41a4e206faede44da5800372f7501757929f4abc [^]
2019-10-22 02:28hgbotCheckin
2019-10-22 02:28hgbotNote Added: 0115195
2019-10-22 15:22marvintmStatusresolved => new
2019-10-22 15:22marvintmResolutionfixed => open
2019-10-23 19:27hgbotCheckin
2019-10-23 19:27hgbotNote Added: 0115255
2019-10-23 19:27hgbotStatusnew => resolved
2019-10-23 19:27hgbotResolutionopen => fixed
2019-10-23 19:27hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/41a4e206faede44da5800372f7501757929f4abc [^] => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/798cdc80552645d077de1f3db5701e0a1ed59a08 [^]
2019-10-24 10:22jorge-garciaReview Assigned To => jorge-garcia
2019-10-24 10:27jorge-garciaNote Added: 0115261
2019-10-24 10:27jorge-garciaStatusresolved => new
2019-10-24 10:27jorge-garciaResolutionfixed => open
2019-10-26 19:42hgbotCheckin
2019-10-26 19:42hgbotNote Added: 0115285
2019-10-26 19:42hgbotStatusnew => resolved
2019-10-26 19:42hgbotResolutionopen => fixed
2019-10-26 19:42hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/798cdc80552645d077de1f3db5701e0a1ed59a08 [^] => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/6e03fca44e7e75cf77dd4711df6ba3a9c49596fc [^]
2019-11-04 10:13jorge-garciaNote Added: 0115387
2019-11-04 10:13jorge-garciaStatusresolved => closed
2019-11-04 10:13jorge-garciaFixed in Version => RR20Q1
2019-11-11 10:15LeyreNote Added: 0115491
2019-11-11 10:15LeyreStatusclosed => new
2019-11-11 10:15LeyreFile Added: error.png
2019-11-11 10:18LeyreNote Edited: 0115491bug_revision_view_page.php?bugnote_id=0115491#r19658
2019-11-11 13:16LeyreNote Edited: 0115491bug_revision_view_page.php?bugnote_id=0115491#r19662
2019-11-11 13:16LeyreFile Deleted: error.png
2019-11-11 21:55rqueraltaStatusnew => scheduled
2019-11-11 21:57hgbotCheckin
2019-11-11 21:57hgbotNote Added: 0115542
2019-11-11 21:57hgbotStatusscheduled => resolved
2019-11-11 21:57hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/6e03fca44e7e75cf77dd4711df6ba3a9c49596fc [^] => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/8ed992a5708171ab948d0ab74643faf058df73d3 [^]
2019-11-12 03:20hgbotCheckin
2019-11-12 03:20hgbotNote Added: 0115544
2019-11-12 03:20hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/8ed992a5708171ab948d0ab74643faf058df73d3 [^] => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/208e1806938d527014dda1e68136da799e9adf0d [^]
2019-11-12 04:59hgbotCheckin
2019-11-12 04:59hgbotNote Added: 0115545
2019-11-12 04:59hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/208e1806938d527014dda1e68136da799e9adf0d [^] => http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/b04833a67ca82127602de9e1b5b5f37b9a442f5a [^]
2019-11-14 17:47marvintmReview Assigned Tojorge-garcia => marvintm
2019-11-14 17:47marvintmStatusresolved => closed
2020-02-25 11:52LeyreRelationship addedrelated to 0043322
2020-02-25 11:53LeyreSummaryThe "By Total" discount does not apply correctly the discounted qty. on the receipt lines => The "By Total" discount does not apply correctly the discounted qty. on the receipt lines, since it does review other discounts
2020-02-25 11:53LeyreDescription Updatedbug_revision_view_page.php?rev_id=20445#r20445

Notes
(0115193)
hgbot   
2019-10-21 20:33   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 41a4e206faede44da5800372f7501757929f4abc
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Wed Oct 16 16:01:02 2019 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/41a4e206faede44da5800372f7501757929f4abc [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- Instead of calculating the discount amount from the total price of the line,
now we calculate it from the total price minus the discounted amount of the line,
if the promitions applied are diferent of the new promotion to apply in the line.

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115195)
hgbot   
2019-10-22 02:28   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: c883ab2cf639105621d1af054c70eb7b8a2dc421
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Mon Oct 21 20:27:02 2019 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/c883ab2cf639105621d1af054c70eb7b8a2dc421 [^]

Related to issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

Backed out changeset: 41a4e206faed

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115255)
hgbot   
2019-10-23 19:27   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 798cdc80552645d077de1f3db5701e0a1ed59a08
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Tue Oct 22 13:35:35 2019 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/798cdc80552645d077de1f3db5701e0a1ed59a08 [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- Instead of calculating the discount amount from the total price of the line,
now we calculate it from the total price minus the discounted amount of the line,
if the promitions applied are diferent of the new promotion to apply in the line
and the line it is not a splited line

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115261)
jorge-garcia   
2019-10-24 10:27   
Code is not working correctly in all cases.

1. Add two lines of the same non-grouped product with price = 100:
   Line 1 - P1 100
   Line 2 - P1 100
2. Add a discount type = User Defined Amount of 40 to the SECOND line
   Line 1 - P1 100
   Line 2 - P1 100 -40 = 60
3. Add a discount type = Variable Discount per Total Amount of 20 to the receipt

The by total discount is not being applied proportionally to the lines. It should be
   Line 1 - P1 14 from by total discount
   Line 2 - P1 6 from by total discount

And instead it is:
   Line 1 - P1 10 from by total discount (wrong)
   Line 2 - P1 10 from by total discount (wrong)
(0115285)
hgbot   
2019-10-26 19:42   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 6e03fca44e7e75cf77dd4711df6ba3a9c49596fc
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Fri Oct 25 13:57:49 2019 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/6e03fca44e7e75cf77dd4711df6ba3a9c49596fc [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- To solve all cases related to this problem, it was required to sort the list
of preprocesses ascendingly and take into account the lists of promotions and
manualpromotions.

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115387)
jorge-garcia   
2019-11-04 10:13   
Code reviewed and tested
(0115491)
Leyre   
2019-11-11 10:15   
(edited on: 2019-11-11 13:16)
Backend:
1. Set a discount: User Defined Amount
2. Set another discount: Variable Discount per Total Amount
3. Modify the Price on the product "Alpine Poles" = 100 and grouped Product= no

Web POS:
1. Add Alpine poles.
2. Add Alpine poles again.
3. Add the first discount (User defined amount) to the first line with amount = 40.
4. Try adding the first discount (By total) to both lines with amount = 20

Solution:
The discount must be:
Product 1 -> price 100 -> First discount = 40; Second discount = 7.5
Product 1 -> price 100 Second discount = 12.5

Possible problem:
if (index < list.length - 1) {
    discount = OB.DEC.toNumber(
      OB.DEC.toBigDecimal(linePrice).multiply(
        OB.DEC.toBigDecimal(totaldiscount).divide(
          OB.DEC.toBigDecimal(
        preprocess.totalNet || preprocess.total
          ),
          20,
          OB.DEC.getRoundingMode()
...

The total in the division must be 160 instead of 200.

(0115542)
hgbot   
2019-11-11 21:57   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 8ed992a5708171ab948d0ab74643faf058df73d3
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Mon Nov 11 15:52:48 2019 -0500
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/8ed992a5708171ab948d0ab74643faf058df73d3 [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- Updated the divisor value, discounting the amount of the previous applied
discounts

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115544)
hgbot   
2019-11-12 03:20   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: 208e1806938d527014dda1e68136da799e9adf0d
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Mon Nov 11 21:19:49 2019 -0500
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/208e1806938d527014dda1e68136da799e9adf0d [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- Backed out changeset: 8ed992a57081

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---
(0115545)
hgbot   
2019-11-12 04:59   
Repository: erp/pmods/org.openbravo.retail.discounts.bytotal
Changeset: b04833a67ca82127602de9e1b5b5f37b9a442f5a
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Mon Nov 11 22:56:45 2019 -0500
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.discounts.bytotal/rev/b04833a67ca82127602de9e1b5b5f37b9a442f5a [^]

Fixed issue 41887: The "By Total" discount does not apply correctly the
discounted qty. on the receipt lines

- Updated the divisor value, discounting the amount of the previous applied
discounts

---
M web/org.openbravo.retail.discounts.bytotal/js/promotion-by-total-utils.js
---