123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- angular.module('odoo')
- /**
- * -----------------------------------------------------------------------------
- * Description: Odoo connection manager
- * -----------------------------------------------------------------------------
- */
- .factory('odooFactory', function (
- $localStorage,
- xmlrpc,
- methodCallManager
- ) {
- var configuration = $localStorage;
- /**
- *
- */
- var auth = function (success, error) {
- xmlrpc.callMethod(methodCallManager.call('authenticate', configuration), [configuration.database, configuration.username, configuration.password, {}]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var read = function (model, domain, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'search_read', [domain]]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var create = function (model, data, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'create', [data]]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var write = function (model, id, data, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'write', [[id], data]]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var unlink = function (model, id, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'unlink', [[id]]]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var check = function (model, operation, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'check_access_rights', [operation], { 'raise_exception': false }]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- /**
- *
- */
- var fields = function (model, success, error) {
- xmlrpc.callMethod(methodCallManager.call('execute_kw', configuration), [configuration.database, configuration.id, configuration.password, model, 'fields_get', [], { 'attributes': ['type', 'readonly', 'required', 'relation', 'relation_field'] }]).then(function (response) {
- if (!response || response['faultCode']) {
- return error(response);
- }
- success(response);
- }, function (xmlrpcError) {
- error(xmlrpcError);
- });
- }
- return {
- auth: auth,
- read: read,
- create: create,
- write: write,
- unlink: unlink,
- check: check,
- fields: fields
- }
- })
- /**
- *
- */
- .factory('methodCallManager', function (xmlrpc) {
- return {
- call: function (methodName, configuration) {
- var hostName = configuration.host + ':' + configuration.port;
- if (!hostName.startsWith('http://')) {
- hostName = 'http://' + hostName;
- }
- if (methodName == 'authenticate') {
- xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/common' });
- } else {
- xmlrpc.config({ hostName: hostName, pathName: '/xmlrpc/2/object' });
- }
- return methodName;
- }
- }
- });
|