Professional Documents
Culture Documents
Answer
Answer
# models.py
from odoo import models, fields
class Job(models.Model):
_name = 'my_module.job'
name = fields.Char('Job Name')
description = fields.Text('Job Description')
# controllers.py
from odoo import http
from odoo.http import request
class JobController(http.Controller):
@http.route('/jobs', type='json', auth='user')
def get_jobs(self):
jobs = request.env['my_module.job'].search([])
return {'jobs': [job.name for job in jobs]}
Frontend (Angular):
// job.service.ts
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class JobService {
constructor(private http: HttpClient) { }
getJobs() {
return this.http.get('/api/jobs');
}
}
// job-list.component.ts
import { Component, OnInit } from '@angular/core';
import { JobService } from './job.service';
@Component({
selector: 'app-job-list',
template: `
<div *ngFor="let job of jobs">
{{ job.name }}
</div>
`,
})
export class JobListComponent implements OnInit {
jobs = [];
ngOnInit() {
this.jobService.getJobs().subscribe(jobs => this.jobs = jobs);
}
}
Please note that these are simplified examples and might need to be adjusted based
on your specific needs. For instance, you might need to handle errors, add more
fields to your jobs, or create more complex views.