|
@@ -1,19 +1,22 @@
|
|
|
angular.module('odoo')
|
|
|
|
|
|
-.factory('customersRemoteFactory', function (
|
|
|
- customersStorageFactory,
|
|
|
- odooFactory,
|
|
|
- configFactory,
|
|
|
- sqlFactory,
|
|
|
- asyncLoopFactory
|
|
|
-) {
|
|
|
-
|
|
|
- // Pull server customers data
|
|
|
- var pull = function (id, success, error) {
|
|
|
- configFactory(function (configuration) {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ .factory('customersRemoteFactory', function (
|
|
|
+ customersStorageFactory,
|
|
|
+ odooFactory,
|
|
|
+ sqlFactory,
|
|
|
+ asyncLoopFactory
|
|
|
+ ) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var pull = function (id, success, error) {
|
|
|
if (id) {
|
|
|
|
|
|
- odooFactory.read('res.partner', [['id', '=', id]], configuration, function (response) {
|
|
|
+ odooFactory.read('res.partner', [['id', '=', id]], function (response) {
|
|
|
success(response);
|
|
|
}, function (odooErr) {
|
|
|
error(odooErr);
|
|
@@ -21,27 +24,25 @@ angular.module('odoo')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- odooFactory.read('res.partner', [['customer', '=', true]], configuration, function (response) {
|
|
|
+ odooFactory.read('res.partner', [['customer', '=', true]], function (response) {
|
|
|
success(response);
|
|
|
}, function (odooErr) {
|
|
|
error(odooErr)
|
|
|
});
|
|
|
|
|
|
}
|
|
|
- }, function (configErr) {
|
|
|
- error(configErr);
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // Push customers data to server
|
|
|
- var push = function (id, data, success, error) {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var push = function (id, data, success, error) {
|
|
|
|
|
|
- // Avoid odoo server warning message
|
|
|
- delete data.id;
|
|
|
- delete data.remote_id;
|
|
|
- delete data.modified;
|
|
|
+ // Avoid odoo server warning message
|
|
|
+ delete data.id;
|
|
|
+ delete data.remote_id;
|
|
|
+ delete data.modified;
|
|
|
|
|
|
- configFactory(function (configuration) {
|
|
|
if (id) {
|
|
|
|
|
|
pull(id, function (response) {
|
|
@@ -55,7 +56,7 @@ angular.module('odoo')
|
|
|
|
|
|
if (localDate > remoteDate) {
|
|
|
|
|
|
- odooFactory.write('res.partner', id, data, configuration, function (response) {
|
|
|
+ odooFactory.write('res.partner', id, data, function (response) {
|
|
|
success(response);
|
|
|
}, function (odooErr) {
|
|
|
error(odooErr);
|
|
@@ -77,149 +78,158 @@ angular.module('odoo')
|
|
|
|
|
|
delete data.modifiedDate;
|
|
|
|
|
|
- odooFactory.create('res.partner', data, configuration, function (response) {
|
|
|
+ odooFactory.create('res.partner', data, function (response) {
|
|
|
success(response);
|
|
|
}, function (odooErr) {
|
|
|
error(odooErr);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
- }, function (configFactoryErr) {
|
|
|
- error(configFactoryErr);
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // Destroy server customer data
|
|
|
- var destroy = function(id, success, error) {
|
|
|
- configFactory(function (configuration) {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var destroy = function (id, success, error) {
|
|
|
|
|
|
- odooFactory.unlink('res.partner', id, configuration, function (response) {
|
|
|
+ odooFactory.unlink('res.partner', id, function (response) {
|
|
|
success(response);
|
|
|
}, function (odooInteroperabilityFactoryErr) {
|
|
|
error(odooInteroperabilityFactoryErr);
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var get = function (constraint, success, error) {
|
|
|
+ sqlFactory.selectByConstraint('partner', constraint, function (customers) {
|
|
|
+ success(customers);
|
|
|
+ }, function (err) {
|
|
|
+ error(err);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- }, function (configFactoryErr) {
|
|
|
- error(configFactoryErr);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Get local customer data
|
|
|
- var get = function (constraint, success, error) {
|
|
|
- sqlFactory.selectByConstraint('partner', constraint, function (customers) {
|
|
|
- success(customers);
|
|
|
- }, function (err) {
|
|
|
- error(err);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // Send all new data from local to remote server
|
|
|
- var syncNewData = function (success, error) {
|
|
|
- get('remote_id = 0 AND customer = 1', function (newCustomers) {
|
|
|
- asyncLoopFactory(newCustomers.length, function (loop) {
|
|
|
- var data = newCustomers.item(loop.iteration());
|
|
|
-
|
|
|
- push(null, data, function (response) {
|
|
|
- loop.next();
|
|
|
- }, function (pushErr) {
|
|
|
- loop.break();
|
|
|
- });
|
|
|
|
|
|
- // End loop
|
|
|
- }, function () {
|
|
|
- success(newCustomers);
|
|
|
- });
|
|
|
- }, function (getErr) {
|
|
|
- error(getErr);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Update all data from server
|
|
|
- var syncUpdatedData = function (success, error) {
|
|
|
- get('remote_id != 0 AND customer = 1 AND modified = 1', function (updatedCustomers) {
|
|
|
- asyncLoopFactory(updatedCustomers.length, function (loop) {
|
|
|
- var data = updatedCustomers.item(loop.iteration());
|
|
|
-
|
|
|
- push(data.remote_id, data, function (response) {
|
|
|
- loop.next();
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var syncNewData = function (success, error) {
|
|
|
+ get('remote_id = 0 AND customer = 1', function (newCustomers) {
|
|
|
+ asyncLoopFactory(newCustomers.length, function (loop) {
|
|
|
+ var data = newCustomers.item(loop.iteration());
|
|
|
+
|
|
|
+ push(null, data, function (response) {
|
|
|
+ loop.next();
|
|
|
+ }, function (pushErr) {
|
|
|
+ loop.break();
|
|
|
+ });
|
|
|
+
|
|
|
+ // end loop
|
|
|
}, function () {
|
|
|
- loop.next();
|
|
|
+ success(newCustomers);
|
|
|
});
|
|
|
-
|
|
|
- // End loop
|
|
|
- }, function () {
|
|
|
- success(updatedCustomers);
|
|
|
+ }, function (getErr) {
|
|
|
+ error(getErr);
|
|
|
});
|
|
|
- }, function (getErr) {
|
|
|
- error(getErr);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Delete all data
|
|
|
- var syncDeletedData = function (success, error) {
|
|
|
- get('remote_id != 0 AND customer = 1 AND modified = 2', function (deletedCustomers) {
|
|
|
- asyncLoopFactory(deletedCustomers.length, function (loop) {
|
|
|
- var id = deletedCustomers.item(loop.iteration()).remote_id;
|
|
|
-
|
|
|
- destroy(id, function (response) {
|
|
|
- loop.next();
|
|
|
- }, function (destroyErr) {
|
|
|
- loop.next();
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- // End loop
|
|
|
- }, function () {
|
|
|
- success(deletedCustomers);
|
|
|
- });
|
|
|
- }, function(getErr) {
|
|
|
- error(getErr);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Download all sync data from server
|
|
|
- var downloadSyncData = function (success, error) {
|
|
|
- pull(null, function (customers) {
|
|
|
- console.log(customers);
|
|
|
- customersStorageFactory.removeAll(function () {
|
|
|
- asyncLoopFactory(customers.length, function (loop) {
|
|
|
- var data = customers[loop.iteration()];
|
|
|
-
|
|
|
- data.remote_id = data.id;
|
|
|
- delete data.id;
|
|
|
-
|
|
|
- customersStorageFactory.save(data, function (customerId) {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var syncUpdatedData = function (success, error) {
|
|
|
+ get('remote_id != 0 AND customer = 1 AND modified = 1', function (updatedCustomers) {
|
|
|
+ asyncLoopFactory(updatedCustomers.length, function (loop) {
|
|
|
+ var data = updatedCustomers.item(loop.iteration());
|
|
|
+
|
|
|
+ push(data.remote_id, data, function (response) {
|
|
|
loop.next();
|
|
|
- }, function (saveErr) {
|
|
|
+ }, function () {
|
|
|
loop.next();
|
|
|
});
|
|
|
|
|
|
- // End loop
|
|
|
+ // End loop
|
|
|
}, function () {
|
|
|
- success(customers);
|
|
|
+ success(updatedCustomers);
|
|
|
});
|
|
|
+ }, function (getErr) {
|
|
|
+ error(getErr);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- }, function (removeAllErr) {
|
|
|
- error(removeAllErr);
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var syncDeletedData = function (success, error) {
|
|
|
+ get('remote_id != 0 AND customer = 1 AND modified = 2', function (deletedCustomers) {
|
|
|
+ asyncLoopFactory(deletedCustomers.length, function (loop) {
|
|
|
+ var id = deletedCustomers.item(loop.iteration()).remote_id;
|
|
|
+
|
|
|
+ destroy(id, function (response) {
|
|
|
+ loop.next();
|
|
|
+ }, function (destroyErr) {
|
|
|
+ loop.next();
|
|
|
+ });
|
|
|
+
|
|
|
+ // end loop
|
|
|
+ }, function () {
|
|
|
+ success(deletedCustomers);
|
|
|
+ });
|
|
|
+ }, function (getErr) {
|
|
|
+ error(getErr);
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var downloadSyncData = function (success, error) {
|
|
|
+ pull(null, function (customers) {
|
|
|
+
|
|
|
+ customersStorageFactory.removeAll(function () {
|
|
|
+ asyncLoopFactory(customers.length, function (loop) {
|
|
|
+ var data = customers[loop.iteration()];
|
|
|
+
|
|
|
+ data.remote_id = data.id;
|
|
|
+ delete data.id;
|
|
|
+
|
|
|
+ customersStorageFactory.save(data, function (customerId) {
|
|
|
+ loop.next();
|
|
|
+ }, function (saveErr) {
|
|
|
+ loop.next();
|
|
|
+ });
|
|
|
+
|
|
|
+ // End loop
|
|
|
+ }, function () {
|
|
|
+ success(customers);
|
|
|
+ });
|
|
|
|
|
|
- }, function (pullErr) {
|
|
|
- error(pullErr);
|
|
|
- });
|
|
|
- }
|
|
|
+ }, function (removeAllErr) {
|
|
|
+ error(removeAllErr);
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function (pullErr) {
|
|
|
+ error(pullErr);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // Sync customers data between remote and local storage
|
|
|
- var sync = function (success, error) {
|
|
|
- syncNewData(function () {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var sync = function (success, error) {
|
|
|
+ syncNewData(function () {
|
|
|
|
|
|
- syncUpdatedData(function () {
|
|
|
+ syncUpdatedData(function () {
|
|
|
|
|
|
- syncDeletedData(function () {
|
|
|
+ syncDeletedData(function () {
|
|
|
|
|
|
- downloadSyncData(function (data) {
|
|
|
- success(data);
|
|
|
- }, function (downloadErr) {
|
|
|
- error(downloadErr);
|
|
|
+ downloadSyncData(function (data) {
|
|
|
+ success(data);
|
|
|
+ }, function (downloadErr) {
|
|
|
+ error(downloadErr);
|
|
|
+ });
|
|
|
+ }, function (syncErr) {
|
|
|
+ error(syncErr);
|
|
|
});
|
|
|
}, function (syncErr) {
|
|
|
error(syncErr);
|
|
@@ -227,15 +237,12 @@ angular.module('odoo')
|
|
|
}, function (syncErr) {
|
|
|
error(syncErr);
|
|
|
});
|
|
|
- }, function (syncErr) {
|
|
|
- error(syncErr);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- pull: pull,
|
|
|
- push: push,
|
|
|
- destroy: destroy,
|
|
|
- sync: sync
|
|
|
- }
|
|
|
-});
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ pull: pull,
|
|
|
+ push: push,
|
|
|
+ destroy: destroy,
|
|
|
+ sync: sync
|
|
|
+ }
|
|
|
+ });
|