Openbravo Issue Tracking System - Retail Modules
View Issue Details
0044421Retail ModulesMulti order paymentpublic2020-06-19 09:552020-06-25 15:51
aaroncalero 
ranjith_qualiantech_com 
highmajoralways
closedfixed 
5
 
RR20Q3 
marvintm
No
0044421: Multiorders prepayment calculation and OBPOS_hookPostMultiOrder hook are executed in parallel
When navigating to the Pay Open Tickets window to pay several orders at the same time, there's a series of hooks and events to notify that the process has finished.
On the one hand there is the loadedMultiOrder event which, when triggered, it will launch the calculation of the prepayment amount.
On the other hand, there is the OBPOS_hookPostMultiOrder hook, which allows developers to add extra code after the Pay Open Tickets window has loaded (i.e. some custom code to automatically propose the use of credit notes).

These two points happen at the same time asynchronously, which can lead to the model in the hook to have incomplete information (i.e. missing totals)
Check the code here [1]
The hook is invoked right after triggering the event. If any code inside the event handling is asynchronous (i.e. the prepayments calculation, which happens at the end of that handler[2]) the hook will be invoked before the event handling has finished.


[1] https://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/file/tip/web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js#l2073 [^]

[2]
https://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/file/tip/web/org.openbravo.retail.posterminal/js/components/order.js#l1800 [^]
The handler for the loadedMultiOrder already accepts a callback as a parameter.
Wrap the call to OB.UTIL.HookManager.executeHooks in [1] in a function and add it as a callback of the loadedMultiOrder trigger.
This way we can ensure that the prepayment calculation (and any other async code in the handler) has finished before executing the hooks.
No tags attached.
Issue History
2020-06-19 09:55aaroncaleroNew Issue
2020-06-19 09:55aaroncaleroAssigned To => Retail
2020-06-19 09:55aaroncaleroResolution time => 1594332000
2020-06-19 09:55aaroncaleroTriggers an Emergency Pack => No
2020-06-23 07:52ranjith_qualiantech_comAssigned ToRetail => ranjith_qualiantech_com
2020-06-24 06:43hgbotCheckin
2020-06-24 06:43hgbotNote Added: 0121007
2020-06-24 06:43hgbotStatusnew => resolved
2020-06-24 06:43hgbotResolutionopen => fixed
2020-06-24 06:43hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/2dc1f07ca39e0eb5e42cb2b6060ce2b3c587076a [^]
2020-06-25 15:51marvintmReview Assigned To => marvintm
2020-06-25 15:51marvintmStatusresolved => closed
2020-06-25 15:51marvintmFixed in Version => RR20Q3

Notes
(0121007)
hgbot   
2020-06-24 06:43   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: 2dc1f07ca39e0eb5e42cb2b6060ce2b3c587076a
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Wed Jun 24 10:12:38 2020 +0530
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/2dc1f07ca39e0eb5e42cb2b6060ce2b3c587076a [^]

Fixed issue-44421: Hook PostMultiOrder should be called in callback of loadedMultiOrder

---
M web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js
---