ソースを参照

SQL builder added and other odoo methods implemented

robert2206 8 年 前
コミット
7d8b53af47

+ 1 - 0
www/index.html

@@ -37,6 +37,7 @@
 
     <!-- Factories -->
     <script src="js/factories/utils.factory.js"></script>
+    <script src="js/factories/preferences.factory.js"></script>
     <script src="js/factories/odoo.factory.js"></script>
     <script src="js/factories/user.storage.factory.js"></script>
     <script src="js/factories/sales/customer.storage.factory.js"></script>

+ 95 - 73
www/js/factories/odoo.factory.js

@@ -1,86 +1,108 @@
 angular.module('odoo')
 
-.factory('odooInteroperabilityFactory', function (xmlrpc, methodCallManager) {
-    return {
-        auth: function (config, success, error) {
-            xmlrpc.callMethod(methodCallManager.call('authenticate', config), [config.database, config.username, config.password, {}]).then(function(response) {
-                if (!response || response['faultCode']) {
-                    error(response);
-                    return;
-                }
+    .factory('odooFactory', function (xmlrpc, methodCallManager) {
+        return {
+            auth: function (config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('authenticate', config), [config.database, config.username, config.password, {}]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        error(response);
+                        return;
+                    }
 
-                success({ id: response, username: config.username, password: config.password });
-            }, function (xmlrpcError) {
-                error(xmlrpcError);
-            });
-        },
-        read: function (model, domain, config, success, error) {
-            xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'search_read', [domain]]).then(function (response) {
-                if (!response || response['faultCode']) {
-                    error(response);
-                    return;
-                }
+                    success({ id: response, username: config.username, password: config.password });
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
+            },
+            read: function (model, domain, config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'search_read', [domain]]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        error(response);
+                        return;
+                    }
 
-                success(response);
-            }, function (xmlrpcError) {
-                error(xmlrpcError);
-            });
-        },
-        create: function (model, data, config, success, error) {
-            xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'create', [data]]).then(function (response) {
-                if (!response || response['faultCode']) {
-                    error(response);
-                    return;
-                }
+                    success(response);
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
+            },
+            create: function (model, data, config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'create', [data]]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        error(response);
+                        return;
+                    }
 
-                success(response);
-            }, function (xmlrpcError) {
-                error(xmlrpcError);
-            });
-        },
-        write: function (model, id, data, config, success, error) {
-            xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'write', [[id], data]]).then(function (response) {
-                if (!response || response['faultCode']) {
-                    error(response);
-                    return;
-                }
+                    success(response);
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
+            },
+            write: function (model, id, data, config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'write', [[id], data]]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        error(response);
+                        return;
+                    }
 
-                success(response);
-            }, function (xmlrpcError) {
-                error(xmlrpcError);
-            });
-        },
-        unlink: function (model, id, config, success, error) {
-            xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'unlink', [[id]]]).then(function (response) {
-                if (!response || response['faultCode']) {
-                    error(response);
-                    return;
-                }
+                    success(response);
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
+            },
+            unlink: function (model, id, config, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'unlink', [[id]]]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        error(response);
+                        return;
+                    }
 
-                success(response);
-            }, function (xmlrpcError) {
-                error(xmlrpcError);
-            });
-        }
-    }
-})
+                    success(response);
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
+            },
+            check: function (model, operation, success, error) {
+                xmlrpc.callMethod(methodCallManager.call('execute_kw', config), [config.database, config.remote_id, config.password, model, 'check_access_rights', [operation], { 'raise_exception': false }]).then(function (response) {
+                    if (!response || response['faultCode']) {
+                        return error(response);
+                    }
 
-.factory('methodCallManager', function(xmlrpc) {
-    return {
-        call: function(methodName, configuration) {
-            var hostName = configuration.host + ':' + configuration.port;
+                    success(response);
+                }, function (xmlrpcError) {
+                    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) {
+                    if (!response || response['faultCode']) {
+                        return error(response);
+                    }
 
-            if(!hostName.startsWith('http://')) {
-                hostName = 'http://' + hostName;
+                    success(response);
+                }, function (xmlrpcError) {
+                    error(xmlrpcError);
+                });
             }
+        }
+    })
 
-            if(methodName == 'authenticate') {
-                xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/common' });
-            } else {
-                xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/object' });
-            }
+    .factory('methodCallManager', function (xmlrpc) {
+        return {
+            call: function (methodName, configuration) {
+                var hostName = configuration.host + ':' + configuration.port;
+
+                if (!hostName.startsWith('http://')) {
+                    hostName = 'http://' + hostName;
+                }
 
-            return methodName;
+                if (methodName == 'authenticate') {
+                    xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/common' });
+                } else {
+                    xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/object' });
+                }
+
+                return methodName;
+            }
         }
-    }
-});
+    });

+ 25 - 26
www/js/factories/sales/crm.stage.storage.factory.js

@@ -8,33 +8,29 @@ angular.module('odoo')
     .factory('crmStagesStorageFactory', function () {
 
         // Save crm stage data to local storage
-        var save = function (crmStage, success, error) {
-            var values = [
-                crmStage.remote_id ? crmStage.remote_id : 0,
-                crmStage.name ? crmStage.name : ''
-            ];
-
-            var sql = null;
-
-            if (crmStage.id) {
-                values.push(crmStage.id);
-
-                sql = 'UPDATE crm_stage SET ' +
-                    'remote_id = ?,' +
-                    'modified = 1,' +
-                    'modified_date = CURRENT_TIMESTAMP,' +
-                    'name = ? ' +
-                    'WHERE id = ?';
+        var save = function (data, success, error) {
+            var query = null;
+
+            if (data.id) {                
+                query = squel.update()
+                    .table('crm_stage')
+                    .set('remote_id', data.remote_id)
+                    .set('modified', 1)
+                    .set('modified_date', 'CURRENT_TIMESTAMP', { dontQuote: true })
+                    .set('name', data.name)
+                    .where('id', data.id);
             } else {
-                sql = 'INSERT INTO crm_stage(' +
-                    'remote_id,' +
-                    'modified,' +
-                    'name) ' +
-                    'VALUES (?, 0, ?)';
+                query = squel.insert()
+                    .into('crm_stage')
+                    .set('remote_id', data.remote_id)
+                    .set('modified', 0)
+                    .set('name', data.name);
             }
 
-            db.executeSql(sql, values, function (result) {
-                success(sql.startsWith('INSERT') ? result.insertId : lead.id);
+            query = query.toParam();
+
+            db.executeSql(query.text(), query.values, function (result) {
+                success(query.text.startsWith('INSERT') ? result.insertId : lead.id);
             }, function (err) {
                 error(err);
             });
@@ -44,9 +40,12 @@ angular.module('odoo')
          * Remove all crm stages from local storage
          */
         var removeAll = function (success, error) {
-            var sql = 'DELETE FROM crm_stage';
+            var query = squel
+                .delete()
+                .from('crm_stage')
+                .toParam();
 
-            db.executeSql(sql, [], function(result) {
+            db.executeSql(query.text, query.values, function(result) {
                 success(result.rowsAffected);
             }, function(err) {
                 error(err);

+ 4 - 4
www/js/factories/sales/crm.stage.sync.factory.js

@@ -7,7 +7,7 @@ angular.module('odoo')
      */
     .factory('crmStagesDataFactory', function (
         crmStagesStorageFactory,
-        odooInteroperabilityFactory,
+        odooFactory,
         configFactory,
         sqlFactory,
         asyncLoopFactory
@@ -20,15 +20,15 @@ angular.module('odoo')
             configFactory(function (configuration) {
                 if (id) {
 
-                    odooInteroperabilityFactory.read('crm.case.stage', [['id', '=', id]], configuration, function (response) {
+                    odooFactory.read('crm.case.stage', [['id', '=', id]], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr);
                     });
 
                 } else {
-
-                    odooInteroperabilityFactory.read('crm.case.stage', [], configuration, function (response) {
+                    
+                    odooFactory.read('crm.case.stage', [], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr)

+ 126 - 53
www/js/factories/sales/customer.storage.factory.js

@@ -1,66 +1,139 @@
 angular.module('odoo')
 
-/**
- * -----------------------------------------------------------------------------
- *  Description:    Local storage manager for customers data
- * -----------------------------------------------------------------------------
- */
-.factory('customersStorageFactory', function () {
+    /**
+     * -----------------------------------------------------------------------------
+     *  Description:    Local storage manager for customers data
+     * -----------------------------------------------------------------------------
+     */
+    .factory('customersStorageFactory', function () {
 
-    // Save customer data to local storage
-    var save = function (customer, success, error) {
-        var sql = '';
+        /**
+         *
+         */
+        var save = function (data, success, error) {
+            var query = null;
 
-        if (customer.id) {
-            sql = `UPDATE partner SET remote_id = ${ customer.remote_id ? customer.remote_id : 0  }, modified = 1, modifiedDate = CURRENT_TIMESTAMP, name = ${ customer.name ? '"' + customer.name + '"' : null }, city = ${ customer.city ? '"' + customer.city + '"' : null }, mobile = ${ customer.mobile ? '"' + customer.mobile + '"' : null }, phone = ${ customer.phone ? '"' + customer.phone + '"' : null }, fax = ${ customer.fax ? '"' + customer.fax + '"' : null }, email = ${ customer.email ? '"' + customer.email + '"' : null }, street = ${ customer.street ? '"' + customer.street + '"' : null }, street2 = ${ customer.street2 ? '"' + customer.street2 + '"' : null }, image_medium = ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, image_small = ${ customer.image_small ? '"' + customer.image_small + '"' : null }, comment = ${ customer.comment ? '"' + customer.comment + '"' : null }, customer = ${ customer.customer ? customer.customer : 1 }, employee = ${ customer.employee ? customer.employee : 0 }, is_company = ${ customer.is_company ? customer.is_company : 0 }, debit = ${ customer.debit ? customer.debit : 0 }, debit_limit = ${ customer.debit_limit ? customer.debit_limit : 0 }, opportunity_count = ${ customer.opportunity_count ? customer.opportunity_count : 0 }, contracts_count = ${ customer.contracts_count ? customer.contracts_count : 0 }, journal_item_count = ${ customer.journal_item_count ? customer.journal_item_count : 0 }, meeting_count = ${ customer.meeting_count ? customer.meeting_count : 0 }, phonecall_count = ${ customer.phonecall_count ? customer.phonecall_count : 0 }, sale_order_count = ${ customer.sale_order_count ? customer.sale_order_count : 0 }, total_invoiced = ${ customer.total_invoiced ? customer.total_invoiced : 0 } WHERE id = ${ customer.id }`;
-        } else {
-            sql = `INSERT INTO partner(remote_id, name, city, mobile, phone, fax, email, street, street2, image_medium, image_small, comment, customer, employee, is_company, debit, debit_limit, opportunity_count, contracts_count, journal_item_count, meeting_count, phonecall_count, sale_order_count, total_invoiced) VALUES (${ customer.remote_id ? customer.remote_id : 0 }, ${ customer.name ? '"' + customer.name + '"' : null }, ${ customer.city ? '"' + customer.city + '"' : null }, ${ customer.mobile ? '"' + customer.mobile + '"' : null }, ${ customer.phone ? '"' + customer.phone + '"' : null }, ${ customer.fax ? '"' + customer.fax + '"' : null }, ${ customer.email ? '"' + customer.email + '"' : null }, ${ customer.street ? '"' + customer.street + '"' : null }, ${ customer.street2 ? '"' + customer.street2 + '"' : null }, ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, ${ customer.image_small ? '"' + customer.image_small + '"' : null }, ${ customer.comment ? '"' + customer.comment + '"' : null }, 1, 0, 0, ${ customer.debit ? customer.debit : 0 }, ${ customer.debit_limit ? customer.debit_limit : 0 }, ${ customer.opportunity_count ? customer.opportunity_count : 0 }, ${ customer.contracts_count ? customer.contracts_count : 0 }, ${ customer.journal_item_count ? customer.journal_item_count : 0 }, ${ customer.meeting_count ? customer.meeting_count : 0 }, ${ customer.phonecall_count ? customer.phonecall_count : 0 }, ${ customer.sale_order_count ? customer.sale_order_count : 0 }, ${ customer.total_invoiced ? customer.total_invoiced : 0 })`;
-        }
+            if (data.id) {
+                query = squel.update()
+                    .table('partner')
+                    .set('remote_id', data.remote_id)
+                    .set('modified', 1)
+                    .set('modifiedDate', 'CURRENT_TIMESTAMP', { dontQuote: true })
+                    .set('name', data.name)
+                    .set('city', data.city)
+                    .set('mobile', data.mobile)
+                    .set('phone', data.phone)
+                    .set('fax', data.fax)
+                    .set('email', data.email)
+                    .set('street', data.street)
+                    .set('street2', data.street2)
+                    .set('image_medium', data.image_medium)
+                    .set('image_small', data.image_small)
+                    .set('comment', data.comment)
+                    .set('customer', data.customer)
+                    .set('employee', data.employee)
+                    .set('is_company', data.is_company)
+                    .set('debit', data.debit)
+                    .set('debit_limit', data.debit_limit)
+                    .set('opportunity_count', data.opportunity_count)
+                    .set('contracts_count', data.contracts_count)
+                    .set('journal_item_count', data.journal_item_count)
+                    .set('meeting_count', data.meeting_count)
+                    .set('phonecall_count', data.phonecall_count)
+                    .set('sale_order_count', data.sale_order_count)
+                    .set('total_invoiced', data.total_invoiced)
+                    .where('id', data.id);
+            } else {
+                 query = squel.insert()
+                    .into('partner')
+                    .set('remote_id', data.remote_id)
+                    .set('modified', 0)
+                    .set('modifiedDate', 'CURRENT_TIMESTAMP', { dontQuote: true })
+                    .set('name', data.name)
+                    .set('city', data.city)
+                    .set('mobile', data.mobile)
+                    .set('phone', data.phone)
+                    .set('fax', data.fax)
+                    .set('email', data.email)
+                    .set('street', data.street)
+                    .set('street2', data.street2)
+                    .set('image_medium', data.image_medium)
+                    .set('image_small', data.image_small)
+                    .set('comment', data.comment)
+                    .set('customer', data.customer)
+                    .set('employee', data.employee)
+                    .set('is_company', data.is_company)
+                    .set('debit', data.debit)
+                    .set('debit_limit', data.debit_limit)
+                    .set('opportunity_count', data.opportunity_count)
+                    .set('contracts_count', data.contracts_count)
+                    .set('journal_item_count', data.journal_item_count)
+                    .set('meeting_count', data.meeting_count)
+                    .set('phonecall_count', data.phonecall_count)
+                    .set('sale_order_count', data.sale_order_count)
+                    .set('total_invoiced', data.total_invoiced);
+            }
 
-        db.executeSql(sql, [], function(result) {
-            success(sql.startsWith('INSERT') ? result.insertId : customer.id);
-        }, function(err) {
-            error(err);
-        });
-    };
+            query = query.toParam();
 
-    // Delete customer from local storage
-    var remove = function (customer, success, error) {
-        if (!customer.id) {
-            error('Customer cannot delete without provide an id');
-        }
+            db.executeSql(query.text, query.values, function (result) {
+                success(query.text.startsWith('INSERT') ? result.insertId : customer.id);
+            }, function (err) {
+                error(err);
+            });
+        };
 
-        var sql = '';
+        /**
+         *
+         */
+        var remove = function (data, success, error) {
+            if (!data.id) {
+                error('Customer cannot delete without provide an id');
+            }
 
-        if (customer.remote_id) {
-            sql = `UPDATE partner SET modified = 2 WHERE id = ${ customer.id }`;
-        } else {
-            sql = `DELETE FROM partner WHERE id = ${ customer.id }`;
-        }
+            var query = null;
 
-        console.log(sql);
+            if (data.remote_id) {
+                query = squel.update()
+                    .table('partner')
+                    .set('modified', 2)
+                    .where('id', data.id)
+                    .toParam();
+            } else {
+                query = squel.delete()
+                    .from('partner')
+                    .where('id', data.id)
+                    .toParam();
+            }
 
-        db.executeSql(sql, [], function(result) {
-            success(result.rowsAffected);
-        }, function(err) {
-            error(err);
-        });
-    };
+            query = query.toParam();
 
-    // Delete all customers from local storage
-    var removeAll = function (success, error) {
-        var sql = 'DELETE FROM partner WHERE customer = 1';
+            db.executeSql(query.text, query.values, function (result) {
+                success(result.rowsAffected);
+            }, function (err) {
+                error(err);
+            });
+        };
 
-        db.executeSql(sql, [], function(result) {
-            success(result.rowsAffected);
-        }, function(err) {
-            error(err);
-        });
-    };
+        /**
+         *
+         */
+        var removeAll = function (success, error) {
+            var query = squel.delete()
+                .from('partner')
+                .where('customer', 1)
+                .toParam();
 
-    return {
-        save: save,
-        remove: remove,
-        removeAll: removeAll
-    }
-});
+            db.executeSql(query.text, query.values, function (result) {
+                success(result.rowsAffected);
+            }, function (err) {
+                error(err);
+            });
+        };
+
+        return {
+            save: save,
+            remove: remove,
+            removeAll: removeAll
+        }
+    });

+ 6 - 6
www/js/factories/sales/customer.sync.factory.js

@@ -2,7 +2,7 @@ angular.module('odoo')
 
 .factory('customersRemoteFactory', function (
     customersStorageFactory,
-    odooInteroperabilityFactory,
+    odooFactory,
     configFactory,
     sqlFactory,
     asyncLoopFactory
@@ -13,7 +13,7 @@ angular.module('odoo')
         configFactory(function (configuration) {
             if (id) {
 
-                odooInteroperabilityFactory.read('res.partner', [['id', '=', id]], configuration, function (response) {
+                odooFactory.read('res.partner', [['id', '=', id]], configuration, function (response) {
                     success(response);
                 }, function (odooErr) {
                     error(odooErr);
@@ -21,7 +21,7 @@ angular.module('odoo')
 
             } else {
 
-                odooInteroperabilityFactory.read('res.partner', [['customer', '=', true]], configuration, function (response) {
+                odooFactory.read('res.partner', [['customer', '=', true]], configuration, function (response) {
                     success(response);
                 }, function (odooErr) {
                     error(odooErr)
@@ -55,7 +55,7 @@ angular.module('odoo')
 
                         if (localDate > remoteDate) {
 
-                            odooInteroperabilityFactory.write('res.partner', id, data, configuration, function (response) {
+                            odooFactory.write('res.partner', id, data, configuration, function (response) {
                                 success(response);
                             }, function (odooErr) {
                                 error(odooErr);
@@ -77,7 +77,7 @@ angular.module('odoo')
 
                 delete data.modifiedDate;
 
-                odooInteroperabilityFactory.create('res.partner', data, configuration, function (response) {
+                odooFactory.create('res.partner', data, configuration, function (response) {
                     success(response);
                 }, function (odooErr) {
                     error(odooErr);
@@ -93,7 +93,7 @@ angular.module('odoo')
     var destroy = function(id, success, error) {
         configFactory(function (configuration) {
 
-            odooInteroperabilityFactory.unlink('res.partner', id, configuration, function (response) {
+            odooFactory.unlink('res.partner', id, configuration, function (response) {
                 success(response);
             }, function (odooInteroperabilityFactoryErr) {
                 error(odooInteroperabilityFactoryErr);

+ 78 - 86
www/js/factories/sales/lead.storage.factory.js

@@ -2,113 +2,105 @@ angular.module('odoo')
 
 .factory('leadsStorageFactory', function () {
 
-    // Save lead data to local storage
-    var save = function (lead, success, error) {
-        
-        var values = [
-                        lead.remote_id ? lead.remote_id : 0,
-                        lead.name ? lead.name : '',
-                        lead.description ? lead.description : '',
-                        lead.contact_name ? lead.contact_name : '',
-                        lead.phone ? lead.phone : '',
-                        lead.mobile ? lead.mobile : '',
-                        lead.fax ? lead.fax : '',
-                        lead.street ? lead.street : '',
-                        lead.street2 ? lead.street2 : '',
-                        lead.meeting_count ? lead.meeting_count : 0,
-                        lead.message_bounce ? lead.message_bounce : 0,
-                        lead.planned_cost ? lead.planned_cost : 0,
-                        lead.planned_revenue ? lead.planned_revenue : 0,
-                        lead.priority ? lead.priority : 2,
-                        lead.probability ? lead.probability : 0,
-                        lead.type ? lead.type : 'lead',
-                        typeof lead.stage_id == 'number' ? lead.stage_id : parseInt(lead.stage_id.split(',')[0]),
-                        lead.user_id ? lead.user_id : 0,
-                        lead.partner_id ? lead.partner_id : 0
-                    ];
+    /**
+     *
+     */
+    var save = function (data, success, error) {
+        var query = null;
 
-        var sql = null;
-
-        if (lead.id) {
-            values.push(lead.id);
-
-            sql = 'UPDATE lead SET ' +
-                  'remote_id = ?,' +
-                  'modified = 1,' +
-                  'modifiedDate = CURRENT_TIMESTAMP,' +
-                  'name = ?,' +
-                  'description = ?,' +
-                  'contact_name = ?,' +
-                  'phone = ?,' +
-                  'mobile = ?,' +
-                  'fax = ?,' +
-                  'street = ?,' +
-                  'street2 = ?,' +
-                  'meeting_count = ?,' +
-                  'message_bounce = ?,' +
-                  'planned_cost = ?,' +
-                  'planned_revenue = ?,' +
-                  'priority = ?,' +
-                  'probability = ?,' +
-                  'type = ?,' +
-                  'stage_id = ?,' +
-                  'user_id = ?,' +
-                  'partner_id = ? ' +
-                  'WHERE id = ?';
+        if (data.id) {
+            query = squel.update()
+                .table('lead')
+                .set('remote_id', data.remote_id)
+                .set('name', data.name)
+                .set('description', data.description)
+                .set('contact_name', data.contact_name)
+                .set('phone', data.phone)
+                .set('mobile', data.mobile)
+                .set('fax', data.fax)
+                .set('street', data.street)
+                .set('street2', data.street2)
+                .set('meeting_count', data.meeting_coun)
+                .set('message_bounce', data.message_bounce)
+                .set('planned_cost', data.planned_cost)
+                .set('planned_revenue', data.planned_revenue)
+                .set('priority', data.priority)
+                .set('probability', data.probability)
+                .set('type', data.type)
+                .set('stage_id', data.stage_id)
+                .set('user_id', data.user_id)
+                .set('partner_id', data.partner_id)
+                .where('id', data.id);
         } else {
-            sql = 'INSERT INTO lead(' +
-                'remote_id,' +
-                'modified,' +
-                'name,' +
-                'description,' +
-                'contact_name,' +
-                'phone,' +
-                'mobile,' +
-                'fax,' +
-                'street,' +
-                'street2,' +
-                'meeting_count,' +
-                'message_bounce,' +
-                'planned_cost,' +
-                'planned_revenue,' +
-                'priority,' +
-                'probability,' +
-                'type,' +
-                'stage_id,' +
-                'user_id,' +
-                'partner_id) ' +
-                'VALUES(?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+            query = squel.insert()
+                .into('lead')
+                .set('remote_id', data.remote_id)
+                .set('modified', data.modified)
+                .set('name', data.name)
+                .set('description', data.description)
+                .set('contact_name', data.contact_name)
+                .set('phone', data.phone)
+                .set('mobile', data.mobile)
+                .set('fax', data.fax)
+                .set('street', data.street)
+                .set('street2', data.street2)
+                .set('meeting_count', data.meeting_count)
+                .set('message_bounce', data.message_bounce)
+                .set('planned_cost', data.planned_cost)
+                .set('planned_revenue', data.street)
+                .set('priority', data.priority)
+                .set('probability', data.probability)
+                .set('type', data.type)
+                .set('stage_id', typeof data.stage_id == 'number' ? data.stage_id : parseInt(data.stage_id.split(',')[0]))
+                .set('user_id', data.user_id)
+                .set('partner_id', data.partner_id);
         }
 
-        db.executeSql(sql, values, function (result) {
-            success(sql.startsWith('INSERT') ? result.insertId : lead.id);
+        query = query.toParam();
+       
+        db.executeSql(query.text, query.values, function (result) {
+            success(query.text.startsWith('INSERT') ? result.insertId : lead.id);
         }, function (err) {
             error(err);
         });
     }
 
-    // Remove lead from local storage
-    var remove = function (lead, success, error) {
-        var values = [lead.id];
-        var sql = null;
+    /**
+     *
+     */
+    var remove = function (data, success, error) {
+        var query = null;
 
-        if (lead.remote_id) {
-            sql = 'UPDATE lead SET modified = 2 WHERE id = ?';
+        if (data.remote_id) {
+            query = squel.update()
+                .table('lead')
+                .set('modified', 2)
+                .set('id', data.id);
         } else {
-            sql = 'DELETE FROM lead WHERE id = ?'
+            query = squel.delete()
+                from('lead')
+                    .where('id', data.id);
         }
 
-        db.executeSql(sql, values, function (result) {
+        query = query.toParam();
+
+        db.executeSql(query.text, query.values, function (result) {
             success(result.rowsAffected);
         }, function(err) {
             error(err);
         });
     }
 
+    /**
+     *
+     */
     var removeAll = function (success, error) {
-        var sql = "DELETE FROM lead WHERE type = 'lead'";
+        var query = squel.delete()
+            .from('lead')
+            .where('type', 'lead')
+            .toParam();
 
-        db.executeSql(sql, [], function(result) {
+        db.executeSql(query.text, query.values, function(result) {
             success(result.rowsAffected);
         }, function(err) {
             error(err);

+ 6 - 6
www/js/factories/sales/lead.sync.factory.js

@@ -2,7 +2,7 @@ angular.module('odoo')
 
     .factory('leadsRemoteFactory', function (
         leadsStorageFactory,
-        odooInteroperabilityFactory,
+        odooFactory,
         configFactory,
         sqlFactory,
         asyncLoopFactory
@@ -13,7 +13,7 @@ angular.module('odoo')
             configFactory(function (configuration) {
                 if (id) {
 
-                    odooInteroperabilityFactory.read('crm.lead', [['id', '=', id]], configuration, function (response) {
+                    odooFactory.read('crm.lead', [['id', '=', id]], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr)
@@ -21,7 +21,7 @@ angular.module('odoo')
 
                 } else {
 
-                    odooInteroperabilityFactory.read('crm.lead', [['type', '=', 'lead']], configuration, function (response) {
+                    odooFactory.read('crm.lead', [['type', '=', 'lead']], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr);
@@ -57,7 +57,7 @@ angular.module('odoo')
 
                             if (localDate > remoteDate) {
 
-                                odooInteroperabilityFactory.write('crm.lead', id, data, configuration, function (response) {
+                                odooFactory.write('crm.lead', id, data, configuration, function (response) {
                                     console.log(response);
                                     success(response);
                                 }, function (odooErr) {
@@ -81,7 +81,7 @@ angular.module('odoo')
 
                     delete data.modifiedDate;
 
-                    odooInteroperabilityFactory.create('crm.lead', data, configuration, function (response) {
+                    odooFactory.create('crm.lead', data, configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr);
@@ -98,7 +98,7 @@ angular.module('odoo')
         var destroy = function (id, success, error) {
             configFactory(function (configuration) {
 
-                odooInteroperabilityFactory.unlink('crm.lead', id, configuration, function (response) {
+                odooFactory.unlink('crm.lead', id, configuration, function (response) {
                     success(response);
                 }, function (odooErr) {
                     error(odooErr);

+ 21 - 12
www/js/factories/sales/opportunity.storage.factory.js

@@ -10,10 +10,10 @@ angular.module('odoo')
         /**
          *
          */
-        var save = function (opportunity, success, error) {
-            opportunity.type = 'opportunity';
+        var save = function (data, success, error) {
+            data.type = 'opportunity';
 
-            leadsStorageFactory.save(opportunity, function (opportunityId) {
+            leadsStorageFactory.save(data, function (opportunityId) {
                 success(opportunityId);
             }, function (saveErr) {
                 error(saveErr);
@@ -23,17 +23,23 @@ angular.module('odoo')
         /**
          *
          */
-        var remove = function (opportunity, success, error) {
-            var values = [opportunity.id];
-            var sql = null;
+        var remove = function (data, success, error) {
+            var query = null;
 
-            if (opportunity.remote_id) {
-                sql = 'UPDATE lead SET modified = 2 WHERE id = ?';
+            if (data.remote_id) {
+                query = squel.update()
+                    .table('lead')
+                    .set('modified', 2)
+                    .where('id', data.id);
             } else {
-                sql = 'DELETE FROM lead WHERE id = ?'
+                query = squel.delete()
+                    .from('lead')
+                    .where('id', data.id);
             }
 
-            db.executeSql(sql, values, function (result) {
+            query = query.toParam();
+
+            db.executeSql(query.text, query.values, function (result) {
                 success(result.rowsAffected);
             }, function (err) {
                 error(err);
@@ -44,9 +50,12 @@ angular.module('odoo')
          *
          */
         var removeAll = function (success, error) {
-            var sql = "DELETE FROM lead WHERE type = 'opportunity'";
+            var query = squel.delete()
+                .from('lead')
+                .where('type', 'opportunity')
+                .toParam();
 
-            db.executeSql(sql, [], function (result) {
+            db.executeSql(query.text, query.values, function (result) {
                 success(result.rowsAffected);
             }, function (err) {
                 error(err);

+ 3 - 3
www/js/factories/sales/opportunity.sync.factory.js

@@ -8,7 +8,7 @@ angular.module('odoo')
     .factory('opportunitiesDataFactory', function (
         opportunitiesStorageFactory,
         leadsRemoteFactory,
-        odooInteroperabilityFactory,
+        odooFactory,
         configFactory,
         sqlFactory,
         asyncLoopFactory
@@ -21,7 +21,7 @@ angular.module('odoo')
             configFactory(function (configuration) {
                 if (id) {
 
-                    odooInteroperabilityFactory.read('crm.lead', [['id', '=', id]], configuration, function (response) {
+                    odooFactory.read('crm.lead', [['id', '=', id]], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr);
@@ -29,7 +29,7 @@ angular.module('odoo')
 
                 } else {
 
-                    odooInteroperabilityFactory.read('crm.lead', [['type', '=', 'opportunity']], configuration, function (response) {
+                    odooFactory.read('crm.lead', [['type', '=', 'opportunity']], configuration, function (response) {
                         success(response);
                     }, function (odooErr) {
                         error(odooErr);

+ 3 - 2
www/templates/sales/customer.html

@@ -2,8 +2,8 @@
     <ion-header-bar class="bar bar-positive">
         <h1 class="title">Cliente</h1>
         <div class="buttons">
-            <button class="button button-clear ion-camera" style="font-size:22px !important; padding-right: 5px;" ng-disabled="!customer.name" ng-click="takePicture()"></i></button>
-            <button class="button button-clear ion-checkmark-round" style="font-size:22px !important; padding-left: 5px;" type="submit" form="customer-form" ng-disabled="!customer.name"></button>
+            <button class="button button-clear ion-camera bar-icon" ng-disabled="!customer.name" ng-click="takePicture()"></i></button>
+            <button class="button button-clear ion-checkmark-round bar-icon" type="submit" form="customer-form" ng-disabled="!customer.name"></button>
         </div>
    </ion-header-bar>
     <ion-content>
@@ -14,6 +14,7 @@
         </div>
         <form id="customer-form" ng-submit="save()">
             <div class="list">
+                <input type="hidden" ng-model="customer.customer" ng-init="customer.customer = 1">
                 <label class="item item-input item-stacked-label">
                     <span class="input-label">Nombre</span>
                     <input type="text" autofocus="autofocus" ng-model="customer.name">