Ver Fonte

database builder started

robert há 8 anos atrás
pai
commit
d21239c108

+ 1 - 0
config.xml

@@ -18,6 +18,7 @@
   <preference name="android-targetSdkVersion" value="23"/>
   <preference name="BackupWebStorage" value="none"/>
   <preference name="SplashScreen" value="screen"/>
+  <preference name="AndroidPersistentFileLocation" value="Compatibility" />
   <feature name="StatusBar">
     <param name="ios-package" value="CDVStatusBar" onload="true"/>
   </feature>

+ 4 - 3
www/init.sql

@@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS 'partner' (
     'id' INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
     'remote_id' INTEGER DEFAULT 0,
     'modified' INTEGER DEFAULT 0,
-    'modifiedDate' TEXT DEFAULT CURRENT_TIMESTAMP,
+    'modified_date' TEXT DEFAULT CURRENT_TIMESTAMP,
     'name' VARCHAR(35) DEFAULT NULL,
     'city' VARCHAR(35) DEFAULT NULL,
     'mobile' VARCHAR(20) DEFAULT NULL,
@@ -40,12 +40,13 @@ CREATE TABLE IF NOT EXISTS 'partner' (
     'total_invoiced' INTEGER DEFAULT NULL
 );
 
+
 -- Lead Table
-CREATE TABLE IF NOT EXISTS 'lead' (
+CREATE TABLE IF NOT EXISTS 'crm_lead' (
     'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
     'remote_id' INTEGER DEFAULT 0,
     'modified' INTEGER DEFAULT 0,
-    'modifiedDate' TEXT DEFAULT CURRENT_TIMESTAMP,
+    'modified_date' TEXT DEFAULT CURRENT_TIMESTAMP,
     'name' VARCHAR(35) DEFAULT NULL,
     'description' VARCHAR(100) DEFAULT NULL,
     'contact_name' VARCHAR(100) DEFAULT NULL,

+ 1 - 1
www/js/controllers/configuration.controller.js

@@ -11,7 +11,7 @@ angular.module('odoo')
 ) {
 
     // $scope.config = { host: 'localhost', port: 8069, database: 'odoo', username: 'admin', password: 'admin' };
-    $scope.config = { host: '192.168.2.106', port: 8069, database: 'odoo', username: 'admin', password: 'admin' };
+    $scope.config = { host: '192.168.2.105', port: 8069, database: 'odoo', username: 'admin', password: 'admin' };
 
     $scope.$on('ionicView.enter', function () {
         console.log('Evaluar usuario');

+ 173 - 168
www/js/controllers/customer.controller.js

@@ -1,192 +1,197 @@
 angular.module('odoo')
 
-.controller('CustomersController', function (
-    $scope,
-    $ionicModal,
-    $ionicActionSheet,
-    $ionicPopup,
-    customersRemoteFactory,
-    customersStorageFactory,
-    sqlFactory,
-    cameraFactory,
-    contactFactory
-) {
-    $scope.loading = false;
-    $scope.customers = [];
-    $scope.customer = {};
-
-    $ionicModal.fromTemplateUrl('templates/sales/customer.html', {
-        scope: $scope,
-        animation: 'slide-in-up'
-    }).then(function(modal) {
-        $scope.customerModal = modal;
-    });
+    .controller('CustomersController', function (
+        $scope,
+        $ionicModal,
+        $ionicActionSheet,
+        $ionicPopup,
+        customersRemoteFactory,
+        customersStorageFactory,
+        sqlFactory,
+        cameraFactory,
+        contactFactory
+    ) {
+        $scope.loading = false;
+        $scope.customers = [];
+        $scope.customer = {};
 
-    $scope.$on('$ionicView.enter', function () {
-        $scope.fill();
-    });
+        $ionicModal.fromTemplateUrl('templates/sales/customer.html', {
+            scope: $scope,
+            animation: 'slide-in-up'
+        }).then(function (modal) {
+            $scope.customerModal = modal;
+        });
 
-    $scope.$on('$destroy', function() {
-        $scope.customerModal.remove();
-    });
+        $scope.$on('$ionicView.enter', function () {
+            $scope.fill();
+        });
 
-    $scope.$on('modal.hidden', function() {
-        $scope.customer = {};
-    });
+        $scope.$on('$destroy', function () {
+            $scope.customerModal.remove();
+        });
 
-    // Fill view list from data readed from local database
-    $scope.fill = function (refresh = false) {
-        $scope.loading = !refresh;
+        $scope.$on('modal.hidden', function () {
+            $scope.customer = {};
+        });
 
-        customersRemoteFactory.sync(function (customers) {
-            console.log('Customers sync correctly and receive ' + customers.length + ' items');
+        // Fill view list from data readed from local database
+        $scope.fill = function (refresh = false) {
+            $scope.loading = !refresh;
 
-            $scope.getCustomers(function () {
-                $scope.$broadcast('scroll.refreshComplete');
-                $scope.loading = false;
-            }, function (getCustomersError) {
-                $scope.$broadcast('scroll.refreshComplete');
-                $scope.loading = false;
+            customersRemoteFactory.sync(function (customers) {
+                console.log('Customers sync correctly and receive ' + customers.length + ' items');
 
-                $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
-            });
-        }, function (syncErr) {
+                $scope.getCustomers(function () {
+                    $scope.$broadcast('scroll.refreshComplete');
+                    $scope.loading = false;
+                }, function (getCustomersError) {
+                    console.log(getCustomersError);
 
-            $scope.getCustomers(function () {
-                $scope.$broadcast('scroll.refreshComplete');
-                $scope.loading = false;
-            }, function (getCustomersError) {
-                $scope.$broadcast('scroll.refreshComplete');
-                $scope.loading = false;
+                    $scope.$broadcast('scroll.refreshComplete');
+                    $scope.loading = false;
 
-                $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
+                    $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
+                });
+            }, function (syncErr) {
+                console.log(syncErr);
+
+                $scope.getCustomers(function () {
+                    $scope.$broadcast('scroll.refreshComplete');
+                    $scope.loading = false;
+                }, function (getCustomersError) {
+                    console.log(getCustomersError);
+                    
+                    $scope.$broadcast('scroll.refreshComplete');
+                    $scope.loading = false;
+
+                    $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
+                });
             });
-        });
-    }
-
-    // Get filtered customers for correct data visualization
-    $scope.getCustomers = function (success, error) {
-        sqlFactory.selectByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
-            $scope.customers = [];
+        }
 
-            for (var i = 0; i < customers.length; i++) {
-                $scope.customers.push(customers.item(i));
-            }
+        // Get filtered customers for correct data visualization
+        $scope.getCustomers = function (success, error) {
+            sqlFactory.selectByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
+                $scope.customers = [];
 
-            $scope.$apply();
-            success();
-        }, function (customerGetByConstraintError) {
-            error(customerGetByConstraintError);
-        });
-    }
+                for (var i = 0; i < customers.length; i++) {
+                    $scope.customers.push(customers.item(i));
+                }
 
-    // Show action sheet for customer options
-    $scope.openOptions = function(index) {
-        if (index == -1) {
-            $scope.customer = {};
-        } else {
-            $scope.customer = $scope.customers[index];
+                $scope.$apply();
+                success();
+            }, function (customerGetByConstraintError) {
+                error(customerGetByConstraintError);
+            });
         }
 
-        console.log('Customer selected => ' + JSON.stringify($scope.customer));
+        // Show action sheet for customer options
+        $scope.openOptions = function (index) {
+            if (index == -1) {
+                $scope.customer = {};
+            } else {
+                $scope.customer = $scope.customers[index];
+            }
+
+            console.log('Customer selected => ' + JSON.stringify($scope.customer));
 
-        $ionicActionSheet.show({
-            titleText: 'Acciones',
-            buttons: [
-                {
-                    text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
+            $ionicActionSheet.show({
+                titleText: 'Acciones',
+                buttons: [
+                    {
+                        text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
+                    },
+                    {
+                        text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
+                    }
+                ],
+                destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
+                cancel: function () {
+                    $scope.customer = {};
+                    console.log('ActionSheet canceled');
+                },
+                buttonClicked: function (index) {
+                    switch (index) {
+                        case 0:
+                            $scope.show();
+                            break;
+                        case 1:
+                            $scope.addContact();
+                            break;
+                        default:
+                            $scope.show();
+                    }
+                    return true;
                 },
-                {
-                    text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
+                destructiveButtonClicked: function () {
+                    $scope.delete();
+
+                    return true;
                 }
-            ],
-            destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
-            cancel: function() {
+            });
+        }
+
+        // Save a customer data on local database
+        $scope.save = function () {
+            customersStorageFactory.save($scope.customer, function (customerId) {
+                if (!$scope.customer.id) {
+                    $scope.customer.id = customerId;
+                    $scope.customers.push($scope.customer);
+                }
+
                 $scope.customer = {};
-                console.log('ActionSheet canceled');
-            },
-            buttonClicked: function(index) {
-                switch (index) {
-                    case 0:
-                        $scope.show();
-                        break;
-                    case 1:
-                        $scope.addContact();
-                        break;
-                    default:
-                        $scope.show();
+                $scope.customerModal.hide();
+                console.log('Customer saved');
+            }, function (error) {
+                $ionicPopup.alert({ title: 'No se ha podido guardar el cliente', template: JSON.stringify(error) });
+                console.log(JSON.stringify(error));
+            });
+        }
+
+        // Delete a customer from local database
+        $scope.delete = function () {
+            $ionicPopup.confirm({
+                title: 'Confirmar',
+                template: 'Estás seguro que quieres eliminar este cliente?'
+            }).then(function (confirmation) {
+                if (confirmation) {
+                    customersStorageFactory.remove($scope.customer, function (affected) {
+                        if (affected != 0) {
+                            var index = $scope.customers.indexOf($scope.customer);
+                            $scope.customers.splice(index, 1);
+                            $scope.customer = {};
+
+                            $scope.$apply();
+                        }
+                    }, function (error) {
+                        $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
+                        console.log(JSON.stringify(error));
+                    });
                 }
-                return true;
-            },
-            destructiveButtonClicked: function() {
-                $scope.delete();
+            });
+        }
 
-                return true;
-            }
-        });
-    }
-
-    // Save a customer data on local database
-    $scope.save = function() {
-        customersStorageFactory.save($scope.customer, function (customerId) {
-            if (!$scope.customer.id) {
-                $scope.customer.id = customerId;
-                $scope.customers.push($scope.customer);
-            }
+        // Show customer data in modal
+        $scope.show = function () {
+            $scope.customerModal.show();
+        }
 
-            $scope.customer = {};
-            $scope.customerModal.hide();
-            console.log('Customer saved');
-        }, function (error) {
-            $ionicPopup.alert({ title: 'No se ha podido guardar el cliente', template: JSON.stringify(error) });
-            console.log(JSON.stringify(error));
-        });
-    }
-
-    // Delete a customer from local database
-    $scope.delete = function () {
-        $ionicPopup.confirm({
-            title: 'Confirmar',
-            template: 'Estás seguro que quieres eliminar este cliente?'
-        }).then(function (confirmation) {
-            if(confirmation) {
-                customersStorageFactory.remove($scope.customer, function (affected) {
-                    if (affected != 0) {
-                        var index = $scope.customers.indexOf($scope.customer);
-                        $scope.customers.splice(index, 1);
-                        $scope.customer = {};
-
-                        $scope.$apply();
-                    }
-                }, function (error) {
-                    $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
-                    console.log(JSON.stringify(error));
-                });
-            }
-        });
-    }
-
-    // Show customer data in modal
-    $scope.show = function () {
-        $scope.customerModal.show();
-    }
-
-    // Take a picture from camera for customer profile
-    $scope.takePicture = function () {
-        cameraFactory.takePicture(function (imageData) {
-            $scope.customer.image_small = imageData;
-            $scope.customer.image_medium = imageData;
-        }, function (error) {
-            console.log(error);
-        });
-    }
-
-    // Add customer data contact to device mobile contacts
-    $scope.addContact = function () {
-        contactFactory.save($scope.customer, function (result) {
-            $ionicPopup.alert({ title: 'Contacto guardado' });
-        }, function (error) {
-            console.log(error);
-        })
-    }
-});
+        // Take a picture from camera for customer profile
+        $scope.takePicture = function () {
+            cameraFactory.takePicture(function (imageData) {
+                $scope.customer.image_small = imageData;
+                $scope.customer.image_medium = imageData;
+            }, function (error) {
+                console.log(error);
+            });
+        }
+
+        // Add customer data contact to device mobile contacts
+        $scope.addContact = function () {
+            contactFactory.save($scope.customer, function (result) {
+                $ionicPopup.alert({ title: 'Contacto guardado' });
+            }, function (error) {
+                console.log(error);
+            })
+        }
+    });

+ 13 - 3
www/js/controllers/sale.controller.js

@@ -1,5 +1,15 @@
 angular.module('odoo')
 
-.controller('SaleController', function ($scope) {
-    console.log('sale controller');
-});
+    .controller('SaleController', function ($scope, odooFactory, configFactory) {
+
+        configFactory(function (configuration) {
+            odooFactory.fields('res.partner', configuration, function (ok) {
+                console.log(ok);
+            }, function (fail) {
+                console.log(fail);
+            });
+        }, function (err) {
+
+        });
+
+    });

+ 2 - 2
www/js/factories/odoo.factory.js

@@ -73,8 +73,8 @@ angular.module('odoo')
                     error(xmlrpcError);
                 });
             },
-            fields: function (model, success, error) {
-                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'fields_get', [], { 'attributes': ['string', 'type'] }]).then(function (response) {
+            fields: function (model, config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'fields_get', [], { 'attributes': ['string', 'type', 'length'] }]).then(function (response) {
                     if (!response || response['faultCode']) {
                         return error(response);
                     }

+ 4 - 4
www/js/factories/sales/lead.storage.factory.js

@@ -10,7 +10,7 @@ angular.module('odoo')
 
         if (data.id) {
             query = squel.update()
-                .table('lead')
+                .table('crm_lead')
                 .set('remote_id', data.remote_id)
                 .set('name', data.name)
                 .set('description', data.description)
@@ -33,7 +33,7 @@ angular.module('odoo')
                 .where('id', data.id);
         } else {
             query = squel.insert()
-                .into('lead')
+                .into('crm_lead')
                 .set('remote_id', data.remote_id)
                 .set('modified', data.modified)
                 .set('name', data.name)
@@ -73,12 +73,12 @@ angular.module('odoo')
 
         if (data.remote_id) {
             query = squel.update()
-                .table('lead')
+                .table('crm_lead')
                 .set('modified', 2)
                 .set('id', data.id);
         } else {
             query = squel.delete()
-                from('lead')
+                from('crm_lead')
                     .where('id', data.id);
         }