Skip to content

Commit

Permalink
[IMP] dental: Add controller
Browse files Browse the repository at this point in the history
-Create Controller
-Show the the list of patient
-Redirect medical aid and personal and medical history to the  form view of these
  • Loading branch information
krku-odoo committed Sep 6, 2024
1 parent 0937960 commit 0ba8db8
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 3 deletions.
1 change: 1 addition & 0 deletions dental/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import controller
1 change: 1 addition & 0 deletions dental/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"views/habits.xml",
"views/allergies.xml",
"views/medication.xml",
"views/dental_controller.xml",
"views/patient_history.xml",
"views/menuitem.xml",
],
Expand Down
1 change: 1 addition & 0 deletions dental/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import dental_controller
77 changes: 77 additions & 0 deletions dental/controller/dental_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from odoo import http
from odoo.http import request


class DentalController(http.Controller):

@http.route(
[
"/dental",
],
type="http",
auth="public",
website=True,
)
def show_all_the_data(self, page=1, **kwargs):
user = request.env.user
try:
page = int(page)
except ValueError:
page = 1
print(user.partner_id.id)
patient = request.env["dental.patients"].sudo()
patient_per_page = 6
total_patients = patient.search_count(
[
("guarantor_id", "=", user.partner_id.id),
]
)
total_pages = (total_patients + patient_per_page - 1) // patient_per_page
page = max(1, min(page, total_pages))
offset = (page - 1) * patient_per_page
patients = patient.search(
[
("guarantor_id", "=", user.partner_id.id),
],
limit=patient_per_page,
offset=offset,
)
return request.render(
"dental.dental_patient_view_controller",
{
"patients": patients,
"page": page,
"total_pages": total_pages,
},
)

@http.route(
["/patient/<int:record_id>"],
type="http",
auth="public",
website=True,
)
def show_patient_details(self, record_id, **kwargs):
data = request.env["dental.patients"].sudo().browse(record_id)
return request.render(
"dental.patient_details_view_controller",
{
"patients": data,
},
)

@http.route(
["/dental/history/<int:patient_id>"],
type="http",
auth="public",
website=True,
)
def show_dental_history(self, patient_id, **kwargs):
data = request.env["dental.patients"].sudo().browse(patient_id)
print(patient_id)
return request.render(
"dental.dental_history_view",
{
"patients": data,
},
)
4 changes: 2 additions & 2 deletions dental/models/dental_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PatientModel(models.Model):
_description = "Dental Patients"
_inherit = ["mail.thread", "mail.activity.mixin"]

name = fields.Char()
name = fields.Char(required=True)
state = fields.Selection(
selection=[
("new", "New"),
Expand Down Expand Up @@ -78,7 +78,7 @@ class PatientModel(models.Model):
guarantor_tags = fields.Many2many(string="Tags", related="guarantor_id.category_id")

def action_open_invoice(self):
if self.state == "new":
if self.state == "to invoice":
print("invoice")
for patient_id in self:
self.ensure_one()
Expand Down
1 change: 1 addition & 0 deletions dental/models/medical_aids.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ class MedicalAidsModel(models.Model):
tracking=True,
default="new",
)
pateint_id = fields.One2many("dental.patients", "medical_aid_id")
13 changes: 13 additions & 0 deletions dental/static/icons/Bill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions dental/static/icons/bag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions dental/static/icons/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dental/static/icons/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0ba8db8

Please sign in to comment.