# HG changeset patch
# User Miguel de Juana <miguel.dejuana@openbravo.com>
# Date 1568360073 -7200
#      Fri Sep 13 09:34:33 2019 +0200
# Node ID 1919148245f7d65b02f6b88afb46399f7eb32536
# Parent  b708bcf18bf135d420c537871255ba424b73c8c9
Fixed issue 0041811: Polling could be not launched due to asynchrony

- Check also messagesByModel because we could moved messages from noStarted to messagesByModel due to asynchrony

diff --git a/web/org.openbravo.mobile.core/source/model/ob-pollingrequesthandler.js b/web/org.openbravo.mobile.core/source/model/ob-pollingrequesthandler.js
--- a/web/org.openbravo.mobile.core/source/model/ob-pollingrequesthandler.js
+++ b/web/org.openbravo.mobile.core/source/model/ob-pollingrequesthandler.js
@@ -245,7 +245,18 @@
       });
     },
     hasNotStartedPollingRequests: function() {
-      return this.notStartedPollingRequest.length > 0;
+      return (
+        this.notStartedPollingRequest.length > 0 ||
+        _.filter(OB.MobileApp.model.get('dataSyncModels'), function(curModel) {
+          if (
+            curModel.pollingClassName &&
+            curModel.messagesByModel &&
+            curModel.messagesByModel.length > 0
+          ) {
+            return true;
+          }
+        }).length > 0
+      );
     }
   };
 })();
