Attached Files | transactions_refactor_mobile_core.diff [^] (4,866 bytes) 2015-04-20 16:50 [Show Content] [Hide Content]diff --git a/web/org.openbravo.mobile.core/source/data/ob-dal.js b/web/org.openbravo.mobile.core/source/data/ob-dal.js
--- a/web/org.openbravo.mobile.core/source/data/ob-dal.js
+++ b/web/org.openbravo.mobile.core/source/data/ob-dal.js
@@ -85,14 +85,6 @@
};
}
- function handleTransactionError(transactionName, trxExists) {
- if (trxExists) {
- OB.error(OB.I18N.getLabel('OBMOBC_TransactionExistsError', [transactionName]));
- } else {
- OB.error(OB.I18N.getLabel('OBMOBC_TransactionNotExistsError', [transactionName]));
- }
- }
-
/*
* initialize the WebSQL dababase
*/
@@ -318,18 +310,8 @@
return null;
};
- OB.Dal.doInTransaction = function (trxName, callback) {
- OB.Dal.currentTransactions = OB.Dal.currentTransactions || {};
- if (OB.Dal.currentTransactions[trxName]) {
- handleTransactionError(trxName, true);
- } else {
- OB.Data.localDB.transaction(function (tx) {
- OB.Dal.currentTransactions[trxName] = tx;
- callback(function () {
- OB.Dal.currentTransactions[trxName] = null;
- });
- });
- }
+ OB.Dal.transaction = function(callback, errorCallback, successCallback) {
+ OB.Data.localDB.transaction(callback, errorCallback, successCallback);
};
OB.Dal.findUsingCache = function (cacheName, model, whereClause, success, error, args) {
@@ -351,12 +333,8 @@
};
- OB.Dal.findInTransaction = function (trxName, model, whereClause, success, error, args) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.find(model, whereClause, success, error, args, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.findInTransaction = function (tx, model, whereClause, success, error, args) {
+ OB.Dal.find(model, whereClause, success, error, args, tx);
};
OB.Dal.find = function (model, whereClause, success, error, args, currentTransaction) {
@@ -529,12 +507,8 @@
}
};
- OB.Dal.queryInTransaction = function (trxName, model, sql, params, success, error, args) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.query(model, sql, params, success, error, args, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.queryInTransaction = function (tx, model, sql, params, success, error, args) {
+ OB.Dal.query(model, sql, params, success, error, args, tx);
};
OB.Dal.query = function (model, sql, params, success, error, args, currentTransaction) {
@@ -576,12 +550,8 @@
}
};
- OB.Dal.saveInTransaction = function (trxName, model, success, error, forceInsert) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.save(model, success, error, forceInsert, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.saveInTransaction = function (tx, model, success, error, forceInsert) {
+ OB.Dal.save(model, success, error, forceInsert, tx);
};
OB.Dal.save = function (model, success, error, forceInsert, currentTransaction) {
@@ -777,12 +747,8 @@
}
};
- OB.Dal.removeInTransaction = function (trxName, model, success, error) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.remove(model, success, error, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.removeInTransaction = function (tx, model, success, error) {
+ OB.Dal.remove(model, success, error, tx);
};
@@ -846,12 +812,8 @@
}
};
- OB.Dal.removeAllInTransaction = function (trxName, model, criteria, success, error) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.removeAll(model, criteria, success, error, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.removeAllInTransaction = function (tx, model, criteria, success, error) {
+ OB.Dal.removeAll(model, criteria, success, error, tx);
};
OB.Dal.removeAll = function (model, criteria, success, error, currentTransaction) {
@@ -892,12 +854,8 @@
}
};
- OB.Dal.getInTransaction = function (trxName, model, id, success, error, empty) {
- if (OB.Dal.currentTransactions && OB.Dal.currentTransactions[trxName]) {
- OB.Dal.get(model, id, success, error, empty, OB.Dal.currentTransactions[trxName]);
- } else {
- handleTransactionError(trxName, false);
- }
+ OB.Dal.getInTransaction = function (tx, model, id, success, error, empty) {
+ OB.Dal.get(model, id, success, error, empty, tx);
};
OB.Dal.get = function (model, id, success, error, empty, currentTransaction) {
transactions_refactor_retail_posterminal.diff [^] (20,173 bytes) 2015-04-20 16:51 [Show Content] [Hide Content]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
@@ -94,8 +94,7 @@
}
var receipt = args.context.receipt,
auxReceipt = new OB.Model.Order(),
- currentDocNo = receipt.get('documentNo') || docno,
- trxName;
+ currentDocNo = receipt.get('documentNo') || docno;
OB.trace('Execution of pre order save hook OK.');
@@ -131,81 +130,75 @@
OB.trace('Calculationg cashup information.');
auxReceipt.clearWith(receipt);
- trxName = 'closeTicketTrx' + receipt.get('id');
- OB.Dal.doInTransaction(trxName, function (finalizationCallback) {
+ OB.Dal.transaction(function (tx) {
OB.UTIL.cashUpReport(auxReceipt, function () {
- OB.UTIL.calculateCurrentCash(null, trxName);
+ OB.UTIL.calculateCurrentCash(null, tx);
OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
OB.trace('Saving receipt.');
- OB.Dal.saveInTransaction(trxName, receipt, function () {
- var successCallback = function (model) {
- OB.trace('Sync process success.');
+ OB.Dal.saveInTransaction(tx, receipt);
+ }, tx);
+ }, tx);
+ }, null, function () {
+ // success transaction...
+ OB.trace('Executing of post order save hook.');
- //In case the processed document is a quotation, we remove its id so it can be reactivated
- if (model && !_.isNull(model)) {
- if (model.get('order') && model.get('order').get('isQuotation')) {
- model.get('order').set('oldId', model.get('order').get('id'));
- model.get('order').set('id', null);
- model.get('order').set('isbeingprocessed', 'N');
- 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]));
- }
- }
- }
+ var successCallback = function (model) {
+ OB.trace('Sync process success.');
- OB.trace('Order successfully removed.');
- };
-
- finalizationCallback();
-
- OB.trace('Executing of post order save hook.');
-
- if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
- //If there are elements in the hook, we are forced to execute the callback only after the synchronization process
- //has been executed, to prevent race conditions with the callback processes (printing and deleting the receipt)
- OB.trace('Execution Sync process.');
-
- OB.MobileApp.model.runSyncProcess(function () {
- OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
- receipt: auxReceipt
- }, function (args) {
- successCallback();
- if (eventParams && eventParams.callback) {
- eventParams.callback();
- }
- });
- }, function () {
- OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
- receipt: auxReceipt
- }, function (args) {
- if (eventParams && eventParams.callback) {
- eventParams.callback();
- }
- });
- });
+ //In case the processed document is a quotation, we remove its id so it can be reactivated
+ if (model && !_.isNull(model)) {
+ if (model.get('order') && model.get('order').get('isQuotation')) {
+ model.get('order').set('oldId', model.get('order').get('id'));
+ model.get('order').set('id', null);
+ model.get('order').set('isbeingprocessed', 'N');
+ OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationSaved', [currentDocNo]));
} else {
-
- OB.trace('Execution Sync process.');
-
- //If there are no elements in the hook, we can execute the callback asynchronusly with the synchronization process
- OB.MobileApp.model.runSyncProcess(function () {
- successCallback(model);
- });
- if (eventParams && eventParams.callback) {
- eventParams.callback();
+ if (isLayaway) {
+ OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_MsgLayawaySaved', [currentDocNo]));
+ } else {
+ OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_MsgReceiptSaved', [currentDocNo]));
}
}
+ }
- }, function () {
- //We do nothing: we don't need to alert the user, as the order is still present in the database, so it will be resent as soon as the user logs in again
- finalizationCallback();
+ OB.trace('Order successfully removed.');
+ };
+
+ if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
+ //If there are elements in the hook, we are forced to execute the callback only after the synchronization process
+ //has been executed, to prevent race conditions with the callback processes (printing and deleting the receipt)
+ OB.trace('Execution Sync process.');
+
+ OB.MobileApp.model.runSyncProcess(function () {
+ OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
+ receipt: auxReceipt
+ }, function (args) {
+ successCallback();
+ if (eventParams && eventParams.callback) {
+ eventParams.callback();
+ }
});
- }, trxName);
- }, trxName);
+ }, function () {
+ OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
+ receipt: auxReceipt
+ }, function (args) {
+ if (eventParams && eventParams.callback) {
+ eventParams.callback();
+ }
+ });
+ });
+ } else {
+
+ OB.trace('Execution Sync process.');
+
+ //If there are no elements in the hook, we can execute the callback asynchronusly with the synchronization process
+ OB.MobileApp.model.runSyncProcess(function () {
+ successCallback(model);
+ });
+ if (eventParams && eventParams.callback) {
+ eventParams.callback();
+ }
+ }
});
});
}, this);
diff --git a/web/org.openbravo.retail.posterminal/js/login/model/login-model.js b/web/org.openbravo.retail.posterminal/js/login/model/login-model.js
--- a/web/org.openbravo.retail.posterminal/js/login/model/login-model.js
+++ b/web/org.openbravo.retail.posterminal/js/login/model/login-model.js
@@ -707,7 +707,7 @@
* Save the new values if are higher than the last known values
* - the minimum sequence number can only grow
*/
- saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, callback, transactionName) {
+ saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
var me = this,
processDocumentSequenceList;
if (me.restartingDocNo === true) {
@@ -756,52 +756,33 @@
// update the database
docSeq.set('documentSequence', me.documentnoThreshold);
docSeq.set('quotationDocumentSequence', me.quotationnoThreshold);
- if (transactionName) {
- OB.Dal.saveInTransaction(transactionName, docSeq, function () {
- if (callback) {
- callback();
- }
- me.restartingDocNo = false;
- }, function () {
- me.restartingDocNo = false;
- });
- } else {
- OB.Dal.save(docSeq, function () {
- if (callback) {
- callback();
- }
- me.restartingDocNo = false;
- }, function () {
- me.restartingDocNo = false;
- });
- }
+ OB.Dal.saveInTransaction(tx, docSeq, function () {
+ if (callback) {
+ callback();
+ }
+ me.restartingDocNo = false;
+ }, function () {
+ me.restartingDocNo = false;
+ });
};
// verify the database values
- if (transactionName) {
- OB.Dal.findInTransaction(transactionName, OB.Model.DocumentSequence, {
- 'posSearchKey': this.get('terminal').searchKey
- }, processDocumentSequenceList, function () {
- me.restartingDocNo = false;
- });
- } else {
- OB.Dal.find(OB.Model.DocumentSequence, {
- 'posSearchKey': this.get('terminal').searchKey
- }, processDocumentSequenceList, function () {
- me.restartingDocNo = false;
- });
- }
+ OB.Dal.findInTransaction(tx, OB.Model.DocumentSequence, {
+ 'posSearchKey': this.get('terminal').searchKey
+ }, processDocumentSequenceList, function () {
+ me.restartingDocNo = false;
+ });
},
/**
* Updates the document sequence. This method should only be called when an order has been sent to the server
* If the order is a quotation, only update the quotationno
*/
- updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, callback, transactionName) {
+ updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
if (quotationnoSuffix >= 0) {
documentnoSuffix = -1;
}
- this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, callback, transactionName);
+ this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, callback, tx);
},
// get the first document number available
diff --git a/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js b/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js
--- a/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js
+++ b/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js
@@ -13,45 +13,27 @@
OB.UTIL = window.OB.UTIL || {};
- function findAndSave(cashuptaxes, i, finishCallback, trxName) {
-
- var saveIfInTransaction, findIfInTransaction;
-
- saveIfInTransaction = function (model, success, error, forceInsert) {
- if (trxName) {
- OB.Dal.saveInTransaction(trxName, model, success, error, forceInsert);
- } else {
- OB.Dal.save(model, success, error, forceInsert);
- }
- };
-
- findIfInTransaction = function (model, whereClause, success, error, args) {
- if (trxName) {
- OB.Dal.findInTransaction(trxName, model, whereClause, success, error, args);
- } else {
- OB.Dal.find(model, whereClause, success, error, args);
- }
- };
+ function findAndSave(cashuptaxes, i, finishCallback, tx) {
if (i < cashuptaxes.length) {
- findIfInTransaction(OB.Model.TaxCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.TaxCashUp, {
'cashup_id': cashuptaxes[i].cashupID,
'name': cashuptaxes[i].taxName,
'orderType': cashuptaxes[i].taxOrderType
}, function (tax) {
if (tax.length === 0) {
- saveIfInTransaction(new OB.Model.TaxCashUp({
+ OB.Dal.saveInTransaction(tx, new OB.Model.TaxCashUp({
name: cashuptaxes[i].taxName,
amount: cashuptaxes[i].taxAmount,
orderType: cashuptaxes[i].taxOrderType,
cashup_id: cashuptaxes[i].cashupID
}), function () {
- findAndSave(cashuptaxes, i + 1, finishCallback, trxName);
+ findAndSave(cashuptaxes, i + 1, finishCallback, tx);
}, null);
} else {
tax.at(0).set('amount', OB.DEC.add(tax.at(0).get('amount'), cashuptaxes[i].taxAmount));
- saveIfInTransaction(tax.at(0), function () {
- findAndSave(cashuptaxes, i + 1, finishCallback, trxName);
+ OB.Dal.saveInTransaction(tx, tax.at(0), function () {
+ findAndSave(cashuptaxes, i + 1, finishCallback, tx);
}, null);
}
});
@@ -62,24 +44,8 @@
}
}
- function updateCashUpInfo(cashUp, receipt, j, callback, trxName) {
- var cashuptaxes, order, orderType, gross, i, taxOrderType, taxAmount, auxPay, saveIfInTransaction, findIfInTransaction;
-
- saveIfInTransaction = function (model, success, error, forceInsert) {
- if (trxName) {
- OB.Dal.saveInTransaction(trxName, model, success, error, forceInsert);
- } else {
- OB.Dal.save(model, success, error, forceInsert);
- }
- };
-
- findIfInTransaction = function (model, whereClause, success, error, args) {
- if (trxName) {
- OB.Dal.findInTransaction(trxName, model, whereClause, success, error, args);
- } else {
- OB.Dal.find(model, whereClause, success, error, args);
- }
- };
+ function updateCashUpInfo(cashUp, receipt, j, callback, tx) {
+ var cashuptaxes, order, orderType, gross, i, taxOrderType, taxAmount, auxPay;
if (j < receipt.length) {
order = receipt[j];
@@ -113,7 +79,7 @@
}
});
cashUp.at(0).set('totalRetailTransactions', OB.DEC.sub(cashUp.at(0).get('grossSales'), cashUp.at(0).get('grossReturns')));
- saveIfInTransaction(cashUp.at(0), null, null);
+ OB.Dal.saveInTransaction(tx, cashUp.at(0), null, null);
// group and sum the taxes
cashuptaxes = [];
@@ -152,7 +118,7 @@
});
});
- findIfInTransaction(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id')
}, function (payMthds) { //OB.Dal.find success
_.each(order.get('payments').models, function (payment) {
@@ -169,13 +135,13 @@
} else {
auxPay.set('totalSales', OB.DEC.add(auxPay.get('totalSales'), payment.get('amount')));
}
- saveIfInTransaction(auxPay, null, null);
+ OB.Dal.saveInTransaction(tx, auxPay, null, null);
}, this);
findAndSave(cashuptaxes, 0, function () {
OB.UTIL.composeCashupInfo(cashUp, null, function () {
- updateCashUpInfo(cashUp, receipt, j + 1, callback, trxName);
- }, trxName);
- }, trxName);
+ updateCashUpInfo(cashUp, receipt, j + 1, callback, tx);
+ }, tx);
+ }, tx);
});
}
} else if (typeof callback === 'function') {
@@ -183,25 +149,17 @@
}
}
- OB.UTIL.cashUpReport = function (receipt, callback, trxName) {
+ OB.UTIL.cashUpReport = function (receipt, callback, tx) {
var auxPay, orderType, taxOrderType, taxAmount, gross;
if (!Array.isArray(receipt)) {
receipt = [receipt];
}
- if (trxName) {
- OB.Dal.findInTransaction(trxName, OB.Model.CashUp, {
- 'isprocessed': 'N'
- }, function (cashUp) {
- updateCashUpInfo(cashUp, receipt, 0, callback, trxName);
- });
- } else {
- OB.Dal.find(OB.Model.CashUp, {
- 'isprocessed': 'N'
- }, function (cashUp) {
- updateCashUpInfo(cashUp, receipt, 0, callback);
- });
- }
+ OB.Dal.findInTransaction(tx, OB.Model.CashUp, {
+ 'isprocessed': 'N'
+ }, function (cashUp) {
+ updateCashUpInfo(cashUp, receipt, 0, callback, tx);
+ });
};
OB.UTIL.deleteCashUps = function (cashUpModels) {
@@ -513,22 +471,13 @@
});
}
};
- OB.UTIL.calculateCurrentCash = function (callback, trxName) {
- var me = this,
- findIfInTransaction;
+ OB.UTIL.calculateCurrentCash = function (callback, tx) {
+ var me = this;
- findIfInTransaction = function (model, whereClause, success, error, args) {
- if (trxName) {
- OB.Dal.findInTransaction(trxName, model, whereClause, success, error, args);
- } else {
- OB.Dal.find(model, whereClause, success, error, args);
- }
- };
-
- findIfInTransaction(OB.Model.CashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.CashUp, {
'isprocessed': 'N'
}, function (cashUp) {
- findIfInTransaction(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id')
}, function (payMthds) { //OB.Dal.find success
var payMthdsCash;
@@ -607,25 +556,12 @@
}, this);
};
- OB.UTIL.saveComposeInfo = function (me, callback, objToSend, cashUp, trxName) {
- var saveIfInTransaction;
-
- saveIfInTransaction = function (model, success, error, forceInsert) {
- if (trxName) {
- OB.Dal.saveInTransaction(trxName, model, success, error, forceInsert);
- } else {
- OB.Dal.save(model, success, error, forceInsert);
- }
- };
+ OB.UTIL.saveComposeInfo = function (me, callback, objToSend, cashUp, tx) {
cashUp.at(0).set('userId', OB.MobileApp.model.get('context').user.id);
objToSend.set('userId', OB.MobileApp.model.get('context').user.id);
cashUp.at(0).set('objToSend', JSON.stringify(objToSend));
- if (callback) {
- saveIfInTransaction(cashUp.at(0), callback(me), null);
- } else {
- saveIfInTransaction(cashUp.at(0), null, null);
- }
+ OB.Dal.saveInTransaction(tx, cashUp.at(0), callback ? callback(me) : null, null);
};
OB.UTIL.getTaxCashUp = function (taxcashups, objToSend, cashUp) {
_.each(taxcashups.models, function (currentTax) {
@@ -646,8 +582,8 @@
}, this);
};
- OB.UTIL.composeCashupInfo = function (cashUp, me, callback, trxName) {
- var findIfInTransaction, objToSend = new Backbone.Model({
+ OB.UTIL.composeCashupInfo = function (cashUp, me, callback, tx) {
+ var objToSend = new Backbone.Model({
posterminal: OB.MobileApp.model.get('terminal').id,
id: cashUp.at(0).get('id'),
isprocessed: cashUp.at(0).get('isprocessed'),
@@ -664,28 +600,20 @@
creationDate: (new Date(cashUp.at(0).get('creationDate'))).toISOString()
});
- findIfInTransaction = function (model, whereClause, success, error, args) {
- if (trxName) {
- OB.Dal.findInTransaction(trxName, model, whereClause, success, error, args);
- } else {
- OB.Dal.find(model, whereClause, success, error, args);
- }
- };
-
//process the payment method cash ups
- findIfInTransaction(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id'),
'_orderByClause': 'name asc'
}, function (payMthds) {
OB.UTIL.getPaymethodCashUp(payMthds, objToSend, cashUp);
//process the taxs cash ups
- findIfInTransaction(OB.Model.TaxCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.TaxCashUp, {
'cashup_id': cashUp.at(0).get('id'),
'_orderByClause': 'name asc'
}, function (taxcashups) {
OB.UTIL.getTaxCashUp(taxcashups, objToSend, cashUp);
- OB.UTIL.saveComposeInfo(me, callback, objToSend, cashUp, trxName);
+ OB.UTIL.saveComposeInfo(me, callback, objToSend, cashUp, tx);
});
});
};
Q2.1_posterminal_29302.patch [^] (16,991 bytes) 2015-06-16 09:23 [Show Content] [Hide Content]# HG changeset patch
# User Aaron Calero <aaron.calero@openbravo.com>
# Date 1428914305 -7200
# Mon Apr 13 10:38:25 2015 +0200
# Node ID 741213b28c3c1b0627af1b15b86eddc3ea8b7c87
# Parent bf8460ecff17d628aeb3d33bec6543e9d52e08dd
Fixed issue 29302: In paymentmethodcashup table one ticket can be added 2 times
Reapplied changes to the standard order flow to close tickets in a transactional way.
diff -r bf8460ecff17 -r 741213b28c3c web/org.openbravo.retail.posterminal/js/data/dataordersave.js
--- a/web/org.openbravo.retail.posterminal/js/data/dataordersave.js Mon May 25 09:55:52 2015 +0000
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordersave.js Mon Apr 13 10:38:25 2015 +0200
@@ -130,78 +130,75 @@
OB.trace('Calculationg cashup information.');
auxReceipt.clearWith(receipt);
- OB.UTIL.cashUpReport(auxReceipt, function () {
- OB.UTIL.calculateCurrentCash();
+ OB.Dal.transaction(function (tx) {
+ OB.UTIL.cashUpReport(auxReceipt, function () {
+ OB.UTIL.calculateCurrentCash(null, tx);
+ OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
+ OB.trace('Saving receipt.');
+ OB.Dal.saveInTransaction(tx, receipt);
+ }, tx);
+ }, tx);
+ }, null, function () {
+ // success transaction...
+ OB.trace('Executing of post order save hook.');
- OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
- OB.trace('Saving receipt.');
+ var successCallback = function (model) {
+ OB.trace('Sync process success.');
- OB.Dal.save(receipt, function () {
+ //In case the processed document is a quotation, we remove its id so it can be reactivated
+ if (model && !_.isNull(model)) {
+ if (model.get('order') && model.get('order').get('isQuotation')) {
+ model.get('order').set('oldId', model.get('order').get('id'));
+ model.get('order').set('id', null);
+ model.get('order').set('isbeingprocessed', 'N');
+ 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]));
+ }
+ }
+ }
- var successCallback = function (model) {
- OB.trace('Sync process success.');
+ OB.trace('Order successfully removed.');
+ };
- //In case the processed document is a quotation, we remove its id so it can be reactivated
- if (model && !_.isNull(model)) {
- if (model.get('order') && model.get('order').get('isQuotation')) {
- model.get('order').set('oldId', model.get('order').get('id'));
- model.get('order').set('id', null);
- model.get('order').set('isbeingprocessed', 'N');
- 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]));
- }
- }
- }
+ if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
+ //If there are elements in the hook, we are forced to execute the callback only after the synchronization process
+ //has been executed, to prevent race conditions with the callback processes (printing and deleting the receipt)
+ OB.trace('Execution Sync process.');
- OB.trace('Order successfully removed.');
- };
-
- OB.trace('Executing of post order save hook.');
-
- if (OB.UTIL.HookManager.get('OBPOS_PostSyncReceipt')) {
- //If there are elements in the hook, we are forced to execute the callback only after the synchronization process
- //has been executed, to prevent race conditions with the callback processes (printing and deleting the receipt)
- OB.trace('Execution Sync process.');
-
- OB.MobileApp.model.runSyncProcess(function () {
- OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
- receipt: auxReceipt
- }, function (args) {
- successCallback();
- if (eventParams && eventParams.callback) {
- eventParams.callback();
- }
- });
- }, function () {
- OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
- receipt: auxReceipt
- }, function (args) {
- if (eventParams && eventParams.callback) {
- eventParams.callback();
- }
- });
- });
- } else {
-
- OB.trace('Execution Sync process.');
-
- //If there are no elements in the hook, we can execute the callback asynchronusly with the synchronization process
- OB.MobileApp.model.runSyncProcess(function () {
- successCallback(model);
- });
+ OB.MobileApp.model.runSyncProcess(function () {
+ OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
+ receipt: auxReceipt
+ }, function (args) {
+ successCallback();
if (eventParams && eventParams.callback) {
eventParams.callback();
}
- }
+ });
+ }, function () {
+ OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
+ receipt: auxReceipt
+ }, function (args) {
+ if (eventParams && eventParams.callback) {
+ eventParams.callback();
+ }
+ });
+ });
+ } else {
- }, function () {
- //We do nothing: we don't need to alert the user, as the order is still present in the database, so it will be resent as soon as the user logs in again
+ OB.trace('Execution Sync process.');
+
+ //If there are no elements in the hook, we can execute the callback asynchronusly with the synchronization process
+ OB.MobileApp.model.runSyncProcess(function () {
+ successCallback(model);
});
- });
+ if (eventParams && eventParams.callback) {
+ eventParams.callback();
+ }
+ }
});
});
}, this);
diff -r bf8460ecff17 -r 741213b28c3c web/org.openbravo.retail.posterminal/js/login/model/login-model.js
--- a/web/org.openbravo.retail.posterminal/js/login/model/login-model.js Mon May 25 09:55:52 2015 +0000
+++ b/web/org.openbravo.retail.posterminal/js/login/model/login-model.js Mon Apr 13 10:38:25 2015 +0200
@@ -707,8 +707,9 @@
* Save the new values if are higher than the last known values
* - the minimum sequence number can only grow
*/
- saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, callback) {
- var me = this;
+ saveDocumentSequence: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
+ var me = this,
+ processDocumentSequenceList;
if (me.restartingDocNo === true) {
return;
}
@@ -725,10 +726,7 @@
this.quotationnoThreshold = quotationnoSuffix;
}
- // verify the database values
- OB.Dal.find(OB.Model.DocumentSequence, {
- 'posSearchKey': this.get('terminal').searchKey
- }, function (documentSequenceList) {
+ processDocumentSequenceList = function (documentSequenceList) {
var docSeq;
if (documentSequenceList && documentSequenceList.length > 0) {
@@ -758,7 +756,7 @@
// update the database
docSeq.set('documentSequence', me.documentnoThreshold);
docSeq.set('quotationDocumentSequence', me.quotationnoThreshold);
- OB.Dal.save(docSeq, function () {
+ OB.Dal.saveInTransaction(tx, docSeq, function () {
if (callback) {
callback();
}
@@ -766,8 +764,12 @@
}, function () {
me.restartingDocNo = false;
});
+ };
- }, function () {
+ // verify the database values
+ OB.Dal.findInTransaction(tx, OB.Model.DocumentSequence, {
+ 'posSearchKey': this.get('terminal').searchKey
+ }, processDocumentSequenceList, function () {
me.restartingDocNo = false;
});
},
@@ -776,11 +778,11 @@
* Updates the document sequence. This method should only be called when an order has been sent to the server
* If the order is a quotation, only update the quotationno
*/
- updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, callback) {
+ updateDocumentSequenceWhenOrderSaved: function (documentnoSuffix, quotationnoSuffix, callback, tx) {
if (quotationnoSuffix >= 0) {
documentnoSuffix = -1;
}
- this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, callback);
+ this.saveDocumentSequence(documentnoSuffix, quotationnoSuffix, callback, tx);
},
// get the first document number available
diff -r bf8460ecff17 -r 741213b28c3c web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js
--- a/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js Mon May 25 09:55:52 2015 +0000
+++ b/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js Mon Apr 13 10:38:25 2015 +0200
@@ -1,6 +1,6 @@
/*
************************************************************************************
- * Copyright (C) 2012 Openbravo S.L.U.
+ * Copyright (C) 2012-2015 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.
@@ -13,27 +13,27 @@
OB.UTIL = window.OB.UTIL || {};
- function findAndSave(cashuptaxes, i, finishCallback) {
+ function findAndSave(cashuptaxes, i, finishCallback, tx) {
if (i < cashuptaxes.length) {
- OB.Dal.find(OB.Model.TaxCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.TaxCashUp, {
'cashup_id': cashuptaxes[i].cashupID,
'name': cashuptaxes[i].taxName,
'orderType': cashuptaxes[i].taxOrderType
}, function (tax) {
if (tax.length === 0) {
- OB.Dal.save(new OB.Model.TaxCashUp({
+ OB.Dal.saveInTransaction(tx, new OB.Model.TaxCashUp({
name: cashuptaxes[i].taxName,
amount: cashuptaxes[i].taxAmount,
orderType: cashuptaxes[i].taxOrderType,
cashup_id: cashuptaxes[i].cashupID
}), function () {
- findAndSave(cashuptaxes, i + 1, finishCallback);
+ findAndSave(cashuptaxes, i + 1, finishCallback, tx);
}, null);
} else {
tax.at(0).set('amount', OB.DEC.add(tax.at(0).get('amount'), cashuptaxes[i].taxAmount));
- OB.Dal.save(tax.at(0), function () {
- findAndSave(cashuptaxes, i + 1, finishCallback);
+ OB.Dal.saveInTransaction(tx, tax.at(0), function () {
+ findAndSave(cashuptaxes, i + 1, finishCallback, tx);
}, null);
}
});
@@ -44,8 +44,9 @@
}
}
- function updateCashUpInfo(cashUp, receipt, j, callback) {
+ function updateCashUpInfo(cashUp, receipt, j, callback, tx) {
var cashuptaxes, order, orderType, gross, i, taxOrderType, taxAmount, auxPay;
+
if (j < receipt.length) {
order = receipt[j];
orderType = order.get('orderType');
@@ -78,7 +79,7 @@
}
});
cashUp.at(0).set('totalRetailTransactions', OB.DEC.sub(cashUp.at(0).get('grossSales'), cashUp.at(0).get('grossReturns')));
- OB.Dal.save(cashUp.at(0), null, null);
+ OB.Dal.saveInTransaction(tx, cashUp.at(0), null, null);
// group and sum the taxes
cashuptaxes = [];
@@ -117,7 +118,7 @@
});
});
- OB.Dal.find(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id')
}, function (payMthds) { //OB.Dal.find success
_.each(order.get('payments').models, function (payment) {
@@ -134,12 +135,13 @@
} else {
auxPay.set('totalSales', OB.DEC.add(auxPay.get('totalSales'), payment.get('amount')));
}
- OB.Dal.save(auxPay, null, null);
+ OB.Dal.saveInTransaction(tx, auxPay, null, null);
}, this);
findAndSave(cashuptaxes, 0, function () {
- OB.UTIL.composeCashupInfo(cashUp, null, null);
- updateCashUpInfo(cashUp, receipt, j + 1, callback);
- });
+ OB.UTIL.composeCashupInfo(cashUp, null, function () {
+ updateCashUpInfo(cashUp, receipt, j + 1, callback, tx);
+ }, tx);
+ }, tx);
});
}
} else if (typeof callback === 'function') {
@@ -147,15 +149,16 @@
}
}
- OB.UTIL.cashUpReport = function (receipt, callback) {
+ OB.UTIL.cashUpReport = function (receipt, callback, tx) {
var auxPay, orderType, taxOrderType, taxAmount, gross;
if (!Array.isArray(receipt)) {
receipt = [receipt];
}
- OB.Dal.find(OB.Model.CashUp, {
+
+ OB.Dal.findInTransaction(tx, OB.Model.CashUp, {
'isprocessed': 'N'
}, function (cashUp) {
- updateCashUpInfo(cashUp, receipt, 0, callback);
+ updateCashUpInfo(cashUp, receipt, 0, callback, tx);
});
};
@@ -467,12 +470,13 @@
});
}
};
- OB.UTIL.calculateCurrentCash = function (callback) {
+ OB.UTIL.calculateCurrentCash = function (callback, tx) {
var me = this;
- OB.Dal.find(OB.Model.CashUp, {
+
+ OB.Dal.findInTransaction(tx, OB.Model.CashUp, {
'isprocessed': 'N'
}, function (cashUp) {
- OB.Dal.find(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id')
}, function (payMthds) { //OB.Dal.find success
var payMthdsCash;
@@ -551,15 +555,12 @@
}, this);
};
- OB.UTIL.saveComposeInfo = function (me, callback, objToSend, cashUp) {
+ OB.UTIL.saveComposeInfo = function (me, callback, objToSend, cashUp, tx) {
+
cashUp.at(0).set('userId', OB.MobileApp.model.get('context').user.id);
objToSend.set('userId', OB.MobileApp.model.get('context').user.id);
cashUp.at(0).set('objToSend', JSON.stringify(objToSend));
- if (callback) {
- OB.Dal.save(cashUp.at(0), callback(me), null);
- } else {
- OB.Dal.save(cashUp.at(0), null, null);
- }
+ OB.Dal.saveInTransaction(tx, cashUp.at(0), callback ? callback(me) : null, null);
};
OB.UTIL.getTaxCashUp = function (taxcashups, objToSend, cashUp) {
_.each(taxcashups.models, function (currentTax) {
@@ -580,7 +581,7 @@
}, this);
};
- OB.UTIL.composeCashupInfo = function (cashUp, me, callback) {
+ OB.UTIL.composeCashupInfo = function (cashUp, me, callback, tx) {
var objToSend = new Backbone.Model({
posterminal: OB.MobileApp.model.get('terminal').id,
id: cashUp.at(0).get('id'),
@@ -599,19 +600,19 @@
});
//process the payment method cash ups
- OB.Dal.find(OB.Model.PaymentMethodCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.PaymentMethodCashUp, {
'cashup_id': cashUp.at(0).get('id'),
'_orderByClause': 'name asc'
}, function (payMthds) {
OB.UTIL.getPaymethodCashUp(payMthds, objToSend, cashUp);
//process the taxs cash ups
- OB.Dal.find(OB.Model.TaxCashUp, {
+ OB.Dal.findInTransaction(tx, OB.Model.TaxCashUp, {
'cashup_id': cashUp.at(0).get('id'),
'_orderByClause': 'name asc'
}, function (taxcashups) {
OB.UTIL.getTaxCashUp(taxcashups, objToSend, cashUp);
- OB.UTIL.saveComposeInfo(me, callback, objToSend, cashUp);
+ OB.UTIL.saveComposeInfo(me, callback, objToSend, cashUp, tx);
});
});
};
|