我想为Odoo ERP系统中的休假请求制作移动应用程序。我使用本机反应来制作应用程序。问题是我试图从用户那里获取输入,然后将其传递给Odoo API以便在系统中提交它,但是我找不到找到它的好方法
Odoo api-xmlrpc:
var Odoo = require('odoo-xmlrpc');
var odoo = new Odoo({
url: 'http://abdelazizs-macbook-pro.local',
port: '8069',
db: 'hr_2-9_test_11',
username: 'admin',
password: 'admin'
});
odoo.connect(function (err) {
if (err) { return console.log(err); }
console.log('Connected to Odoo server.');
});
odoo.connect(function (err) {
if (err) { return console.log(err); }
console.log('Connected to Odoo server.');
var inParams = [];
inParams.push({'name': 'egg'
,'holiday_status_id':parseInt(1)
, 'date_from':'2018-08-14 16:35:38'
, 'date_to':'2018-08-16 16:35:38'
, 'employee_id':parseInt(1)})
var params = [];
params.push(inParams);
odoo.execute_kw('hr.holidays', 'create', params, function (err, value) {
if (err) { return console.log(err); }
console.log('Result: ', value);
});
});
我们要用用户输入替换这些默认参数
{'name': 'egg'
,'holiday_status_id':parseInt(1)
, 'date_from':'2018-08-14 16:35:38'
, 'date_to':'2018-08-16 16:35:38'
, 'employee_id':parseInt(1)}
这是选择日期的应用程序组件之一:
import React, { Component } from 'react';
import DatePicker from 'react-native-datepicker';
import {Text, View} from 'react-native';
export default class Component1 extends Component {
constructor(props){
super(props)
this.state = {date:"2019-05-15"}
}
render(){
return(
<View>
<Text style={{fontSize:25,}}>From</Text>
<DatePicker
style={{width: 300,justifyContent: 'center',
}}
date={this.state.date}
mode="date"
placeholder="select date"
format="YYYY-MM-DD"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
right: 0,
top: 4,
marginRight: 10
},
dateInput: {
marginLeft: 36
}
// ... You can check the source to find the other keys.
}}
onDateChange={(date) => {this.setState({date: date})}}
/>
</View>
);
}
}
答案 0 :(得分:0)
您必须像这样调用组件
class MyComponent extends React.Component{
state = {
date: ''
}
callToOdoo = () => {
//your odoo call
}
dateHandler = (date) => {
this.setState({date: date}, () => {
this.callToOdoo();
})
}
render(){
return(<View>
<DatePicker
{...}
onDateChange={{this.dateHandler}}
/>