问题描述
我正在使用angular2构建一个应用程序,该应用程序必须能够获取数据并将其插入Odoo数据库中,为此,我正在使用angular2-odoo-jsonrpc: https://www.npmjs.com/package/angular2-odoo-jsonrpc
I am building an app with angular2 that has to be able to fetch and insert data into Odoo database , in that purpose , I am using angular2-odoo-jsonrpc : https://www.npmjs.com/package/angular2-odoo-jsonrpc
我能够从Odoo中获得所需的所有数据,但是,我也希望能够在Odoo数据库中插入数据,因此我习惯于以下代码:
and I was able to get all the data I needed from Odoo , but , I also want to be able to insert data in the Odoo database , so I used to following code :
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).有什么帮助吗?
I suppose I didn't know how to use the call function : call(model, method, args, kwargs) . Any help ?
推荐答案
我终于可以为call方法找到正确的参数,并且可以正常工作,并且可以向Odoo数据库中添加新项目:
I finally could find the right arguments for the call method and it worked and I could add a new project to Odoo database :
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){
}}
这篇关于如何通过我的angular2应用在Odoo中创建一个新项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!