astronaut1712 / angular2-odoo-jsonrpc

OdooRPC for angular2
21 stars 24 forks source link

How to create a new timesheet #9

Open MeriemBo opened 7 years ago

MeriemBo commented 7 years ago

I want to create a new timesheet in the backend of Odoo via my app ,

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{

ngOnInit(){ let self = this; 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); }) } constructor( private odooRPC: OdooRPCService){ }}

What should I put in the arguments of the create method ? :/ and should it be relied to some kinf of forms ?

hengkyz commented 7 years ago
 this._angularOdooService.call('crm.stage', 'create', [{  'name':this.crmStageForm.controls['name'].value,
                                                             'usage':this.crmStageForm.controls['usage'].value,
                                                             'probability':0}], {})
      .subscribe(res => {
        this._router.navigate(['/crm/crm-stage/'+res.result+'/view']);
        this._snackBarService.open('Data succesfully created', '', { duration: 8000 })

      })

that is the example, how to create, indeed you need some form to catch the input, without form how you get the input what data should be created?

MeriemBo commented 7 years ago

I'll need the following fields : -the date -the project -the task -the time spent

hengkyz commented 7 years ago
[{  'name':this.crmStageForm.controls['name'].value,
     'usage':this.crmStageForm.controls['usage'].value,
     'probability':0}]

put the value there

MeriemBo commented 7 years ago

I'm sorry but can you please be more explicit ?

hengkyz commented 7 years ago

like i told you you in your previous question, you should learn about angular2 form, to catch the input from the user. then put that input in the dict that i told you above, if you just want to try it without input, you can just put const value in that dict

[[{  'name':'test_project_name',
     'time_spend':10,
     'description':'demo description'}]]

you can try that script it should be work fine

MeriemBo commented 7 years ago

All right , I'll try working with this , thank you so much.

hengkyz commented 7 years ago

please close the issue

MeriemBo commented 7 years ago

Hello again , if you don't mind @hengkyz , I keep getting an error TS2339 : Property"crmStageFrom" does not exist on time Timesheet , with the line : this.crmStageForm.controls['name'].value , I literraly used what you said :

import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms'; import { OdooRPCService } from 'angular2-odoo-jsonrpc'; import { MdSnackBar, MdSnackBarConfig } from '@angular/material'; import { ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; import { timesheet } from './timesheet'; ... ... ngOnInit() { let self=this; self.odooRPC.call('crm.stage', 'create', [{ 'name':self.crmStageForm.controls['name'].value, 'usage':this.crmStageForm.controls['usage'].value, 'probability':0}], {}) .subscribe(res => { self.router.navigate(['/crm/crm-stage/'+res.result+'/view']); self.snackbar.open('Data succesfully created', '', { duration: 8000 })

        })
}
hengkyz commented 7 years ago

the error because you did not declare the crmStageFrom in your class, this. crmStageForm = this.fb.group({ name: [null], });

MeriemBo commented 7 years ago

import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms'; import { OdooRPCService } from 'angular2-odoo-jsonrpc'; import { MdSnackBar, MdSnackBarConfig } from '@angular/material'; import { ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; import { timesheet } from './timesheet'; import {Http, Response} from '@angular/http'; import 'rxjs/Rx';

@Component({ selector: 'timesheet', templateUrl: 'timesheet.component.html', }) export class Timesheet implements OnInit {

TimesheetForm: FormGroup;
public submitted: boolean;
constructor(private fb: FormBuilder,private odooRPC: OdooRPCService, private router: Router,private snackbar: MdSnackBar,public viewContainerRef: ViewContainerRef) {
    this. TimesheetForm = this.fb.group({ name: [null], });
}

ngOnInit() {
    let self=this;
    self.odooRPC.call('crm.stage', 'create', [{  'name':self.TimesheetForm.controls['name'].value,
        'usage':this.TimesheetForm.controls['usage'].value,
        'probability':0}], {})
        .subscribe((res:Response) => {
            self.router.navigate(['/crm/crm-stage/'+res.result+'/view']);
            self.snackbar.open('Data succesfully created', '', { duration: 8000 })
        })
}

@hengkyz now the .subscribe funtion gives an error : TS2339 subscribe does not exist on type promise

hengkyz commented 7 years ago

hy @MeriemBo you cant subscribe the promise type, you should use ".then" instead of subscribe