-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anhndapec
committed
Jan 2, 2025
1 parent
b79cc0b
commit 5607458
Showing
4 changed files
with
125 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,86 @@ | ||
{% extends "layouts/base-fullscreen.html" %} | ||
|
||
{% block title %} Register {% endblock %} | ||
{% block title %} Create Task {% endblock %} | ||
|
||
<!-- Specific Page CSS goes HERE --> | ||
{% block stylesheets %}{% endblock stylesheets %} | ||
|
||
{% block content %} | ||
|
||
<div class="content"> | ||
<div class="container"> | ||
<div class="row pt-5"> | ||
<div class="col-md-6 mt-5 offset-md-3 pt-5 mt-5"> | ||
<div class="card"> | ||
<div class="card-header text-center py-4"> | ||
<h4 class="title"> | ||
Sign UP home - templdates - hrms -templdate | ||
Create Task | ||
</h4> | ||
</div> | ||
<div class="card-body px-5 py-3"> | ||
<form> | ||
<div class="row"> | ||
<div class="col-md-12 px-md-1"> | ||
<div class="form-group"> | ||
<label>Username</label> | ||
<input type="text" class="form-control" placeholder="Username" | ||
value="michael23"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-12 px-md-1"> | ||
<div class="form-group"> | ||
<label>Email</label> | ||
<input type="email" class="form-control" placeholder="email" | ||
value="[email protected]"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-12 px-md-1"> | ||
<div class="form-group"> | ||
<label>Password</label> | ||
<input type="password" class="form-control" placeholder="password" | ||
value="[email protected]"> | ||
</div> | ||
</div> | ||
<form id="taskForm"> | ||
<div class="form-group"> | ||
<label for="name">Name</label> | ||
<input type="text" class="form-control" id="name" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="project">Project</label> | ||
<select class="form-control" id="project"> | ||
{% for project in projects %} | ||
<option value="{{ project.id }}">{{ project.name }}</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label for="stage">Stage</label> | ||
<input type="text" class="form-control" id="stage" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="start_date">Start Date</label> | ||
<input type="datetime-local" class="form-control" id="start_date" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="deadline">Deadline</label> | ||
<input type="datetime-local" class="form-control" id="deadline" required> | ||
</div> | ||
<div class="text-center"> | ||
<button type="button" class="btn btn-fill btn-primary" onclick="createTask()">Create Task</button> | ||
</div> | ||
|
||
</form> | ||
</div> | ||
<div class="card-footer text-center"> | ||
<button type="submit" class="btn btn-fill btn-primary">Register</button> | ||
|
||
<br /><br /> | ||
|
||
<p> | ||
Have an account? <a href="/login.html" class="text-primary">Login</a> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
{% endblock content %} | ||
|
||
<!-- Specific Page JS goes HERE --> | ||
{% block javascripts %}{% endblock javascripts %} | ||
{% block javascripts %} | ||
<script> | ||
function createTask() { | ||
const form = document.getElementById('taskForm'); | ||
const formData = { | ||
name: form.name.value, | ||
project_id: form.project.value, | ||
stage: form.stage.value, | ||
start_date: form.start_date.value, | ||
deadline: form.deadline.value | ||
}; | ||
|
||
fetch('{% url "hrms:api_create_task" %}', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-CSRFToken': '{{ csrf_token }}' | ||
}, | ||
body: JSON.stringify(formData) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
alert(`Task Created Successfully! Task ID: ${data.task_id}`); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
alert('Failed to create task.'); | ||
}); | ||
} | ||
</script> | ||
{% endblock javascripts %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django import forms | ||
|
||
|
||
class TaskForm(forms.Form): | ||
name = forms.CharField(label="Name", max_length=100) | ||
project = forms.ChoiceField( | ||
label="Project", choices=[] | ||
) # Sẽ được cập nhật trong view | ||
stage = forms.CharField(label="Stage", max_length=100) | ||
start_date = forms.DateTimeField(label="Start Date") | ||
deadline = forms.DateTimeField(label="Deadline") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from django.urls import re_path | ||
from .views import TaskCreateView | ||
from django.urls import path | ||
from .views import TaskCreateView, TaskCreateAPIView | ||
|
||
app_name = 'hrms' | ||
|
||
|
||
urlpatterns = [ | ||
re_path('task/create', TaskCreateView.as_view(), name='task_create'), | ||
path('task/create', TaskCreateView.as_view(), name='create_task'), | ||
path('api/create_task/', TaskCreateAPIView.as_view(), name='api_create_task'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
from django.views import View | ||
from django.shortcuts import render | ||
from django.http import JsonResponse | ||
from django.views import View | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.utils.decorators import method_decorator | ||
import xmlrpc.client | ||
import json | ||
|
||
ODOO_URL = "http://odoo17:8069" | ||
ODOO_DB = "odoo" | ||
ODOO_USERNAME = "admin" | ||
ODOO_PASSWORD = "admin" | ||
|
||
|
||
def get_projects_from_odoo(): | ||
url = ODOO_URL | ||
db = ODOO_DB | ||
username = ODOO_USERNAME | ||
password = ODOO_PASSWORD | ||
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) | ||
uid = common.authenticate(db, username, password, {}) | ||
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) | ||
projects = models.execute_kw(db, uid, password, 'project.project', 'search_read', [[], ['id', 'name']]) | ||
return projects | ||
|
||
|
||
class TaskCreateView(View): | ||
def get(self, request): | ||
return render(request, 'hrms/task_create.html') | ||
projects = get_projects_from_odoo() | ||
return render(request, 'hrms/task_create.html', {'projects': projects}) | ||
|
||
|
||
@method_decorator(csrf_exempt, name='dispatch') | ||
class TaskCreateAPIView(View): | ||
def post(self, request, *args, **kwargs): | ||
data = json.loads(request.body) | ||
url = ODOO_URL | ||
db = ODOO_DB | ||
username = ODOO_USERNAME | ||
password = ODOO_PASSWORD | ||
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) | ||
uid = common.authenticate(db, username, password, {}) | ||
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) | ||
|
||
task_id = models.execute_kw(db, uid, password, 'project.task', 'create', [{ | ||
'name': data['name'], | ||
'project_id': data['project_id'], | ||
'stage_id': data['stage'], | ||
'date_start': data['start_date'], | ||
'date_deadline': data['deadline'], | ||
}]) | ||
|
||
return JsonResponse({'task_id': task_id}) |