# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1551965930 -19800
#      Thu Mar 07 19:08:50 2019 +0530
# Node ID c8e30af0c10fca02acdb30c900e53315ebe72051
# Parent  88a5c9b52b17a8178dcb80b29903828dc5f4c048
Related to issue 40326 : Receipts from other sessions should be deleted while doing cashup

* While doing cashup, Other Session receipts will not be added to OB.MobileApp.model.orderList.
  So receipt createdBy and session user is same, receipt should be removed from orderList and local db
  else receipt should be only removed from local db

diff -r 88a5c9b52b17 -r c8e30af0c10f web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js	Mon Mar 04 18:42:19 2019 -0500
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js	Thu Mar 07 19:08:50 2019 +0530
@@ -6101,7 +6101,7 @@
 
       function removeReceiptFromDatabase(receipt, callback) {
         var model, orderList = OB.MobileApp.model.orderList;
-        if (orderList) {
+        if (orderList && receipt && receipt.get('createdBy') === OB.MobileApp.model.get('orgUserId')) {
           model = _.find(orderList.models, function (model) {
             return model.get('id') === receipt.get('id');
           });
@@ -6153,7 +6153,7 @@
             model.set('json', JSON.stringify(model.serializeToJSON()));
             OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(model.get('documentnoSuffix'), model.get('quotationnoSuffix'), model.get('returnnoSuffix'), function () {
               model.save(function () {
-                if (orderList) {
+                if (orderList && model.get('createdBy') === OB.MobileApp.model.get('orgUserId')) {
                   var orderListModel = _.find(orderList.models, function (m) {
                     return m.get('id') === model.get('id');
                   });
