# HG changeset patch
# User Asier Martirena <asier.martirena@openbravo.com>
# Date 1575290894 -3600
#      Mon Dec 02 13:48:14 2019 +0100
# Node ID 68e769f409c6c4c94fdbc2a8235be6834951607b
# Parent  98bc81646eecb4741b3821909c8362c42176bd69
Fixed issue 41762: Check the outdated of the synchronizing receipts directly in the Web POS

Instead of waiting to check the outdated status of a receipt directly in the backend process, now a check is done before the synchronization is done to be able to stop the process if the ticket has been modified after it was loaded in the Web POS.
This allows to avoid the most errors while importing data generated due to this cause.

diff --git a/src-db/database/sourcedata/AD_MESSAGE.xml b/src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml
@@ -937,6 +937,18 @@
 <!--12BF57825EA1456E8567E73E1E947402-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--12BF57825EA1456E8567E73E1E947402--></AD_MESSAGE>
 
+<!--12DA431A4FCA47F89C8519B42F46E295--><AD_MESSAGE>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <AD_MESSAGE_ID><![CDATA[12DA431A4FCA47F89C8519B42F46E295]]></AD_MESSAGE_ID>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <VALUE><![CDATA[OBPOS_SyncPending]]></VALUE>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <MSGTEXT><![CDATA[The receipt %0 is still synchronizing. It's not possible to synchronize it again until the previous one finishes. Try again later.]]></MSGTEXT>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--12DA431A4FCA47F89C8519B42F46E295-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--12DA431A4FCA47F89C8519B42F46E295--></AD_MESSAGE>
+
 <!--1315FACB3884414BA9E7B8CAB3A9E81F--><AD_MESSAGE>
 <!--1315FACB3884414BA9E7B8CAB3A9E81F-->  <AD_MESSAGE_ID><![CDATA[1315FACB3884414BA9E7B8CAB3A9E81F]]></AD_MESSAGE_ID>
 <!--1315FACB3884414BA9E7B8CAB3A9E81F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1585,6 +1597,18 @@
 <!--2526D690429D4D0B8CC879B799D9A611-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--2526D690429D4D0B8CC879B799D9A611--></AD_MESSAGE>
 
+<!--25415E46FCB54A64A24C27E38FF9237D--><AD_MESSAGE>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <AD_MESSAGE_ID><![CDATA[25415E46FCB54A64A24C27E38FF9237D]]></AD_MESSAGE_ID>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <VALUE><![CDATA[OBPOS_ErrorCheckingReceipt]]></VALUE>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <MSGTEXT><![CDATA[There was an error while checking the receipt]]></MSGTEXT>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--25415E46FCB54A64A24C27E38FF9237D-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--25415E46FCB54A64A24C27E38FF9237D--></AD_MESSAGE>
+
 <!--25866352B24A483F936D4F557C4A940A--><AD_MESSAGE>
 <!--25866352B24A483F936D4F557C4A940A-->  <AD_MESSAGE_ID><![CDATA[25866352B24A483F936D4F557C4A940A]]></AD_MESSAGE_ID>
 <!--25866352B24A483F936D4F557C4A940A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -2990,6 +3014,18 @@
 <!--3A9DC2120A7D4F9FB0C3BF24E6A0B901-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--3A9DC2120A7D4F9FB0C3BF24E6A0B901--></AD_MESSAGE>
 
+<!--3AD5E3D255834AC99842DE893DAA395E--><AD_MESSAGE>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <AD_MESSAGE_ID><![CDATA[3AD5E3D255834AC99842DE893DAA395E]]></AD_MESSAGE_ID>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <VALUE><![CDATA[OBPOS_UpdatedReceipt]]></VALUE>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <MSGTEXT><![CDATA[The receipt has already been updated]]></MSGTEXT>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--3AD5E3D255834AC99842DE893DAA395E-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--3AD5E3D255834AC99842DE893DAA395E--></AD_MESSAGE>
+
 <!--3AE2C03C27BD457D92FB657A83719419--><AD_MESSAGE>
 <!--3AE2C03C27BD457D92FB657A83719419-->  <AD_MESSAGE_ID><![CDATA[3AE2C03C27BD457D92FB657A83719419]]></AD_MESSAGE_ID>
 <!--3AE2C03C27BD457D92FB657A83719419-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -8729,6 +8765,18 @@
 <!--A7CBAF28EE6C42A791DF740B61D77D4C-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--A7CBAF28EE6C42A791DF740B61D77D4C--></AD_MESSAGE>
 
+<!--A82BF80461074071BBFEE185294D72DD--><AD_MESSAGE>
+<!--A82BF80461074071BBFEE185294D72DD-->  <AD_MESSAGE_ID><![CDATA[A82BF80461074071BBFEE185294D72DD]]></AD_MESSAGE_ID>
+<!--A82BF80461074071BBFEE185294D72DD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A82BF80461074071BBFEE185294D72DD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A82BF80461074071BBFEE185294D72DD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A82BF80461074071BBFEE185294D72DD-->  <VALUE><![CDATA[OBPOS_SyncWithErrors]]></VALUE>
+<!--A82BF80461074071BBFEE185294D72DD-->  <MSGTEXT><![CDATA[The receipt %0 has been synchronized with errors. It's not possible to synchronize it again until those errors are fixed.]]></MSGTEXT>
+<!--A82BF80461074071BBFEE185294D72DD-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--A82BF80461074071BBFEE185294D72DD-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--A82BF80461074071BBFEE185294D72DD-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--A82BF80461074071BBFEE185294D72DD--></AD_MESSAGE>
+
 <!--A847E3FCBDCD4ED98A1FB6671E5A4420--><AD_MESSAGE>
 <!--A847E3FCBDCD4ED98A1FB6671E5A4420-->  <AD_MESSAGE_ID><![CDATA[A847E3FCBDCD4ED98A1FB6671E5A4420]]></AD_MESSAGE_ID>
 <!--A847E3FCBDCD4ED98A1FB6671E5A4420-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -10925,6 +10973,18 @@
 <!--D31E1DB98104425FBA69D90814D10DE9-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--D31E1DB98104425FBA69D90814D10DE9--></AD_MESSAGE>
 
+<!--D3292AA1625A4FA8A641638024CADDE3--><AD_MESSAGE>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <AD_MESSAGE_ID><![CDATA[D3292AA1625A4FA8A641638024CADDE3]]></AD_MESSAGE_ID>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <VALUE><![CDATA[OBPOS_NotPossibleToConfirmReceipt]]></VALUE>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <MSGTEXT><![CDATA[It has not been possible to confirm the status of the receipt %0. Please, go online before closing it.]]></MSGTEXT>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--D3292AA1625A4FA8A641638024CADDE3-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--D3292AA1625A4FA8A641638024CADDE3--></AD_MESSAGE>
+
 <!--D387B80B40A945B89B84255FFAD2076A--><AD_MESSAGE>
 <!--D387B80B40A945B89B84255FFAD2076A-->  <AD_MESSAGE_ID><![CDATA[D387B80B40A945B89B84255FFAD2076A]]></AD_MESSAGE_ID>
 <!--D387B80B40A945B89B84255FFAD2076A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -11694,6 +11754,18 @@
 <!--DF0B0C41CE7D490AAE15F6408CE0AF72-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--DF0B0C41CE7D490AAE15F6408CE0AF72--></AD_MESSAGE>
 
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1--><AD_MESSAGE>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <AD_MESSAGE_ID><![CDATA[DF0B7FF461C74C2EA78F6B099A51B1F1]]></AD_MESSAGE_ID>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <VALUE><![CDATA[OBPOS_NotPossibleToConfirmReceiptWarn]]></VALUE>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <MSGTEXT><![CDATA[It has not been possible to confirm the status of the receipt %0. Do you want to continue?]]></MSGTEXT>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--DF0B7FF461C74C2EA78F6B099A51B1F1--></AD_MESSAGE>
+
 <!--DFE86ADABCC443AD990A32603747EBBD--><AD_MESSAGE>
 <!--DFE86ADABCC443AD990A32603747EBBD-->  <AD_MESSAGE_ID><![CDATA[DFE86ADABCC443AD990A32603747EBBD]]></AD_MESSAGE_ID>
 <!--DFE86ADABCC443AD990A32603747EBBD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -12198,6 +12270,18 @@
 <!--E8A4371A89F448188D846B927D8D839D-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--E8A4371A89F448188D846B927D8D839D--></AD_MESSAGE>
 
+<!--E8AF932893AC449FBF0BEF357E5973B1--><AD_MESSAGE>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <AD_MESSAGE_ID><![CDATA[E8AF932893AC449FBF0BEF357E5973B1]]></AD_MESSAGE_ID>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <VALUE><![CDATA[OBPOS_RemoveAndLoad]]></VALUE>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <MSGTEXT><![CDATA[There is a newer version of the receipt %0 in the server. Please, remove the receipt and load it again if needed.]]></MSGTEXT>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--E8AF932893AC449FBF0BEF357E5973B1-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--E8AF932893AC449FBF0BEF357E5973B1--></AD_MESSAGE>
+
 <!--E8D0E5B09BB04AD09D73299B63D70C87--><AD_MESSAGE>
 <!--E8D0E5B09BB04AD09D73299B63D70C87-->  <AD_MESSAGE_ID><![CDATA[E8D0E5B09BB04AD09D73299B63D70C87]]></AD_MESSAGE_ID>
 <!--E8D0E5B09BB04AD09D73299B63D70C87-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src-db/database/sourcedata/AD_PREFERENCE.xml b/src-db/database/sourcedata/AD_PREFERENCE.xml
--- a/src-db/database/sourcedata/AD_PREFERENCE.xml
+++ b/src-db/database/sourcedata/AD_PREFERENCE.xml
@@ -451,6 +451,17 @@
 <!--334C41966CAE4DEDB430C96C466377AB-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
 <!--334C41966CAE4DEDB430C96C466377AB--></AD_PREFERENCE>
 
+<!--33F51ABEE99D46E499A1B4E33BC40FB2--><AD_PREFERENCE>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <AD_PREFERENCE_ID><![CDATA[33F51ABEE99D46E499A1B4E33BC40FB2]]></AD_PREFERENCE_ID>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <VALUE><![CDATA[N]]></VALUE>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <PROPERTY><![CDATA[OBPOS_AllowToSynchronizeLoadedReceiptsOffline]]></PROPERTY>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--33F51ABEE99D46E499A1B4E33BC40FB2--></AD_PREFERENCE>
+
 <!--349C292127AE47888F6185D1ACEE7991--><AD_PREFERENCE>
 <!--349C292127AE47888F6185D1ACEE7991-->  <AD_PREFERENCE_ID><![CDATA[349C292127AE47888F6185D1ACEE7991]]></AD_PREFERENCE_ID>
 <!--349C292127AE47888F6185D1ACEE7991-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src-db/database/sourcedata/AD_REF_LIST.xml b/src-db/database/sourcedata/AD_REF_LIST.xml
--- a/src-db/database/sourcedata/AD_REF_LIST.xml
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml
@@ -3018,6 +3018,18 @@
 <!--E53EE08A990E4ED99FEB794FF1F4E94C-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
 <!--E53EE08A990E4ED99FEB794FF1F4E94C--></AD_REF_LIST>
 
+<!--E60919FF262B4A5091228A65FF0FD931--><AD_REF_LIST>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <AD_REF_LIST_ID><![CDATA[E60919FF262B4A5091228A65FF0FD931]]></AD_REF_LIST_ID>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <VALUE><![CDATA[OBPOS_AllowToSynchronizeLoadedReceiptsOffline]]></VALUE>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <NAME><![CDATA[Web POS Allow to Synchronize Loaded Receipts Offline]]></NAME>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <DESCRIPTION><![CDATA[Preference to allow to synchronize receipts in offline without checking if the receipt is updated.]]></DESCRIPTION>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--E60919FF262B4A5091228A65FF0FD931-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--E60919FF262B4A5091228A65FF0FD931--></AD_REF_LIST>
+
 <!--E74F58F60D6743A48C52B2B232DD80BE--><AD_REF_LIST>
 <!--E74F58F60D6743A48C52B2B232DD80BE-->  <AD_REF_LIST_ID><![CDATA[E74F58F60D6743A48C52B2B232DD80BE]]></AD_REF_LIST_ID>
 <!--E74F58F60D6743A48C52B2B232DD80BE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src-db/database/sourcedata/OBMOBC_SERVICES.xml b/src-db/database/sourcedata/OBMOBC_SERVICES.xml
--- a/src-db/database/sourcedata/OBMOBC_SERVICES.xml
+++ b/src-db/database/sourcedata/OBMOBC_SERVICES.xml
@@ -437,6 +437,19 @@
 <!--670E3C221CB14D1BBEFCE47270B7F266-->  <SERVER_RUNTIME><![CDATA[OBSTSYN_ON_CENTRAL]]></SERVER_RUNTIME>
 <!--670E3C221CB14D1BBEFCE47270B7F266--></OBMOBC_SERVICES>
 
+<!--697D67A91CAB45E3AE055985607CD952--><OBMOBC_SERVICES>
+<!--697D67A91CAB45E3AE055985607CD952-->  <OBMOBC_SERVICES_ID><![CDATA[697D67A91CAB45E3AE055985607CD952]]></OBMOBC_SERVICES_ID>
+<!--697D67A91CAB45E3AE055985607CD952-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--697D67A91CAB45E3AE055985607CD952-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--697D67A91CAB45E3AE055985607CD952-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--697D67A91CAB45E3AE055985607CD952-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--697D67A91CAB45E3AE055985607CD952-->  <SERVICE><![CDATA[org.openbravo.retail.posterminal.process.CheckUpdated]]></SERVICE>
+<!--697D67A91CAB45E3AE055985607CD952-->  <DESCRIPTION><![CDATA[Process to check if a synchronizing order has been modified in the server since the moment the terminal loaded the ticket in the Web POS.]]></DESCRIPTION>
+<!--697D67A91CAB45E3AE055985607CD952-->  <ROUTINGTYPE><![CDATA[Failover]]></ROUTINGTYPE>
+<!--697D67A91CAB45E3AE055985607CD952-->  <DEFAULTTIMEOUT><![CDATA[5]]></DEFAULTTIMEOUT>
+<!--697D67A91CAB45E3AE055985607CD952-->  <SERVER_RUNTIME><![CDATA[OBSTSYN_ON_CENTRAL]]></SERVER_RUNTIME>
+<!--697D67A91CAB45E3AE055985607CD952--></OBMOBC_SERVICES>
+
 <!--6AB9803C78B645B8BF647C8D6744125D--><OBMOBC_SERVICES>
 <!--6AB9803C78B645B8BF647C8D6744125D-->  <OBMOBC_SERVICES_ID><![CDATA[6AB9803C78B645B8BF647C8D6744125D]]></OBMOBC_SERVICES_ID>
 <!--6AB9803C78B645B8BF647C8D6744125D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src/org/openbravo/retail/posterminal/process/CheckUpdated.java b/src/org/openbravo/retail/posterminal/process/CheckUpdated.java
new file mode 100644
--- /dev/null
+++ b/src/org/openbravo/retail/posterminal/process/CheckUpdated.java
@@ -0,0 +1,118 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2019 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+package org.openbravo.retail.posterminal.process;
+
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.Session;
+import org.hibernate.query.Query;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.mobile.core.process.JSONProcessSimple;
+import org.openbravo.mobile.core.utils.OBMOBCUtils;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.model.common.order.OrderLine;
+import org.openbravo.service.json.JsonConstants;
+
+public class CheckUpdated extends JSONProcessSimple {
+
+  private final String PENDING = "P";
+  private final String ERROR = "E";
+  private final String OUTDATED = "O";
+
+  @Override
+  public JSONObject exec(JSONObject jsonData) {
+    final JSONObject result = new JSONObject();
+
+    OBContext.setAdminMode(true);
+    try {
+      final JSONObject data = new JSONObject();
+      final JSONObject jsonOrder = jsonData.getJSONObject("order");
+      final Session session = OBDal.getInstance().getSession();
+
+      if (hasImportEntries(session, jsonOrder.optString("id"))) {
+        data.put("error", true);
+        data.put("type", PENDING);
+      } else if (hasErrosrWhileImporting(session, jsonOrder.optString("id"))) {
+        data.put("error", true);
+        data.put("type", ERROR);
+      } else if (isOrderOutdated(jsonOrder)) {
+        data.put("error", true);
+        data.put("type", OUTDATED);
+      }
+
+      result.put(JsonConstants.RESPONSE_DATA, data);
+      result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
+
+    } catch (JSONException e) {
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return result;
+  }
+
+  private boolean hasImportEntries(final Session session, final String orderId) {
+    final String whereClause = "%\"id\":\"" + orderId + "\"%";
+    final String importEntryHQL = "" //
+        + "SELECT id " //
+        + "FROM C_IMPORT_ENTRY " //
+        + "WHERE importStatus = 'Initial' " //
+        + "AND (typeofdata = 'Order' OR typeofdata = 'OBPOS_CancelLayaway' OR typeofdata = 'OBPOS_VoidLayaway') " //
+        + "AND jsonInfo LIKE :orderId";
+    final Query<String> importEntryQuery = session.createQuery(importEntryHQL.toString(),
+        String.class);
+    importEntryQuery.setParameter("orderId", whereClause);
+    importEntryQuery.setMaxResults(1);
+    return importEntryQuery.uniqueResult() != null;
+  }
+
+  private boolean hasErrosrWhileImporting(final Session session, final String orderId) {
+    final String whereClause = "%\"id\":\"" + orderId + "\"%";
+    final String errorWhileImportingHQL = "" //
+        + "SELECT id " //
+        + "FROM OBPOS_Errors " //
+        + "WHERE orderstatus = 'N' " //
+        + "AND (typeofdata = 'Order' OR typeofdata = 'OBPOS_CancelLayaway' OR typeofdata = 'OBPOS_VoidLayaway') " //
+        + "AND jsonInfo LIKE :orderId";
+    final Query<String> errorWhileImportingQuery = session
+        .createQuery(errorWhileImportingHQL.toString(), String.class);
+    errorWhileImportingQuery.setParameter("orderId", whereClause);
+    errorWhileImportingQuery.setMaxResults(1);
+    return errorWhileImportingQuery.uniqueResult() != null;
+  }
+
+  private boolean isOrderOutdated(final JSONObject jsonOrder) throws JSONException {
+    final Order order = OBDal.getInstance().get(Order.class, jsonOrder.optString("id"));
+    String loaded = jsonOrder.optString("loaded", null),
+        updated = OBMOBCUtils.convertToUTCDateComingFromServer(order.getUpdated());
+    if (loaded == null || loaded.compareTo(updated) != 0) {
+      return true;
+    } else {
+      final JSONArray jsonOrderlines = jsonOrder.optJSONArray("lines");
+      if (jsonOrderlines != null) {
+        for (int i = 0; i < jsonOrderlines.length(); i++) {
+          final JSONObject jsonOrderLine = jsonOrderlines.getJSONObject(i);
+          final OrderLine orderLine = OBDal.getInstance()
+              .get(OrderLine.class, jsonOrderLine.optString("id"));
+          if (orderLine != null) {
+            loaded = jsonOrderLine.optString("loaded");
+            updated = OBMOBCUtils.convertToUTCDateComingFromServer(orderLine.getUpdated());
+            if (loaded == null || loaded.compareTo(updated) != 0) {
+              return true;
+            }
+          }
+        }
+      }
+    }
+    return false;
+  }
+
+}
diff --git a/web/org.openbravo.retail.posterminal/js/data/dataordersave.js b/web/org.openbravo.retail.posterminal/js/data/dataordersave.js
--- a/web/org.openbravo.retail.posterminal/js/data/dataordersave.js
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordersave.js
@@ -210,360 +210,368 @@
           receipt: model.get('order')
         },
         function(args) {
-          var receipt = args.context.receipt;
+          var receipt = args.context.receipt,
+            handleError = function() {
+              args.context.receipt.set('isbeingprocessed', 'N');
+              args.context.receipt.set('hasbeenpaid', 'N');
+              args.context.receipt.unset('completeTicket');
+              args.context.receipt.trigger('paymentCancel');
+              if (eventParams && eventParams.callback) {
+                eventParams.callback({
+                  frozenReceipt: receipt,
+                  isCancelled: true,
+                  skipCallback: args.skipCallback
+                });
+              }
+              args.context.receipt.setIsCalculateReceiptLockState(false);
+              args.context.receipt.setIsCalculateGrossLockState(false);
+              OB.UTIL.ProcessController.finish('tapTotalButton', execution);
+              if (OB.MobileApp.model.showSynchronizedDialog) {
+                OB.MobileApp.model.hideSynchronizingDialog();
+              }
+            };
+
           if (args && args.cancellation && args.cancellation === true) {
-            args.context.receipt.set('isbeingprocessed', 'N');
-            args.context.receipt.set('hasbeenpaid', 'N');
-            args.context.receipt.unset('completeTicket');
-            args.context.receipt.trigger('paymentCancel');
-            if (eventParams && eventParams.callback) {
-              eventParams.callback({
-                frozenReceipt: receipt,
-                isCancelled: true,
-                skipCallback: args.skipCallback
-              });
-            }
-            args.context.receipt.setIsCalculateReceiptLockState(false);
-            args.context.receipt.setIsCalculateGrossLockState(false);
-            OB.UTIL.ProcessController.finish('tapTotalButton', execution);
-            if (OB.MobileApp.model.showSynchronizedDialog) {
-              OB.MobileApp.model.hideSynchronizingDialog();
-            }
+            handleError();
             return true;
           }
-          OB.UTIL.clone(receipt, frozenReceipt);
 
-          OB.UTIL.TicketCloseUtils.processChangePayments(
-            frozenReceipt,
+          OB.UTIL.TicketCloseUtils.checkOrdersUpdated(
+            receipt.get('doCancelAndReplace')
+              ? receipt.get('canceledorder')
+              : receipt,
             function() {
-              receipt.trigger('checkOpenDrawer');
-
-              if (OB.UTIL.RfidController.isRfidConfigured()) {
-                OB.UTIL.RfidController.processRemainingCodes(frozenReceipt);
-                OB.UTIL.RfidController.updateEpcBuffers();
-              }
+              OB.UTIL.clone(receipt, frozenReceipt);
 
-              OB.trace('Execution of pre order save hook OK.');
-              delete frozenReceipt.attributes.json;
-              frozenReceipt.set('creationDate', normalizedCreationDate);
-              frozenReceipt.set(
-                'timezoneOffset',
-                creationDate.getTimezoneOffset()
-              );
-              frozenReceipt.set('created', creationDate.getTime());
-              frozenReceipt.set(
-                'obposCreatedabsolute',
-                OB.I18N.formatDateISO(creationDate)
-              );
-              frozenReceipt.set('orderDate', orderDate);
-              frozenReceipt.set(
-                'movementDate',
-                OB.I18N.normalizeDate(new Date())
-              );
-              frozenReceipt.set(
-                'accountingDate',
-                OB.I18N.normalizeDate(new Date())
-              );
-              frozenReceipt.set('undo', null);
-              frozenReceipt.set('multipleUndo', null);
+              OB.UTIL.TicketCloseUtils.processChangePayments(
+                frozenReceipt,
+                function() {
+                  receipt.trigger('checkOpenDrawer');
 
-              // Set the quantities to deliver
-              frozenReceipt.setQuantitiesToDeliver();
+                  if (OB.UTIL.RfidController.isRfidConfigured()) {
+                    OB.UTIL.RfidController.processRemainingCodes(frozenReceipt);
+                    OB.UTIL.RfidController.updateEpcBuffers();
+                  }
 
-              frozenReceipt.set('paymentMethodKind', null);
-              if (
-                frozenReceipt.get('payments').length === 1 &&
-                frozenReceipt.get('completeTicket') &&
-                frozenReceipt.isFullyPaid()
-              ) {
-                var payment = frozenReceipt.get('payments').models[0];
-                frozenReceipt.set('paymentMethodKind', payment.get('kind'));
-              }
+                  OB.trace('Execution of pre order save hook OK.');
+                  delete frozenReceipt.attributes.json;
+                  frozenReceipt.set('creationDate', normalizedCreationDate);
+                  frozenReceipt.set(
+                    'timezoneOffset',
+                    creationDate.getTimezoneOffset()
+                  );
+                  frozenReceipt.set('created', creationDate.getTime());
+                  frozenReceipt.set(
+                    'obposCreatedabsolute',
+                    OB.I18N.formatDateISO(creationDate)
+                  );
+                  frozenReceipt.set('orderDate', orderDate);
+                  frozenReceipt.set(
+                    'movementDate',
+                    OB.I18N.normalizeDate(new Date())
+                  );
+                  frozenReceipt.set(
+                    'accountingDate',
+                    OB.I18N.normalizeDate(new Date())
+                  );
+                  frozenReceipt.set('undo', null);
+                  frozenReceipt.set('multipleUndo', null);
 
-              // multiterminal support
-              // be sure that the active terminal is the one set as the order proprietary
-              frozenReceipt.set(
-                'posTerminal',
-                OB.MobileApp.model.get('terminal').id
-              );
-              frozenReceipt.set(
-                'posTerminal' +
-                  OB.Constants.FIELDSEPARATOR +
-                  OB.Constants.IDENTIFIER,
-                OB.MobileApp.model.get('terminal')._identifier
-              );
+                  // Set the quantities to deliver
+                  frozenReceipt.setQuantitiesToDeliver();
 
-              frozenReceipt.get('approvals').forEach(function(approval) {
-                if (typeof approval.approvalType === 'object') {
-                  approval.approvalMessage = OB.I18N.getLabel(
-                    approval.approvalType.message,
-                    approval.approvalType.params
-                  );
-                  approval.approvalType = approval.approvalType.approval;
-                }
-              });
-
-              frozenReceipt.set(
-                'obposAppCashup',
-                OB.MobileApp.model.get('terminal').cashUpId
-              );
-              // convert returns
-              if (receipt.isNegative()) {
-                _.forEach(frozenReceipt.get('payments').models, function(item) {
+                  frozenReceipt.set('paymentMethodKind', null);
                   if (
-                    !item.get('isPrePayment') &&
-                    !item.get('reversedPaymentId') &&
-                    !frozenReceipt.get('isPaid')
+                    frozenReceipt.get('payments').length === 1 &&
+                    frozenReceipt.get('completeTicket') &&
+                    frozenReceipt.isFullyPaid()
                   ) {
-                    item.set('amount', -item.get('amount'));
-                    if (item.get('amountRounded')) {
-                      item.set('amountRounded', -item.get('amountRounded'));
-                    }
-                    item.set('origAmount', -item.get('origAmount'));
-                    if (item.get('origAmountRounded')) {
-                      item.set(
-                        'origAmountRounded',
-                        -item.get('origAmountRounded')
-                      );
-                    }
-                    item.set('paid', -item.get('paid'));
-                  } else {
-                    item.set('paid', item.get('amount'));
+                    var payment = frozenReceipt.get('payments').models[0];
+                    frozenReceipt.set('paymentMethodKind', payment.get('kind'));
                   }
-                });
-              }
 
-              var successCallback = function() {
-                var syncSuccessCallback,
-                  syncErrorCallback,
-                  closeParamCallback,
-                  restoreReceiptCallback,
-                  serverMessageForQuotation,
-                  receiptForPostSyncReceipt;
-                // success transaction...
-                OB.info(
-                  '[receipt.closed] Transaction success. ReceiptId: ' +
-                    frozenReceipt.get('id')
-                );
-                OB.info(
-                  'Ticket closed: ',
-                  frozenReceipt
-                    .get('json')
-                    .replace(/logclientErrors/g, 'logErrors'),
-                  'caller: ' +
-                    OB.UTIL.getStackTrace('Backbone.Events.trigger', true)
-                );
+                  // multiterminal support
+                  // be sure that the active terminal is the one set as the order proprietary
+                  frozenReceipt.set(
+                    'posTerminal',
+                    OB.MobileApp.model.get('terminal').id
+                  );
+                  frozenReceipt.set(
+                    'posTerminal' +
+                      OB.Constants.FIELDSEPARATOR +
+                      OB.Constants.IDENTIFIER,
+                    OB.MobileApp.model.get('terminal')._identifier
+                  );
 
-                // create a clone of the receipt to be used when executing the final callback
-                receipt.clearWith(frozenReceipt);
-                OB.UTIL.clone(receipt, diffReceipt);
-                if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
-                  receiptForPostSyncReceipt = new OB.Model.Order();
-                  OB.UTIL.clone(frozenReceipt, receiptForPostSyncReceipt);
-                }
+                  frozenReceipt.get('approvals').forEach(function(approval) {
+                    if (typeof approval.approvalType === 'object') {
+                      approval.approvalMessage = OB.I18N.getLabel(
+                        approval.approvalType.message,
+                        approval.approvalType.params
+                      );
+                      approval.approvalType = approval.approvalType.approval;
+                    }
+                  });
 
-                serverMessageForQuotation = function(frozenReceipt) {
-                  var isLayaway =
-                    frozenReceipt.get('orderType') === 2 ||
-                    frozenReceipt.get('isLayaway');
-                  var currentDocNo = frozenReceipt.get('documentNo');
-                  if (frozenReceipt && frozenReceipt.get('isQuotation')) {
-                    OB.UTIL.showSuccess(
-                      OB.I18N.getLabel('OBPOS_QuotationSaved', [currentDocNo])
-                    );
-                  } else {
-                    if (isLayaway) {
-                      OB.UTIL.showSuccess(
-                        OB.I18N.getLabel('OBPOS_MsgLayawaySaved', [
-                          currentDocNo
-                        ])
-                      );
-                    } else {
-                      OB.UTIL.showSuccess(
-                        OB.I18N.getLabel('OBPOS_MsgReceiptSaved', [
-                          currentDocNo
-                        ])
-                      );
-                    }
-                  }
-                  OB.UTIL.ProcessController.finish('tapTotalButton', execution);
-                  OB.trace('Order successfully removed.');
-                };
-
-                closeParamCallback = function() {
-                  if (eventParams && eventParams.callback) {
-                    eventParams.callback({
-                      frozenReceipt: frozenReceipt,
-                      diffReceipt: diffReceipt,
-                      isCancelled: false
+                  frozenReceipt.set(
+                    'obposAppCashup',
+                    OB.MobileApp.model.get('terminal').cashUpId
+                  );
+                  // convert returns
+                  if (receipt.isNegative()) {
+                    _.forEach(frozenReceipt.get('payments').models, function(
+                      item
+                    ) {
+                      if (
+                        !item.get('isPrePayment') &&
+                        !item.get('reversedPaymentId') &&
+                        !frozenReceipt.get('isPaid')
+                      ) {
+                        item.set('amount', -item.get('amount'));
+                        if (item.get('amountRounded')) {
+                          item.set('amountRounded', -item.get('amountRounded'));
+                        }
+                        item.set('origAmount', -item.get('origAmount'));
+                        if (item.get('origAmountRounded')) {
+                          item.set(
+                            'origAmountRounded',
+                            -item.get('origAmountRounded')
+                          );
+                        }
+                        item.set('paid', -item.get('paid'));
+                      } else {
+                        item.set('paid', item.get('amount'));
+                      }
                     });
                   }
-                };
+
+                  var successCallback = function() {
+                    var syncSuccessCallback,
+                      syncErrorCallback,
+                      closeParamCallback,
+                      restoreReceiptCallback,
+                      serverMessageForQuotation,
+                      receiptForPostSyncReceipt;
+                    // success transaction...
+                    OB.info(
+                      '[receipt.closed] Transaction success. ReceiptId: ' +
+                        frozenReceipt.get('id')
+                    );
+                    OB.info(
+                      'Ticket closed: ',
+                      frozenReceipt
+                        .get('json')
+                        .replace(/logclientErrors/g, 'logErrors'),
+                      'caller: ' +
+                        OB.UTIL.getStackTrace('Backbone.Events.trigger', true)
+                    );
+
+                    // create a clone of the receipt to be used when executing the final callback
+                    receipt.clearWith(frozenReceipt);
+                    OB.UTIL.clone(receipt, diffReceipt);
+                    if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
+                      receiptForPostSyncReceipt = new OB.Model.Order();
+                      OB.UTIL.clone(frozenReceipt, receiptForPostSyncReceipt);
+                    }
 
-                syncSuccessCallback = function(callback, eventParams) {
-                  if (
-                    OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt') &&
-                    (!eventParams ||
-                      (eventParams && !eventParams.ignoreSyncProcess))
-                  ) {
-                    OB.UTIL.HookManager.executeHooks(
-                      'OBPOS_PostSyncReceipt',
-                      {
-                        receipt: receiptForPostSyncReceipt,
-                        syncSuccess: true
-                      },
-                      function() {
+                    serverMessageForQuotation = function(frozenReceipt) {
+                      var isLayaway =
+                        frozenReceipt.get('orderType') === 2 ||
+                        frozenReceipt.get('isLayaway');
+                      var currentDocNo = frozenReceipt.get('documentNo');
+                      if (frozenReceipt && frozenReceipt.get('isQuotation')) {
+                        OB.UTIL.showSuccess(
+                          OB.I18N.getLabel('OBPOS_QuotationSaved', [
+                            currentDocNo
+                          ])
+                        );
+                      } else {
+                        if (isLayaway) {
+                          OB.UTIL.showSuccess(
+                            OB.I18N.getLabel('OBPOS_MsgLayawaySaved', [
+                              currentDocNo
+                            ])
+                          );
+                        } else {
+                          OB.UTIL.showSuccess(
+                            OB.I18N.getLabel('OBPOS_MsgReceiptSaved', [
+                              currentDocNo
+                            ])
+                          );
+                        }
+                      }
+                      OB.UTIL.ProcessController.finish(
+                        'tapTotalButton',
+                        execution
+                      );
+                      OB.trace('Order successfully removed.');
+                    };
+
+                    closeParamCallback = function() {
+                      if (eventParams && eventParams.callback) {
+                        eventParams.callback({
+                          frozenReceipt: frozenReceipt,
+                          diffReceipt: diffReceipt,
+                          isCancelled: false
+                        });
+                      }
+                    };
+
+                    syncSuccessCallback = function(callback, eventParams) {
+                      if (
+                        OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt') &&
+                        (!eventParams ||
+                          (eventParams && !eventParams.ignoreSyncProcess))
+                      ) {
+                        OB.UTIL.HookManager.executeHooks(
+                          'OBPOS_PostSyncReceipt',
+                          {
+                            receipt: receiptForPostSyncReceipt,
+                            syncSuccess: true
+                          },
+                          function() {
+                            printWelcome();
+                            callback();
+                          }
+                        );
+                      } else {
                         printWelcome();
                         callback();
                       }
-                    );
-                  } else {
-                    printWelcome();
-                    callback();
-                  }
-                };
+                    };
 
-                restoreReceiptCallback = function() {
-                  restoreReceiptOnError(eventParams, receipt);
-                  OB.UTIL.ProcessController.finish('tapTotalButton', execution);
-                };
+                    restoreReceiptCallback = function() {
+                      restoreReceiptOnError(eventParams, receipt);
+                      OB.UTIL.ProcessController.finish(
+                        'tapTotalButton',
+                        execution
+                      );
+                    };
 
-                syncErrorCallback = function() {
-                  if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
-                    OB.UTIL.HookManager.executeHooks(
-                      'OBPOS_PostSyncReceipt',
-                      {
-                        receipt: receiptForPostSyncReceipt,
-                        syncSuccess: false
-                      },
-                      restoreReceiptCallback
-                    );
-                  } else {
-                    restoreReceiptCallback();
-                  }
-                  OB.UTIL.ProcessController.finish('tapTotalButton', execution);
-                };
+                    syncErrorCallback = function() {
+                      if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
+                        OB.UTIL.HookManager.executeHooks(
+                          'OBPOS_PostSyncReceipt',
+                          {
+                            receipt: receiptForPostSyncReceipt,
+                            syncSuccess: false
+                          },
+                          restoreReceiptCallback
+                        );
+                      } else {
+                        restoreReceiptCallback();
+                      }
+                      OB.UTIL.ProcessController.finish(
+                        'tapTotalButton',
+                        execution
+                      );
+                    };
 
-                if (
-                  !OB.MobileApp.model.hasPermission(
-                    'OBMOBC_SynchronizedMode',
-                    true
-                  )
-                ) {
-                  // the trigger is fired on the receipt object, as there is only 1 that is being updated
-                  receipt.trigger('integrityOk', frozenReceipt); // Is important for module print last receipt. This module listen trigger.
-                  closeParamCallback();
-                }
-
-                OB.trace('Execution Sync process.');
-                OB.MobileApp.model.runSyncProcess(
-                  function() {
-                    // in synchronized mode do the doc sequence update in the success
                     if (
-                      OB.MobileApp.model.hasPermission(
+                      !OB.MobileApp.model.hasPermission(
                         'OBMOBC_SynchronizedMode',
                         true
                       )
                     ) {
-                      OB.Dal.transaction(function(tx) {
-                        OB.UTIL.calculateCurrentCash(null, tx);
-                        OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(
-                          frozenReceipt.get('documentnoSuffix'),
-                          frozenReceipt.get('quotationnoSuffix'),
-                          frozenReceipt.get('returnnoSuffix'),
-                          function() {
-                            // the trigger is fired on the receipt object, as there is only 1 that is being updated
-                            receipt.trigger('integrityOk', frozenReceipt); // Is important for module print last receipt. This module listen trigger.
-                            syncSuccessCallback(function() {
-                              serverMessageForQuotation(frozenReceipt);
-                              closeParamCallback();
-                            }, eventParams);
-                          },
-                          tx
-                        );
-                      });
-                    } else {
-                      syncSuccessCallback(function() {
-                        serverMessageForQuotation(frozenReceipt);
-                      }, eventParams);
+                      // the trigger is fired on the receipt object, as there is only 1 that is being updated
+                      receipt.trigger('integrityOk', frozenReceipt); // Is important for module print last receipt. This module listen trigger.
+                      closeParamCallback();
                     }
-                    OB.debug('Ticket closed: runSyncProcess executed');
-                  },
-                  function() {
-                    syncErrorCallback();
-                  }
-                );
-              };
 
-              var executePreSyncReceipt = function(tx) {
-                OB.UTIL.HookManager.executeHooks(
-                  'OBPOS_PreSyncReceipt',
-                  {
-                    receipt: frozenReceipt,
-                    model: model,
-                    tx: tx
-                  },
-                  function(args) {
-                    frozenReceipt.set(
-                      'json',
-                      JSON.stringify(frozenReceipt.serializeToSaveJSON())
-                    );
-                    frozenReceipt.set('hasbeenpaid', 'Y');
-                    // Important: at this point, the frozenReceipt is considered final. Nothing must alter it
-                    // when all the properties of the frozenReceipt have been set, keep a copy
-                    OB.UTIL.clone(receipt, diffReceipt);
-                    OB.Dal.saveInTransaction(tx, frozenReceipt, function() {
-                      successCallback();
-                    });
-                  }
-                );
-              };
-
-              //Create the invoice
-              frozenReceipt.generateInvoice(function(invoice) {
-                if (invoice) {
-                  frozenReceipt.set('calculatedInvoice', invoice);
-                }
-                OB.info(
-                  '[receipt.closed] Starting transaction. ReceiptId: ' +
-                    frozenReceipt.get('id')
-                );
-                OB.Dal.transaction(
-                  function(tx) {
-                    OB.trace('Calculationg cashup information.');
-                    OB.UTIL.cashUpReport(
-                      frozenReceipt,
-                      function(cashUp) {
-                        frozenReceipt.set(
-                          'cashUpReportInformation',
-                          JSON.parse(cashUp.models[0].get('objToSend'))
-                        );
-                        frozenReceipt.set(
-                          'json',
-                          JSON.stringify(frozenReceipt.serializeToJSON())
-                        );
-                        OB.UTIL.setScanningFocus(true);
+                    OB.trace('Execution Sync process.');
+                    OB.MobileApp.model.runSyncProcess(
+                      function() {
+                        // in synchronized mode do the doc sequence update in the success
                         if (
                           OB.MobileApp.model.hasPermission(
                             'OBMOBC_SynchronizedMode',
                             true
                           )
                         ) {
-                          OB.Dal.saveInTransaction(
-                            tx,
-                            frozenReceipt,
-                            function() {
-                              executePreSyncReceipt(tx);
-                            }
-                          );
+                          OB.Dal.transaction(function(tx) {
+                            OB.UTIL.calculateCurrentCash(null, tx);
+                            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(
+                              frozenReceipt.get('documentnoSuffix'),
+                              frozenReceipt.get('quotationnoSuffix'),
+                              frozenReceipt.get('returnnoSuffix'),
+                              function() {
+                                // the trigger is fired on the receipt object, as there is only 1 that is being updated
+                                receipt.trigger('integrityOk', frozenReceipt); // Is important for module print last receipt. This module listen trigger.
+                                syncSuccessCallback(function() {
+                                  serverMessageForQuotation(frozenReceipt);
+                                  closeParamCallback();
+                                }, eventParams);
+                              },
+                              tx
+                            );
+                          });
                         } else {
-                          OB.UTIL.calculateCurrentCash(null, tx);
-                          OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(
-                            frozenReceipt.get('documentnoSuffix'),
-                            frozenReceipt.get('quotationnoSuffix'),
-                            frozenReceipt.get('returnnoSuffix'),
-                            function() {
-                              OB.trace('Saving receipt.');
+                          syncSuccessCallback(function() {
+                            serverMessageForQuotation(frozenReceipt);
+                          }, eventParams);
+                        }
+                        OB.debug('Ticket closed: runSyncProcess executed');
+                      },
+                      function() {
+                        syncErrorCallback();
+                      }
+                    );
+                  };
+
+                  var executePreSyncReceipt = function(tx) {
+                    OB.UTIL.HookManager.executeHooks(
+                      'OBPOS_PreSyncReceipt',
+                      {
+                        receipt: frozenReceipt,
+                        model: model,
+                        tx: tx
+                      },
+                      function(args) {
+                        frozenReceipt.set(
+                          'json',
+                          JSON.stringify(frozenReceipt.serializeToSaveJSON())
+                        );
+                        frozenReceipt.set('hasbeenpaid', 'Y');
+                        // Important: at this point, the frozenReceipt is considered final. Nothing must alter it
+                        // when all the properties of the frozenReceipt have been set, keep a copy
+                        OB.UTIL.clone(receipt, diffReceipt);
+                        OB.Dal.saveInTransaction(tx, frozenReceipt, function() {
+                          successCallback();
+                        });
+                      }
+                    );
+                  };
+
+                  //Create the invoice
+                  frozenReceipt.generateInvoice(function(invoice) {
+                    if (invoice) {
+                      frozenReceipt.set('calculatedInvoice', invoice);
+                    }
+                    OB.info(
+                      '[receipt.closed] Starting transaction. ReceiptId: ' +
+                        frozenReceipt.get('id')
+                    );
+                    OB.Dal.transaction(
+                      function(tx) {
+                        OB.trace('Calculationg cashup information.');
+                        OB.UTIL.cashUpReport(
+                          frozenReceipt,
+                          function(cashUp) {
+                            frozenReceipt.set(
+                              'cashUpReportInformation',
+                              JSON.parse(cashUp.models[0].get('objToSend'))
+                            );
+                            frozenReceipt.set(
+                              'json',
+                              JSON.stringify(frozenReceipt.serializeToJSON())
+                            );
+                            OB.UTIL.setScanningFocus(true);
+                            if (
+                              OB.MobileApp.model.hasPermission(
+                                'OBMOBC_SynchronizedMode',
+                                true
+                              )
+                            ) {
                               OB.Dal.saveInTransaction(
                                 tx,
                                 frozenReceipt,
@@ -571,34 +579,52 @@
                                   executePreSyncReceipt(tx);
                                 }
                               );
-                            },
-                            tx
-                          );
-                        }
+                            } else {
+                              OB.UTIL.calculateCurrentCash(null, tx);
+                              OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(
+                                frozenReceipt.get('documentnoSuffix'),
+                                frozenReceipt.get('quotationnoSuffix'),
+                                frozenReceipt.get('returnnoSuffix'),
+                                function() {
+                                  OB.trace('Saving receipt.');
+                                  OB.Dal.saveInTransaction(
+                                    tx,
+                                    frozenReceipt,
+                                    function() {
+                                      executePreSyncReceipt(tx);
+                                    }
+                                  );
+                                },
+                                tx
+                              );
+                            }
+                          },
+                          tx
+                        );
                       },
-                      tx
-                    );
-                  },
-                  function() {
-                    // the transaction failed
-                    OB.UTIL.ProcessController.finish(
-                      'tapTotalButton',
-                      execution
+                      function() {
+                        // the transaction failed
+                        OB.UTIL.ProcessController.finish(
+                          'tapTotalButton',
+                          execution
+                        );
+                        OB.UTIL.showError(
+                          '[receipt.closed] The transaction failed to be commited. ReceiptId: ' +
+                            receipt.get('id')
+                        );
+                        // rollback other changes
+                        receipt.set('hasbeenpaid', 'N');
+                        frozenReceipt.set('hasbeenpaid', 'N');
+                        receipt.unset('completeTicket');
+                        frozenReceipt.unset('completeTicket');
+                      },
+                      null
                     );
-                    OB.UTIL.showError(
-                      '[receipt.closed] The transaction failed to be commited. ReceiptId: ' +
-                        receipt.get('id')
-                    );
-                    // rollback other changes
-                    receipt.set('hasbeenpaid', 'N');
-                    frozenReceipt.set('hasbeenpaid', 'N');
-                    receipt.unset('completeTicket');
-                    frozenReceipt.unset('completeTicket');
-                  },
-                  null
-                );
-              });
-            }
+                  });
+                }
+              );
+            },
+            handleError
           );
         }
       );
@@ -981,133 +1007,151 @@
                 },
                 function(args) {
                   OB.trace('Execution of pre order save hook OK.');
-                  if (args && args.cancellation && args.cancellation === true) {
+
+                  var handleError = function() {
                     hasError = true;
                     completeMultiOrder();
+                  };
+
+                  if (args && args.cancellation && args.cancellation === true) {
+                    handleError();
                     return true;
                   }
-                  OB.UTIL.TicketCloseUtils.processChangePayments(
-                    args.receipt,
+
+                  OB.UTIL.TicketCloseUtils.checkOrdersUpdated(
+                    receipt,
                     function() {
-                      var currentReceipt = args.receipt;
-                      currentReceipt.prepareToSend(function() {
-                        if (
-                          currentReceipt.get('orderType') !== 2 &&
-                          currentReceipt.get('orderType') !== 3
-                        ) {
-                          var negativeLines = _.filter(
-                            currentReceipt.get('lines').models,
-                            function(line) {
-                              return line.get('qty') < 0;
+                      OB.UTIL.TicketCloseUtils.processChangePayments(
+                        args.receipt,
+                        function() {
+                          var currentReceipt = args.receipt;
+                          currentReceipt.prepareToSend(function() {
+                            if (
+                              currentReceipt.get('orderType') !== 2 &&
+                              currentReceipt.get('orderType') !== 3
+                            ) {
+                              var negativeLines = _.filter(
+                                currentReceipt.get('lines').models,
+                                function(line) {
+                                  return line.get('qty') < 0;
+                                }
+                              ).length;
+                              if (
+                                negativeLines ===
+                                  currentReceipt.get('lines').models.length ||
+                                (negativeLines > 0 &&
+                                  OB.MobileApp.model.get('permissions')
+                                    .OBPOS_SalesWithOneLineNegativeAsReturns)
+                              ) {
+                                currentReceipt.setOrderType(
+                                  'OBPOS_receipt.return',
+                                  OB.DEC.One,
+                                  {
+                                    applyPromotions: false,
+                                    saveOrder: false
+                                  }
+                                );
+                              } else {
+                                currentReceipt.setOrderType('', OB.DEC.Zero, {
+                                  applyPromotions: false,
+                                  saveOrder: false
+                                });
+                              }
+                            }
+                            currentReceipt.set('orderDate', new Date());
+
+                            var creationDate,
+                              normalizedCreationDate = OB.I18N.normalizeDate(
+                                currentReceipt.get('creationDate')
+                              );
+                            if (normalizedCreationDate === null) {
+                              creationDate = new Date();
+                              normalizedCreationDate = OB.I18N.normalizeDate(
+                                creationDate
+                              );
+                            } else {
+                              creationDate = new Date(normalizedCreationDate);
                             }
-                          ).length;
-                          if (
-                            negativeLines ===
-                              currentReceipt.get('lines').models.length ||
-                            (negativeLines > 0 &&
-                              OB.MobileApp.model.get('permissions')
-                                .OBPOS_SalesWithOneLineNegativeAsReturns)
-                          ) {
-                            currentReceipt.setOrderType(
-                              'OBPOS_receipt.return',
-                              OB.DEC.One,
-                              {
-                                applyPromotions: false,
-                                saveOrder: false
-                              }
+                            currentReceipt.set(
+                              'creationDate',
+                              normalizedCreationDate
+                            );
+                            currentReceipt.set(
+                              'movementDate',
+                              OB.I18N.normalizeDate(new Date())
+                            );
+                            currentReceipt.set(
+                              'accountingDate',
+                              OB.I18N.normalizeDate(new Date())
+                            );
+
+                            delete currentReceipt.attributes.json;
+                            currentReceipt.set(
+                              'timezoneOffset',
+                              creationDate.getTimezoneOffset()
+                            );
+                            currentReceipt.set(
+                              'created',
+                              creationDate.getTime()
+                            );
+                            currentReceipt.set(
+                              'obposCreatedabsolute',
+                              OB.I18N.formatDateISO(creationDate)
+                            ); // Absolute date in ISO format
+                            currentReceipt.set(
+                              'obposAppCashup',
+                              OB.MobileApp.model.get('terminal').cashUpId
                             );
-                          } else {
-                            currentReceipt.setOrderType('', OB.DEC.Zero, {
-                              applyPromotions: false,
-                              saveOrder: false
-                            });
-                          }
-                        }
-                        currentReceipt.set('orderDate', new Date());
+                            if (
+                              OB.UTIL.isNullOrUndefined(
+                                currentReceipt.get('amountToLayaway')
+                              )
+                            ) {
+                              currentReceipt.set('completeTicket', true);
+                            }
+                            // multiterminal support
+                            // be sure that the active terminal is the one set as the order proprietary
+                            currentReceipt.set(
+                              'posTerminal',
+                              OB.MobileApp.model.get('terminal').id
+                            );
+                            currentReceipt.set(
+                              'posTerminal' +
+                                OB.Constants.FIELDSEPARATOR +
+                                OB.Constants.IDENTIFIER,
+                              OB.MobileApp.model.get('terminal')._identifier
+                            );
+
+                            // Set the quantities to deliver
+                            currentReceipt.setQuantitiesToDeliver();
 
-                        var creationDate,
-                          normalizedCreationDate = OB.I18N.normalizeDate(
-                            currentReceipt.get('creationDate')
-                          );
-                        if (normalizedCreationDate === null) {
-                          creationDate = new Date();
-                          normalizedCreationDate = OB.I18N.normalizeDate(
-                            creationDate
-                          );
-                        } else {
-                          creationDate = new Date(normalizedCreationDate);
+                            currentReceipt
+                              .get('approvals')
+                              .forEach(function(approval) {
+                                if (typeof approval.approvalType === 'object') {
+                                  approval.approvalMessage = OB.I18N.getLabel(
+                                    approval.approvalType.message,
+                                    approval.approvalType.params
+                                  );
+                                  approval.approvalType =
+                                    approval.approvalType.approval;
+                                }
+                              });
+
+                            currentReceipt.generateInvoice(function(invoice) {
+                              if (invoice) {
+                                currentReceipt.set(
+                                  'calculatedInvoice',
+                                  invoice
+                                );
+                              }
+                              completeMultiOrder();
+                            });
+                          });
                         }
-                        currentReceipt.set(
-                          'creationDate',
-                          normalizedCreationDate
-                        );
-                        currentReceipt.set(
-                          'movementDate',
-                          OB.I18N.normalizeDate(new Date())
-                        );
-                        currentReceipt.set(
-                          'accountingDate',
-                          OB.I18N.normalizeDate(new Date())
-                        );
-
-                        delete currentReceipt.attributes.json;
-                        currentReceipt.set(
-                          'timezoneOffset',
-                          creationDate.getTimezoneOffset()
-                        );
-                        currentReceipt.set('created', creationDate.getTime());
-                        currentReceipt.set(
-                          'obposCreatedabsolute',
-                          OB.I18N.formatDateISO(creationDate)
-                        ); // Absolute date in ISO format
-                        currentReceipt.set(
-                          'obposAppCashup',
-                          OB.MobileApp.model.get('terminal').cashUpId
-                        );
-                        if (
-                          OB.UTIL.isNullOrUndefined(
-                            currentReceipt.get('amountToLayaway')
-                          )
-                        ) {
-                          currentReceipt.set('completeTicket', true);
-                        }
-                        // multiterminal support
-                        // be sure that the active terminal is the one set as the order proprietary
-                        currentReceipt.set(
-                          'posTerminal',
-                          OB.MobileApp.model.get('terminal').id
-                        );
-                        currentReceipt.set(
-                          'posTerminal' +
-                            OB.Constants.FIELDSEPARATOR +
-                            OB.Constants.IDENTIFIER,
-                          OB.MobileApp.model.get('terminal')._identifier
-                        );
-
-                        // Set the quantities to deliver
-                        currentReceipt.setQuantitiesToDeliver();
-
-                        currentReceipt
-                          .get('approvals')
-                          .forEach(function(approval) {
-                            if (typeof approval.approvalType === 'object') {
-                              approval.approvalMessage = OB.I18N.getLabel(
-                                approval.approvalType.message,
-                                approval.approvalType.params
-                              );
-                              approval.approvalType =
-                                approval.approvalType.approval;
-                            }
-                          });
-
-                        currentReceipt.generateInvoice(function(invoice) {
-                          if (invoice) {
-                            currentReceipt.set('calculatedInvoice', invoice);
-                          }
-                          completeMultiOrder();
-                        });
-                      });
-                    }
+                      );
+                    },
+                    handleError
                   );
                 }
               );
diff --git a/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js b/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/model/pointofsale-model.js
@@ -1109,95 +1109,106 @@
         }
 
         function updateCashup() {
-          auxReceipt.set('timezoneOffset', new Date().getTimezoneOffset());
-          auxReceipt.set('gross', OB.DEC.Zero);
-          auxReceipt.set('isVoided', true);
-          auxReceipt.set('orderType', 3);
-          auxReceipt.prepareToSend(function() {
-            OB.Dal.transaction(function(tx) {
-              OB.UTIL.cashUpReport(
-                auxReceipt,
-                function(cashUp) {
-                  auxReceipt.set(
-                    'cashUpReportInformation',
-                    JSON.parse(cashUp.models[0].get('objToSend'))
-                  );
-                  OB.UTIL.HookManager.executeHooks(
-                    'OBPOS_PreSyncReceipt',
-                    {
-                      receipt: receipt,
-                      model: me,
-                      tx: tx
-                    },
-                    function(args) {
+          OB.UTIL.TicketCloseUtils.checkOrdersUpdated(
+            auxReceipt,
+            function() {
+              auxReceipt.set('timezoneOffset', new Date().getTimezoneOffset());
+              auxReceipt.set('gross', OB.DEC.Zero);
+              auxReceipt.set('isVoided', true);
+              auxReceipt.set('orderType', 3);
+              auxReceipt.prepareToSend(function() {
+                OB.Dal.transaction(function(tx) {
+                  OB.UTIL.cashUpReport(
+                    auxReceipt,
+                    function(cashUp) {
                       auxReceipt.set(
-                        'json',
-                        JSON.stringify(receipt.serializeToSaveJSON())
+                        'cashUpReportInformation',
+                        JSON.parse(cashUp.models[0].get('objToSend'))
                       );
-                      process.exec(
+                      OB.UTIL.HookManager.executeHooks(
+                        'OBPOS_PreSyncReceipt',
                         {
-                          messageId: OB.UTIL.get_UUID(),
-                          data: [
-                            {
-                              id: auxReceipt.get('id'),
-                              posTerminal: OB.MobileApp.model.get('terminal')
-                                .id,
-                              order: auxReceipt
-                            }
-                          ]
+                          receipt: receipt,
+                          model: me,
+                          tx: tx
                         },
-                        function(data) {
-                          if (data && data.exception) {
-                            revertCashupReport(function() {
-                              if (data.exception.message) {
-                                OB.UTIL.showConfirmation.display(
-                                  OB.I18N.getLabel('OBMOBC_Error'),
-                                  data.exception.message
+                        function(args) {
+                          auxReceipt.set(
+                            'json',
+                            JSON.stringify(receipt.serializeToSaveJSON())
+                          );
+                          process.exec(
+                            {
+                              messageId: OB.UTIL.get_UUID(),
+                              data: [
+                                {
+                                  id: auxReceipt.get('id'),
+                                  posTerminal: OB.MobileApp.model.get(
+                                    'terminal'
+                                  ).id,
+                                  order: auxReceipt
+                                }
+                              ]
+                            },
+                            function(data) {
+                              if (data && data.exception) {
+                                revertCashupReport(function() {
+                                  if (data.exception.message) {
+                                    OB.UTIL.showConfirmation.display(
+                                      OB.I18N.getLabel('OBMOBC_Error'),
+                                      data.exception.message
+                                    );
+                                  } else {
+                                    OB.UTIL.showError(
+                                      OB.I18N.getLabel(
+                                        'OBPOS_MsgErrorVoidLayaway'
+                                      )
+                                    );
+                                  }
+                                  finishVoidLayaway();
+                                });
+                              } else {
+                                auxReceipt.trigger(
+                                  OB.MobileApp.model.get('terminal')
+                                    .defaultwebpostab
                                 );
-                              } else {
-                                OB.UTIL.showError(
-                                  OB.I18N.getLabel('OBPOS_MsgErrorVoidLayaway')
+                                OB.Dal.remove(receipt, null, function(tx, err) {
+                                  OB.UTIL.showError(err);
+                                });
+                                OB.UTIL.clone(auxReceipt, receiptForPrinting);
+                                auxReceipt.trigger('print', receiptForPrinting);
+                                orderList.deleteCurrent();
+                                receipt.trigger('change:gross', receipt);
+                                OB.UTIL.showSuccess(
+                                  OB.I18N.getLabel(
+                                    'OBPOS_MsgSuccessVoidLayaway'
+                                  )
                                 );
+                                finishVoidLayaway();
                               }
-                              finishVoidLayaway();
-                            });
-                          } else {
-                            auxReceipt.trigger(
-                              OB.MobileApp.model.get('terminal')
-                                .defaultwebpostab
-                            );
-                            OB.Dal.remove(receipt, null, function(tx, err) {
-                              OB.UTIL.showError(err);
-                            });
-                            OB.UTIL.clone(auxReceipt, receiptForPrinting);
-                            auxReceipt.trigger('print', receiptForPrinting);
-                            orderList.deleteCurrent();
-                            receipt.trigger('change:gross', receipt);
-                            OB.UTIL.showSuccess(
-                              OB.I18N.getLabel('OBPOS_MsgSuccessVoidLayaway')
-                            );
-                            finishVoidLayaway();
-                          }
+                            },
+                            function() {
+                              revertCashupReport(function() {
+                                OB.UTIL.showError(
+                                  OB.I18N.getLabel(
+                                    'OBPOS_OfflineWindowRequiresOnline'
+                                  )
+                                );
+                                finishVoidLayaway();
+                              });
+                            }
+                          );
                         },
-                        function() {
-                          revertCashupReport(function() {
-                            OB.UTIL.showError(
-                              OB.I18N.getLabel(
-                                'OBPOS_OfflineWindowRequiresOnline'
-                              )
-                            );
-                            finishVoidLayaway();
-                          });
-                        }
+                        tx
                       );
                     },
                     tx
                   );
-                },
-                tx
-              );
-            });
-          });
+                });
+              });
+            },
+            finishVoidLayaway
+          );
         }
 
         OB.UTIL.clone(receipt, auxReceipt);
@@ -1229,333 +1240,379 @@
               cloneOrderForPrinting = new OB.Model.Order(),
               creationDate;
 
-            receipt.prepareToSend(function() {
-              creationDate = new Date();
-              receipt.set('creationDate', OB.I18N.normalizeDate(creationDate));
-              receipt.set(
-                'obposCreatedabsolute',
-                OB.I18N.formatDateISO(creationDate)
-              ); // Absolute date in ISO format
-              receipt.set(
-                'obposAppCashup',
-                OB.MobileApp.model.get('terminal').cashUpId
-              );
-              OB.UTIL.HookManager.executeHooks(
-                'OBPOS_FinishCancelLayaway',
-                {
-                  context: me,
-                  model: me,
-                  receipt: receipt
-                },
-                function(args) {
+            OB.UTIL.TicketCloseUtils.checkOrdersUpdated(
+              receipt.get('canceledorder'),
+              function() {
+                receipt.prepareToSend(function() {
+                  creationDate = new Date();
+                  receipt.set(
+                    'creationDate',
+                    OB.I18N.normalizeDate(creationDate)
+                  );
+                  receipt.set(
+                    'obposCreatedabsolute',
+                    OB.I18N.formatDateISO(creationDate)
+                  ); // Absolute date in ISO format
+                  receipt.set(
+                    'obposAppCashup',
+                    OB.MobileApp.model.get('terminal').cashUpId
+                  );
                   OB.UTIL.HookManager.executeHooks(
-                    'OBPOS_PreSyncReceipt',
+                    'OBPOS_FinishCancelLayaway',
                     {
-                      receipt: receipt,
-                      model: me
+                      context: me,
+                      model: me,
+                      receipt: receipt
                     },
                     function(args) {
-                      OB.Dal.transaction(
-                        function(tx) {
-                          if (receipt.isNegative()) {
-                            receipt.get('payments').forEach(function(payment) {
-                              payment.set(
-                                'amount',
-                                OB.DEC.mul(payment.get('amount'), -1)
-                              );
-                              payment.set(
-                                'origAmount',
-                                OB.DEC.mul(payment.get('origAmount'), -1)
-                              );
-                              payment.set(
-                                'paid',
-                                OB.DEC.mul(payment.get('paid'), -1)
+                      OB.UTIL.HookManager.executeHooks(
+                        'OBPOS_PreSyncReceipt',
+                        {
+                          receipt: receipt,
+                          model: me
+                        },
+                        function(args) {
+                          OB.Dal.transaction(
+                            function(tx) {
+                              if (receipt.isNegative()) {
+                                receipt
+                                  .get('payments')
+                                  .forEach(function(payment) {
+                                    payment.set(
+                                      'amount',
+                                      OB.DEC.mul(payment.get('amount'), -1)
+                                    );
+                                    payment.set(
+                                      'origAmount',
+                                      OB.DEC.mul(payment.get('origAmount'), -1)
+                                    );
+                                    payment.set(
+                                      'paid',
+                                      OB.DEC.mul(payment.get('paid'), -1)
+                                    );
+                                  });
+                              }
+                              OB.UTIL.cashUpReport(
+                                receipt,
+                                function(cashUp) {
+                                  var cancelLayawayModel = new OB.Model.CancelLayaway(),
+                                    cancelLayawayObj;
+
+                                  receipt.set(
+                                    'cashUpReportInformation',
+                                    JSON.parse(
+                                      cashUp.models[0].get('objToSend')
+                                    )
+                                  );
+                                  receipt.set('created', new Date().getTime());
+                                  receipt.set(
+                                    'json',
+                                    JSON.stringify(
+                                      receipt.serializeToSaveJSON()
+                                    )
+                                  );
+
+                                  OB.UTIL.clone(receipt, cloneOrderForNew);
+                                  OB.UTIL.clone(receipt, cloneOrderForPrinting);
+
+                                  cancelLayawayObj = receipt.serializeToJSON();
+                                  cancelLayawayModel.set(
+                                    'json',
+                                    JSON.stringify(cancelLayawayObj)
+                                  );
+                                  OB.Dal.getInTransaction(
+                                    tx,
+                                    OB.Model.Order,
+                                    receipt.id,
+                                    function(model) {
+                                      OB.Dal.removeInTransaction(tx, model);
+                                    }
+                                  );
+                                  OB.Dal.saveInTransaction(
+                                    tx,
+                                    cancelLayawayModel
+                                  );
+                                },
+                                tx
                               );
-                            });
-                          }
-                          OB.UTIL.cashUpReport(
-                            receipt,
-                            function(cashUp) {
-                              var cancelLayawayModel = new OB.Model.CancelLayaway(),
-                                cancelLayawayObj;
-
-                              receipt.set(
-                                'cashUpReportInformation',
-                                JSON.parse(cashUp.models[0].get('objToSend'))
+                            },
+                            function() {
+                              //transaction error callback
+                              OB.error(
+                                '[cancellayaway] The transaction failed to be commited. LayawayId: ' +
+                                  receipt.get('id')
                               );
-                              receipt.set('created', new Date().getTime());
-                              receipt.set(
-                                'json',
-                                JSON.stringify(receipt.serializeToSaveJSON())
+                              OB.UTIL.ProcessController.finish(
+                                'cancelLayaway',
+                                execution
+                              );
+                            },
+                            function() {
+                              //transaction success callback
+                              OB.info(
+                                '[cancellayaway] Transaction success. LayawayId: ' +
+                                  receipt.get('id')
                               );
 
-                              OB.UTIL.clone(receipt, cloneOrderForNew);
-                              OB.UTIL.clone(receipt, cloneOrderForPrinting);
+                              function cancelAndNew() {
+                                if (
+                                  OB.MobileApp.model.hasPermission(
+                                    'OBPOS_cancelLayawayAndNew',
+                                    true
+                                  )
+                                ) {
+                                  OB.UTIL.showConfirmation.display(
+                                    OB.I18N.getLabel(
+                                      'OBPOS_cancelLayawayAndNewHeader'
+                                    ),
+                                    OB.I18N.getLabel(
+                                      'OBPOS_cancelLayawayAndNewBody'
+                                    ),
+                                    [
+                                      {
+                                        label: OB.I18N.getLabel('OBPOS_LblOk'),
+                                        action: function() {
+                                          orderList.addNewOrder();
+                                          var linesMap = {},
+                                            order = orderList.modelorder,
+                                            addRelatedLines,
+                                            addLineToTicket;
+
+                                          var finalCallback = function() {
+                                            order.unset(
+                                              'preventServicesUpdate'
+                                            );
+                                            order
+                                              .get('lines')
+                                              .trigger('updateRelations');
+                                          };
+
+                                          addRelatedLines = function(index) {
+                                            if (
+                                              index ===
+                                              order.get('lines').length
+                                            ) {
+                                              finalCallback();
+                                              return;
+                                            }
+                                            var line = order
+                                                .get('lines')
+                                                .at(index),
+                                              oldLine = linesMap[line.id];
+                                            if (oldLine.get('relatedLines')) {
+                                              line.set('relatedLines', []);
+                                              _.each(
+                                                oldLine.get('relatedLines'),
+                                                function(relatedLine) {
+                                                  var newRelatedLine = _.clone(
+                                                    relatedLine
+                                                  );
+                                                  // If the service is not a deferred service, the related line, documentNo
+                                                  // and orderId must be updated. If it is, is must be marked as deferred
+                                                  if (
+                                                    !newRelatedLine.otherTicket
+                                                  ) {
+                                                    var i,
+                                                      keys = _.keys(linesMap);
+                                                    newRelatedLine.orderDocumentNo = order.get(
+                                                      'documentNo'
+                                                    );
+                                                    newRelatedLine.orderId =
+                                                      order.id;
+                                                    for (
+                                                      i = 0;
+                                                      i < keys.length;
+                                                      i++
+                                                    ) {
+                                                      var key = keys[i];
+                                                      if (
+                                                        newRelatedLine.orderlineId ===
+                                                        linesMap[key].id
+                                                      ) {
+                                                        newRelatedLine.orderlineId = key;
+                                                        break;
+                                                      }
+                                                    }
+                                                  }
+                                                  line
+                                                    .get('relatedLines')
+                                                    .push(newRelatedLine);
+                                                  if (
+                                                    !order.get('hasServices')
+                                                  ) {
+                                                    order.set(
+                                                      'hasServices',
+                                                      true
+                                                    );
+                                                  }
+                                                }
+                                              );
+                                            }
+                                            // Hook to allow any needed relation from an external module
+                                            OB.UTIL.HookManager.executeHooks(
+                                              'OBPOS_CancelAndNewAddLineRelation',
+                                              {
+                                                order: order,
+                                                cloneOrderForNew: cloneOrderForNew,
+                                                line: line,
+                                                oldLine: oldLine,
+                                                linesMap: linesMap
+                                              },
+                                              function(args) {
+                                                addRelatedLines(index + 1);
+                                              }
+                                            );
+                                          };
 
-                              cancelLayawayObj = receipt.serializeToJSON();
-                              cancelLayawayModel.set(
-                                'json',
-                                JSON.stringify(cancelLayawayObj)
-                              );
-                              OB.Dal.getInTransaction(
-                                tx,
-                                OB.Model.Order,
-                                receipt.id,
-                                function(model) {
-                                  OB.Dal.removeInTransaction(tx, model);
+                                          addLineToTicket = function(idx) {
+                                            if (
+                                              idx ===
+                                              cloneOrderForNew.get('lines')
+                                                .length
+                                            ) {
+                                              addRelatedLines(0);
+                                            } else {
+                                              var line = cloneOrderForNew
+                                                .get('lines')
+                                                .at(idx);
+                                              order.addProduct(
+                                                line.get('product'),
+                                                -line.get('qty'),
+                                                {
+                                                  isSilentAddProduct: true
+                                                },
+                                                undefined,
+                                                function(success, orderline) {
+                                                  if (success) {
+                                                    linesMap[
+                                                      order
+                                                        .get('lines')
+                                                        .at(
+                                                          order.get('lines')
+                                                            .length - 1
+                                                        ).id
+                                                    ] = line;
+                                                  }
+                                                  addLineToTicket(idx + 1);
+                                                }
+                                              );
+                                            }
+                                          };
+
+                                          if (
+                                            cloneOrderForNew.get('isLayaway')
+                                          ) {
+                                            OB.MobileApp.view.$.containerWindow
+                                              .getRoot()
+                                              .showDivText(null, {
+                                                permission: null,
+                                                orderType: 2
+                                              });
+                                          }
+                                          order.set(
+                                            'bp',
+                                            cloneOrderForNew.get('bp')
+                                          );
+                                          addLineToTicket(0);
+                                        }
+                                      },
+                                      {
+                                        label: OB.I18N.getLabel('OBPOS_Cancel')
+                                      }
+                                    ]
+                                  );
+                                }
+                              }
+
+                              function syncProcessCallback() {
+                                OB.UTIL.showSuccess(
+                                  OB.I18N.getLabel(
+                                    'OBPOS_MsgSuccessCancelLayaway',
+                                    [
+                                      receipt
+                                        .get('canceledorder')
+                                        .get('documentNo')
+                                    ]
+                                  )
+                                );
+                                orderList.deleteCurrent();
+                                OB.UTIL.calculateCurrentCash();
+                                OB.UTIL.ProcessController.finish(
+                                  'cancelLayaway',
+                                  execution
+                                );
+                                receipt.trigger(
+                                  'print',
+                                  cloneOrderForPrinting,
+                                  {
+                                    callback: cancelAndNew,
+                                    forceCallback: true
+                                  }
+                                );
+                              }
+
+                              OB.MobileApp.model.runSyncProcess(
+                                function() {
+                                  syncProcessCallback();
+                                },
+                                function() {
+                                  if (
+                                    OB.MobileApp.model.hasPermission(
+                                      'OBMOBC_SynchronizedMode',
+                                      true
+                                    )
+                                  ) {
+                                    OB.Dal.get(
+                                      OB.Model.Order,
+                                      receipt.get('id'),
+                                      function(loadedReceipt) {
+                                        receipt.clearWith(loadedReceipt);
+                                        //We need to restore the payment tab, as that's what the user should see if synchronization fails
+                                        OB.MobileApp.view.waterfall(
+                                          'onTabChange',
+                                          {
+                                            tabPanel: 'payment',
+                                            keyboard: 'toolbarpayment',
+                                            edit: false
+                                          }
+                                        );
+                                        receipt.set('hasbeenpaid', 'N');
+                                        receipt.unset('completeTicket');
+                                        receipt.trigger('updatePending');
+                                        OB.Dal.save(
+                                          receipt,
+                                          function() {
+                                            OB.UTIL.calculateCurrentCash(
+                                              function() {
+                                                OB.UTIL.ProcessController.finish(
+                                                  'cancelLayaway',
+                                                  execution
+                                                );
+                                              }
+                                            );
+                                          },
+                                          null,
+                                          false
+                                        );
+                                      }
+                                    );
+                                  } else {
+                                    syncProcessCallback();
+                                  }
                                 }
                               );
-                              OB.Dal.saveInTransaction(tx, cancelLayawayModel);
-                            },
-                            tx
-                          );
-                        },
-                        function() {
-                          //transaction error callback
-                          OB.error(
-                            '[cancellayaway] The transaction failed to be commited. LayawayId: ' +
-                              receipt.get('id')
-                          );
-                          OB.UTIL.ProcessController.finish(
-                            'cancelLayaway',
-                            execution
-                          );
-                        },
-                        function() {
-                          //transaction success callback
-                          OB.info(
-                            '[cancellayaway] Transaction success. LayawayId: ' +
-                              receipt.get('id')
-                          );
-
-                          function cancelAndNew() {
-                            if (
-                              OB.MobileApp.model.hasPermission(
-                                'OBPOS_cancelLayawayAndNew',
-                                true
-                              )
-                            ) {
-                              OB.UTIL.showConfirmation.display(
-                                OB.I18N.getLabel(
-                                  'OBPOS_cancelLayawayAndNewHeader'
-                                ),
-                                OB.I18N.getLabel(
-                                  'OBPOS_cancelLayawayAndNewBody'
-                                ),
-                                [
-                                  {
-                                    label: OB.I18N.getLabel('OBPOS_LblOk'),
-                                    action: function() {
-                                      orderList.addNewOrder();
-                                      var linesMap = {},
-                                        order = orderList.modelorder,
-                                        addRelatedLines,
-                                        addLineToTicket;
-
-                                      var finalCallback = function() {
-                                        order.unset('preventServicesUpdate');
-                                        order
-                                          .get('lines')
-                                          .trigger('updateRelations');
-                                      };
-
-                                      addRelatedLines = function(index) {
-                                        if (
-                                          index === order.get('lines').length
-                                        ) {
-                                          finalCallback();
-                                          return;
-                                        }
-                                        var line = order.get('lines').at(index),
-                                          oldLine = linesMap[line.id];
-                                        if (oldLine.get('relatedLines')) {
-                                          line.set('relatedLines', []);
-                                          _.each(
-                                            oldLine.get('relatedLines'),
-                                            function(relatedLine) {
-                                              var newRelatedLine = _.clone(
-                                                relatedLine
-                                              );
-                                              // If the service is not a deferred service, the related line, documentNo
-                                              // and orderId must be updated. If it is, is must be marked as deferred
-                                              if (!newRelatedLine.otherTicket) {
-                                                var i,
-                                                  keys = _.keys(linesMap);
-                                                newRelatedLine.orderDocumentNo = order.get(
-                                                  'documentNo'
-                                                );
-                                                newRelatedLine.orderId =
-                                                  order.id;
-                                                for (
-                                                  i = 0;
-                                                  i < keys.length;
-                                                  i++
-                                                ) {
-                                                  var key = keys[i];
-                                                  if (
-                                                    newRelatedLine.orderlineId ===
-                                                    linesMap[key].id
-                                                  ) {
-                                                    newRelatedLine.orderlineId = key;
-                                                    break;
-                                                  }
-                                                }
-                                              }
-                                              line
-                                                .get('relatedLines')
-                                                .push(newRelatedLine);
-                                              if (!order.get('hasServices')) {
-                                                order.set('hasServices', true);
-                                              }
-                                            }
-                                          );
-                                        }
-                                        // Hook to allow any needed relation from an external module
-                                        OB.UTIL.HookManager.executeHooks(
-                                          'OBPOS_CancelAndNewAddLineRelation',
-                                          {
-                                            order: order,
-                                            cloneOrderForNew: cloneOrderForNew,
-                                            line: line,
-                                            oldLine: oldLine,
-                                            linesMap: linesMap
-                                          },
-                                          function(args) {
-                                            addRelatedLines(index + 1);
-                                          }
-                                        );
-                                      };
-
-                                      addLineToTicket = function(idx) {
-                                        if (
-                                          idx ===
-                                          cloneOrderForNew.get('lines').length
-                                        ) {
-                                          addRelatedLines(0);
-                                        } else {
-                                          var line = cloneOrderForNew
-                                            .get('lines')
-                                            .at(idx);
-                                          order.addProduct(
-                                            line.get('product'),
-                                            -line.get('qty'),
-                                            {
-                                              isSilentAddProduct: true
-                                            },
-                                            undefined,
-                                            function(success, orderline) {
-                                              if (success) {
-                                                linesMap[
-                                                  order
-                                                    .get('lines')
-                                                    .at(
-                                                      order.get('lines')
-                                                        .length - 1
-                                                    ).id
-                                                ] = line;
-                                              }
-                                              addLineToTicket(idx + 1);
-                                            }
-                                          );
-                                        }
-                                      };
-
-                                      if (cloneOrderForNew.get('isLayaway')) {
-                                        OB.MobileApp.view.$.containerWindow
-                                          .getRoot()
-                                          .showDivText(null, {
-                                            permission: null,
-                                            orderType: 2
-                                          });
-                                      }
-                                      order.set(
-                                        'bp',
-                                        cloneOrderForNew.get('bp')
-                                      );
-                                      addLineToTicket(0);
-                                    }
-                                  },
-                                  {
-                                    label: OB.I18N.getLabel('OBPOS_Cancel')
-                                  }
-                                ]
-                              );
-                            }
-                          }
-
-                          function syncProcessCallback() {
-                            OB.UTIL.showSuccess(
-                              OB.I18N.getLabel(
-                                'OBPOS_MsgSuccessCancelLayaway',
-                                [receipt.get('canceledorder').get('documentNo')]
-                              )
-                            );
-                            orderList.deleteCurrent();
-                            OB.UTIL.calculateCurrentCash();
-                            OB.UTIL.ProcessController.finish(
-                              'cancelLayaway',
-                              execution
-                            );
-                            receipt.trigger('print', cloneOrderForPrinting, {
-                              callback: cancelAndNew,
-                              forceCallback: true
-                            });
-                          }
-
-                          OB.MobileApp.model.runSyncProcess(
-                            function() {
-                              syncProcessCallback();
-                            },
-                            function() {
-                              if (
-                                OB.MobileApp.model.hasPermission(
-                                  'OBMOBC_SynchronizedMode',
-                                  true
-                                )
-                              ) {
-                                OB.Dal.get(
-                                  OB.Model.Order,
-                                  receipt.get('id'),
-                                  function(loadedReceipt) {
-                                    receipt.clearWith(loadedReceipt);
-                                    //We need to restore the payment tab, as that's what the user should see if synchronization fails
-                                    OB.MobileApp.view.waterfall('onTabChange', {
-                                      tabPanel: 'payment',
-                                      keyboard: 'toolbarpayment',
-                                      edit: false
-                                    });
-                                    receipt.set('hasbeenpaid', 'N');
-                                    receipt.unset('completeTicket');
-                                    receipt.trigger('updatePending');
-                                    OB.Dal.save(
-                                      receipt,
-                                      function() {
-                                        OB.UTIL.calculateCurrentCash(
-                                          function() {
-                                            OB.UTIL.ProcessController.finish(
-                                              'cancelLayaway',
-                                              execution
-                                            );
-                                          }
-                                        );
-                                      },
-                                      null,
-                                      false
-                                    );
-                                  }
-                                );
-                              } else {
-                                syncProcessCallback();
-                              }
                             }
                           );
                         }
                       );
                     }
                   );
-                }
-              );
-            });
+                });
+              },
+              function() {
+                OB.UTIL.ProcessController.finish('cancelLayaway', execution);
+              }
+            );
           };
 
           receipt.canCancelOrder(
diff --git a/web/org.openbravo.retail.posterminal/js/utils/ticketCloseUtils.js b/web/org.openbravo.retail.posterminal/js/utils/ticketCloseUtils.js
--- a/web/org.openbravo.retail.posterminal/js/utils/ticketCloseUtils.js
+++ b/web/org.openbravo.retail.posterminal/js/utils/ticketCloseUtils.js
@@ -448,4 +448,139 @@
       })
       .join(' + ');
   };
+
+  OB.UTIL.TicketCloseUtils.checkOrdersUpdated = function(
+    order,
+    successCallback,
+    errorCallback
+  ) {
+    var errorPopup = function(offline, errorType) {
+      var title = '',
+        message = '',
+        buttons = [];
+      if (
+        offline &&
+        !OB.MobileApp.model.hasPermission(
+          'OBPOS_AllowToSynchronizeLoadedReceiptsOffline',
+          true
+        )
+      ) {
+        title = OB.I18N.getLabel('OBPOS_ErrorCheckingReceipt');
+        message = OB.I18N.getLabel('OBPOS_NotPossibleToConfirmReceipt', [
+          order.get('documentNo')
+        ]);
+        buttons.push({
+          label: OB.I18N.getLabel('OBMOBC_LblOk'),
+          isConfirmButton: true,
+          action: function() {
+            errorCallback();
+          }
+        });
+      } else if (
+        offline &&
+        OB.MobileApp.model.hasPermission(
+          'OBPOS_AllowToSynchronizeLoadedReceiptsOffline',
+          true
+        )
+      ) {
+        title = OB.I18N.getLabel('OBPOS_UpdatedReceipt');
+        message = OB.I18N.getLabel('OBPOS_NotPossibleToConfirmReceiptWarn', [
+          order.get('documentNo')
+        ]);
+        buttons.push({
+          label: OB.I18N.getLabel('OBMOBC_LblOk'),
+          isConfirmButton: true,
+          action: function() {
+            successCallback();
+          }
+        });
+        buttons.push({
+          label: OB.I18N.getLabel('OBMOBC_LblCancel'),
+          action: function() {
+            errorCallback();
+          }
+        });
+      } else {
+        title = OB.I18N.getLabel('OBPOS_ErrorCheckingReceipt');
+        if (errorType === 'P') {
+          message = OB.I18N.getLabel('OBPOS_SyncPending', [
+            order.get('documentNo')
+          ]);
+        } else if (errorType === 'E') {
+          message = OB.I18N.getLabel('OBPOS_SyncWithErrors', [
+            order.get('documentNo')
+          ]);
+        } else {
+          message = OB.I18N.getLabel('OBPOS_RemoveAndLoad', [
+            order.get('documentNo')
+          ]);
+        }
+
+        buttons.push({
+          label: OB.I18N.getLabel('OBMOBC_LblOk'),
+          isConfirmButton: true,
+          action: function() {
+            errorCallback();
+          }
+        });
+      }
+      OB.UTIL.showConfirmation.display(title, message, buttons, {
+        onHideFunction: function() {
+          errorCallback();
+        }
+      });
+    };
+
+    if (OB.MobileApp.model.hasPermission('OBMOBC_SynchronizedMode', true)) {
+      successCallback();
+      return;
+    }
+
+    if (!order.get('isLayaway') && !order.get('isPaid')) {
+      successCallback();
+      return;
+    }
+
+    if (!OB.MobileApp.model.get('connectedToERP') || !navigator.onLine) {
+      errorPopup(true);
+      return;
+    }
+
+    var checkUpdated = new OB.DS.Process(
+        'org.openbravo.retail.posterminal.process.CheckUpdated'
+      ),
+      _order = {
+        id: order.id,
+        loaded: order.get('loaded'),
+        lines: []
+      };
+    _.each(order.get('lines').models, function(line) {
+      var _line = {
+        id: line.id,
+        loaded: line.get('loaded')
+      };
+      _order.lines.push(_line);
+    });
+    checkUpdated.exec(
+      {
+        order: _order
+      },
+      function(data) {
+        if (data) {
+          if (data.exception) {
+            errorPopup(false);
+          } else if (data.error) {
+            errorPopup(false, data.type);
+          } else {
+            successCallback();
+          }
+        } else {
+          errorCallback();
+        }
+      },
+      function(data) {
+        errorPopup(true);
+      }
+    );
+  };
 })();
