angular2-odoo-jsonrpc icon indicating copy to clipboard operation
angular2-odoo-jsonrpc copied to clipboard

How to create a new timesheet

Open MeriemBo opened this issue 7 years ago • 11 comments

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 ?

MeriemBo avatar Apr 19 '17 08:04 MeriemBo

 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?

hengkyz avatar Apr 19 '17 09:04 hengkyz

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

MeriemBo avatar Apr 19 '17 09:04 MeriemBo

[{  'name':this.crmStageForm.controls['name'].value,
     'usage':this.crmStageForm.controls['usage'].value,
     'probability':0}]

put the value there

hengkyz avatar Apr 19 '17 09:04 hengkyz

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

MeriemBo avatar Apr 19 '17 09:04 MeriemBo

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

hengkyz avatar Apr 19 '17 09:04 hengkyz

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

MeriemBo avatar Apr 19 '17 10:04 MeriemBo

please close the issue

hengkyz avatar Apr 20 '17 07:04 hengkyz

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 })

        })
}

MeriemBo avatar May 05 '17 11:05 MeriemBo

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

hengkyz avatar May 05 '17 11:05 hengkyz

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

MeriemBo avatar May 05 '17 13:05 MeriemBo

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

hengkyz avatar Nov 14 '17 04:11 hengkyz