Openbravo Issue Tracking System - Retail Modules
View Issue Details
0038768Retail ModulesWeb POSpublic2018-06-15 13:442018-06-21 08:56
marvintm 
rqueralta 
highmajorrandom
closedfixed 
5
 
RR18Q3 
marvintm
No
0038768: Invoice generation in cashup may fail randomly if multiple invoices are generated
Currently the cashup generates invoices with a temporary document number, and at the end of the process this temporary number is replaced by the final one. The reason it works in this way is to maximize performance by reducing contention, as generating the final document number requires acquiring a lock over a record in the AD_Sequence table, and it's in our best interest to try to minimise the duration of this lock.

However, there is a problem currently with the way this works. The cashup may generate more than one invoice (as multiple business partners may have generated orders, or different invoices for orders and returns may also be generated). A random document number is generated for each, but the random numbers generated for these document numbers are not very large, and there is a possibility of collision. If the same number is generated for two invoices in the same cashup, then the second one will fail because of the unique constraint in the document number column of the C_Invoice table.
The only way to reproduce this problem reliably is to change this line in OrderGroupingProcessor:


    final String strExecutionId = "WebPOS_CashUp_" + String.valueOf(rnd.nextInt(1000000));

so that it generates the same value and then create a cashup with more than one invoice.
The temporary document number should contain a longer random component based on a UUID (to try to minimise the chances of locking), and also a fixed part (1, 2, 3, ...) to guarantee that even in the case of random collision, the invoices in the same cashup are correctly created.
No tags attached.
Issue History
2018-06-15 13:44marvintmNew Issue
2018-06-15 13:44marvintmAssigned To => Retail
2018-06-15 13:44marvintmResolution time => 1530828000
2018-06-15 13:44marvintmTriggers an Emergency Pack => No
2018-06-15 15:12marvintmProposed Solution updated
2018-06-15 20:39rqueraltaAssigned ToRetail => rqueralta
2018-06-15 20:39rqueraltaStatusnew => scheduled
2018-06-19 17:48hgbotCheckin
2018-06-19 17:48hgbotNote Added: 0105264
2018-06-19 17:48hgbotStatusscheduled => resolved
2018-06-19 17:48hgbotResolutionopen => fixed
2018-06-19 17:48hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/a63bd8fd12192f63525f89c75351ce7a8b9b19ea [^]
2018-06-21 08:55hgbotCheckin
2018-06-21 08:55hgbotNote Added: 0105291
2018-06-21 08:56marvintmReview Assigned To => marvintm
2018-06-21 08:56marvintmStatusresolved => closed
2018-06-21 08:56marvintmFixed in Version => RR18Q3

Notes
(0105264)
hgbot   
2018-06-19 17:48   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: a63bd8fd12192f63525f89c75351ce7a8b9b19ea
Author: Rafael Queralta <rafaelcuba81 <at> gmail.com>
Date: Sun Jun 17 09:16:09 2018 -0400
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/a63bd8fd12192f63525f89c75351ce7a8b9b19ea [^]

Fixed issue 38768: Invoice generation in cashup may fail randomly if multiple
invoices are generated

- Added random UUID to avoid document number collision

---
M src/org/openbravo/retail/posterminal/OrderGroupingProcessor.java
---
(0105291)
hgbot   
2018-06-21 08:55   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: 1efc59c9417f395a6217bae481cf3bfac41c448d
Author: Antonio Moreno <antonio.moreno <at> openbravo.com>
Date: Thu Jun 21 08:55:43 2018 +0200
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/1efc59c9417f395a6217bae481cf3bfac41c448d [^]

Related to issue 38768. Removed unnecessary lines.

---
M src/org/openbravo/retail/posterminal/OrderGroupingProcessor.java
---