1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- angular.module('odoo')
- .factory('odoo', 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(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);
- });
- },
- 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);
- });
- }
- }
- })
- .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;
- }
- }
- });
|