# HG changeset patch
# User Guillermo Alvarez de Eulate <guillermo.alvarez@openbravo.com>
# Date 1490946038 -7200
#      Fri Mar 31 09:40:38 2017 +0200
# Node ID 66d29f10b16dde3c594a268b9a5f95ab044d4cf8
# Parent  199ccf0b30c47ff320bea29c428962ddf3cccaa7
Fixed issue 35663: When a quotation is loaded, a check is done to verify that not orders created for that quotation are already opened

diff -r 199ccf0b30c4 -r 66d29f10b16d src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jan 12 16:51:29 2017 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Mar 31 09:40:38 2017 +0200
@@ -4371,6 +4371,18 @@
 <!--97CB5B8566F44416986B7FB607640E13-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--97CB5B8566F44416986B7FB607640E13--></AD_MESSAGE>
 
+<!--9803EFEAD46040859C357515EAA21070--><AD_MESSAGE>
+<!--9803EFEAD46040859C357515EAA21070-->  <AD_MESSAGE_ID><![CDATA[9803EFEAD46040859C357515EAA21070]]></AD_MESSAGE_ID>
+<!--9803EFEAD46040859C357515EAA21070-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9803EFEAD46040859C357515EAA21070-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9803EFEAD46040859C357515EAA21070-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9803EFEAD46040859C357515EAA21070-->  <VALUE><![CDATA[OBPOS_OrderAssociatedToQuotationInProgress]]></VALUE>
+<!--9803EFEAD46040859C357515EAA21070-->  <MSGTEXT><![CDATA[Quotation %0 cannot be loaded because order %1 (created from quotation %2) is already opened. Please close or complete %3 or select an other quotation]]></MSGTEXT>
+<!--9803EFEAD46040859C357515EAA21070-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--9803EFEAD46040859C357515EAA21070-->  <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--9803EFEAD46040859C357515EAA21070-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--9803EFEAD46040859C357515EAA21070--></AD_MESSAGE>
+
 <!--981BFC3717364D71BCE5A77F1B8CCBA0--><AD_MESSAGE>
 <!--981BFC3717364D71BCE5A77F1B8CCBA0-->  <AD_MESSAGE_ID><![CDATA[981BFC3717364D71BCE5A77F1B8CCBA0]]></AD_MESSAGE_ID>
 <!--981BFC3717364D71BCE5A77F1B8CCBA0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 199ccf0b30c4 -r 66d29f10b16d web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js
--- a/web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js	Thu Jan 12 16:51:29 2017 +0100
+++ b/web/org.openbravo.retail.posterminal/js/components/modalpaidreceipts.js	Fri Mar 31 09:40:38 2017 +0200
@@ -388,17 +388,28 @@
       // Check in Current Session
       var orderTypeMsg, i;
       for (i = 0; i < me.model.get('orderList').length; i++) {
-        if (me.model.get('orderList').models[i].get('id') === model.get('id')) {
+        if (me.model.get('orderList').models[i].get('id') === model.get('id') || ((!(_.isNull(me.model.get('orderList').models[i].get('oldId')))) && me.model.get('orderList').models[i].get('oldId') === model.get('id'))) {
+          var errorMsg;
           orderTypeMsg = OB.I18N.getLabel('OBPOS_ticket');
+          errorMsg = (enyo.format(OB.I18N.getLabel('OBPOS_ticketAlreadyOpened'), orderTypeMsg, model.get('documentNo')));
           if (me.model.get('orderList').models[i].get('isLayaway')) {
             orderTypeMsg = OB.I18N.getLabel('OBPOS_LblLayaway');
+            errorMsg = (enyo.format(OB.I18N.getLabel('OBPOS_ticketAlreadyOpened'), orderTypeMsg, model.get('documentNo')));
           } else if (me.model.get('orderList').models[i].get('isQuotation')) {
             orderTypeMsg = OB.I18N.getLabel('OBPOS_Quotation');
+            errorMsg = (enyo.format(OB.I18N.getLabel('OBPOS_ticketAlreadyOpened'), orderTypeMsg, model.get('documentNo')));
+          } else if ((!(_.isNull(me.model.get('orderList').models[i].get('oldId')))) && me.model.get('orderList').models[i].get('oldId') === model.get('id')) {
+            //(!(_.isNull(me.model.get('orderList').models[i].get('oldId')) -> It is a sales order created from a quotation
+            //me.model.get('orderList').models[i].get('oldId') === model.get('id') -> The quotation that we are loading created an order which is not synchronized or closed
+            //Quotation %0 cannot be loaded because order %1 (created from quotation %2) is already opened. Please close or complete %3 or select an other quotation
+            var SoFromQtDocNo = me.model.get('orderList').models[i].get('documentNo');
+            var QtDocumentNo = model.get('documentNo');
+            errorMsg = OB.I18N.getLabel('OBPOS_OrderAssociatedToQuotationInProgress', [QtDocumentNo, SoFromQtDocNo, QtDocumentNo, SoFromQtDocNo]);
           }
           me.doShowPopup({
             popup: 'OB_UI_MessageDialog',
             args: {
-              message: (enyo.format(OB.I18N.getLabel('OBPOS_ticketAlreadyOpened'), orderTypeMsg, model.get('documentNo')))
+              message: errorMsg
             }
           });
           if (OB.MobileApp.model.receipt.get('documentNo') !== model.get('documentNo')) {
