我正在使用angular2构建一个应用程序,该应用程序必须能够获取并将数据插入到Odoo数据库中,为此,我使用angular2-odoo-jsonrpc:https://www.npmjs.com/package/angular2-odoo-jsonrpc
我能够从Odoo获取所需的所有数据,但是,我也希望能够在Odoo数据库中插入数据,所以我习惯了以下代码:
import { Component, OnInit } from '@angular/core';
import { OdooRPCService } from 'angular2-odoo-jsonrpc';
import { Http} from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [OdooRPCService]
})
export class AppComponent implements OnInit{
projectList;
ngOnInit(){
let self = this;
self.projectList = [];
self.odooRPC.init({
odoo_server: "https://demo"
});
self.odooRPC.login('DB', 'admin', 'admin').then(res => {
console.log('login success');
}).catch( err => {
console.error('login failed', err);
})
self.odooRPC.call('project.project', 'create',"" ,{ 'name' :'New project'})
.then((projects:any) => {
if(projects){
self.projectList = projects;
}
})
}
constructor( private odooRPC: OdooRPCService){
}}
但我一直收到这个错误:
error_handler.js:54 EXCEPTION: Uncaught (in promise): Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 964, in call
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 888, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
TypeError: create() got an unexpected keyword argument 'fields'
我想我不知道如何使用调用函数:call(model,method,args,kwargs)。有帮助吗?
答案 0 :(得分:0)
我终于可以找到调用方法的正确参数并且它可以工作,我可以向Odoo数据库添加一个新项目:
import { Component, OnInit } from '@angular/core';
import { OdooRPCService } from 'angular2-odoo-jsonrpc';
import { Http} from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [OdooRPCService]
})
export class AppComponent implements OnInit{
projectList;
ngOnInit(){
let self = this;
self.projectList = [];
self.odooRPC.init({
odoo_server: "https://demo"
});
self.odooRPC.login('DB', 'admin', 'admin').then(res => {
console.log('login success');
}).catch( err => {
console.error('login failed', err);
})
**self.odooRPC.call('project.project', 'create',[{name:'New'}] , {})**
.then((projects:any) => {
if(projects){
self.projectList = projects;
}
})
}
constructor( private odooRPC: OdooRPCService){
}}