Openbravo Issue Tracking System - Retail Modules
View Issue Details
0035998Retail ModulesWeb POSpublic2017-05-15 16:302017-05-29 13:59
aaroncalero 
migueldejuana 
highmajoralways
closedfixed 
5
 
RR17Q3 
guilleaer
No
0035998: Javascript error editing the current customer on remote mode, using Terminal Authentication
When the Remote mode for customers is configured together with the Terminal Authentication preference, a javascript error might raise while trying to save changes done to the customer currently assigned to the receipt.
The issue can be reproduced easily if the internet connection speed is slow, or if the OBPOS_PostCustomerSave hook includes several remote calls.
Using standard retail sampledata (livebuilds).
Login in backend.
Go to the Preference window and configure the following preferences:
*Enable Remote for Customer with value 'Y'
*Terminal Authentication enabled with value 'Y'
Go to the POS Terminal window, find the VBS-1 terminal and define the Terminal Key Identifier as VBS1

Login in web pos, terminal VBS-1. The Terminal Authentication window will be shown.
Enter the requested values.
Once the application has logged in, open the browser console, go to the Network tab and enable a slow throttling (i.e. GPRS, 50kb/s).
In web pos, open the customer selector popup and edit the VBS Customer record.
Click on Save.
A "SyntaxError: Unexpected token o in JSON at position 1" error will be raised and the customer edition won't be saved.

The functions defined on the datacustomersave.js file are in charge of saving and synchronizing modifications done to customers from webpos. The functions on this file use a reference to OB.Model.ChangedBusinessPartners, which is the model used to synchronize changes to business partners.
The reference to that object, bpToSave, is used on different parts of the code, which asynchronously access and modify the object.
Especifically, the OBPOS_PostCustomerSave hook is called twice using the same object ([1] and [2]).
The callback of the first hook saves the model, then changes the json property of the object (assigning a js object instead of a string, corrupting the object and later causing the SyntaxError) and finally it tries to synchronize the customer.
The callback of the second hook saves the same object again, and finally tries to synchronize the object again. If the connection speed is slow, the first hook finishes before reaching this point, so the 2nd synchronization is done using a corrupt BP object):
This code should be refactored to call the hook only once, regardless of which flow is executed (create/update, either in remote or local mode).
Also if the same object is going to be used across the code, the asynchrony should be controlled using callbacks, to ensure that the code is always executed in the same order.

[1] https://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/file/12a71cc328da/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js#l121 [^]
[2] https://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/file/12a71cc328da/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js#l197 [^]
No tags attached.
related to defect 0033926 closed mtaal [STORE SERVER] Business partners are not updated when editing them in Web POS. 
related to defect 0034023RR16Q4 closed mtaal JSON error unexpected token in remote BP data when saving address through customer 
related to defect 0036051 new Retail datacustomersave.js executes twice OBPOS_PostCustomerSave 
Issue History
2017-05-15 16:30aaroncaleroNew Issue
2017-05-15 16:30aaroncaleroAssigned To => Retail
2017-05-15 16:30aaroncaleroResolution time => 1496008800
2017-05-15 16:30aaroncaleroTriggers an Emergency Pack => No
2017-05-16 16:28migueldejuanaRelationship addedrelated to 0033926
2017-05-16 16:28migueldejuanaRelationship addedrelated to 0034023
2017-05-19 09:15hgbotCheckin
2017-05-19 09:15hgbotNote Added: 0096670
2017-05-19 09:15hgbotStatusnew => resolved
2017-05-19 09:15hgbotResolutionopen => fixed
2017-05-19 09:15hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/40bd1098c95802ebaebb1a09416604a056beebc9 [^]
2017-05-19 11:16migueldejuanaRelationship addedrelated to 0036051
2017-05-25 12:13marvintmAssigned ToRetail => migueldejuana
2017-05-29 13:59guilleaerReview Assigned To => guilleaer
2017-05-29 13:59guilleaerStatusresolved => closed
2017-05-29 13:59guilleaerFixed in Version => RR17Q3

Notes
(0096670)
hgbot   
2017-05-19 09:15   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: 40bd1098c95802ebaebb1a09416604a056beebc9
Author: Miguel de Juana <miguel.dejuana <at> openbravo.com>
Date: Fri May 19 09:14:50 2017 +0200
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/40bd1098c95802ebaebb1a09416604a056beebc9 [^]

Fixed issue 0035998: Javascript error editing the current customer on remote mode, using Terminal Authentication

- Stringify json object to set it to the bp to save
- Execute OBPOS_PostCustomerSave just once

---
M web/org.openbravo.retail.posterminal/js/data/datacustomersave.js
---