From e459d24d222839e7e6edce41fc94ad653b4cae22 Mon Sep 17 00:00:00 2001 From: smee-odoo Date: Tue, 10 Sep 2024 16:11:07 +0530 Subject: [PATCH] [IMP] dental: updated the web controller After this commit: -updated the views --- dental/controller/portal.py | 44 ++- dental/models/dental_patients.py | 36 +- dental/models/medical_history.py | 7 +- dental/views/medical_history_views.xml | 111 ++++-- dental/views/portal_template.xml | 515 +++++++++++++++++++------ 5 files changed, 530 insertions(+), 183 deletions(-) diff --git a/dental/controller/portal.py b/dental/controller/portal.py index 867b214177..6ba6870699 100644 --- a/dental/controller/portal.py +++ b/dental/controller/portal.py @@ -1,15 +1,35 @@ from odoo import http from odoo.http import request from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.addons.portal.controllers.portal import pager as portal_pager class DentalPortal(CustomerPortal): - @http.route('/my/dental', type='http', auth='user', website=True) - def portal_my_dental(self, **kw): + @http.route(['/my/dental', '/my/dental/page/'], type='http', auth='user', website=True) + def portal_my_dental(self, page=1, **kw): current = request.env.user.id - users = request.env['dental.patient'].search([('guarantor_id', '=', current)]) + dental_patient = request.env['dental.patient'] + domain = [('guarantor_id', '=', current)] + + items_per_page = 2 + total_users = dental_patient.search_count(domain) + + pager = portal_pager( + url='/my/dental', + total=total_users, + page=int(page), + step=items_per_page, + ) + + users = dental_patient.search( + domain, + limit=items_per_page, + offset=pager['offset'], + ) + return request.render('dental.portal_my_dental', { - 'users': users + 'users': users, + 'pager': pager }) @http.route('/my/dental/', type='http', auth='user', website=True) @@ -35,13 +55,23 @@ def portal_my_dental_medical_history(self, patient_id, **kw): @http.route('/my/dental//medical_aid', type='http', auth='user', website=True) def portal_my_dental_medical_aid(self, patient_id, **kw): - medical_aid = request.env['dental.patient'].search([]).insurance_id + medical_aids = request.env['dental.patient'].browse(patient_id).insurance_id return request.render('dental.portal_my_dental_medical_aid', { - 'medical_aid': medical_aid + 'medical_aids': medical_aids }) @http.route('/my/dental//dental_history', type='http', auth='user', website=True) def portal_my_dental_dental_history(self, patient_id, **kw): - + medical_historys = request.env['medical.history'].search([('patient_id', '=', patient_id)]) return request.render('dental.portal_my_dental_dental_history', { + 'medical_historys': medical_historys + }) + + @http.route('/my/dental//dental_history/', type='http', auth='user', website=True) + def portal_my_dental_medical_history_form(self, patient_id, history_id, **kw): + medical_historys = request.env['medical.history'].search( + [('patient_id', '=', patient_id)]) + medical_history = medical_historys.browse(history_id) + return request.render('dental.portal_teeth_staining', { + 'medical_history': medical_history, }) diff --git a/dental/models/dental_patients.py b/dental/models/dental_patients.py index e8b9f3a97b..8e8ba477be 100644 --- a/dental/models/dental_patients.py +++ b/dental/models/dental_patients.py @@ -1,4 +1,4 @@ -from odoo import models, fields, Command +from odoo import models, fields, Command, api class DentalPatients(models.Model): @@ -79,6 +79,23 @@ class DentalPatients(models.Model): depedent_code = fields.Char(string="Dependent Code") medical_history_ids = fields.One2many('medical.history', 'patient_id', string="Medical History") + @api.onchange("stage") + def _onchange_stage(self): + if self.stage == 'to invoice': + self.guarantor_id = self.env.user.id + move_vals = { + 'partner_id': self.guarantor_id.id, + 'move_type': 'out_invoice', + 'invoice_line_ids': [ + Command.create({ + "name": "consultation fees", + "quantity": 1, + "price_unit": 500 + }) + ] + } + self.env['account.move'].create(move_vals) + def book_invoice_button(self): self.stage = 'to invoice' self.guarantor_id = self.env.user.id @@ -93,19 +110,12 @@ def book_invoice_button(self): }) ] } - self.env['account.move'].check_access_rights('create') - self.env['account.move'].check_access_rule('create') - self.env['account.move'].sudo().create(move_vals) + self.env['account.move'].create(move_vals) def book_appointment_button(self): move_vals = { - 'appointment_duration': 1, - 'appointment_tz': self.env.user.tz, - 'assign_method': 'resource_time', - 'max_schedule_days': 1, - 'min_cancellation_hours': 24, - 'min_schedule_hours': 48, - 'name': 'Appointment', - 'schedule_based_on': 'users', + 'duration': 1, + 'appointment_type_id': self.env.ref('appointment.appointment_type_dental_care').id, + 'name': f"{self.name}-Dentist Appointment" } - self.env['appointment.type'].sudo().create(move_vals) + self.env['calendar.event'].create(move_vals) diff --git a/dental/models/medical_history.py b/dental/models/medical_history.py index a39dcec371..7818ba4010 100644 --- a/dental/models/medical_history.py +++ b/dental/models/medical_history.py @@ -7,7 +7,7 @@ class MedicalHistory(models.Model): _description = "Medical History" _inherit = ["mail.thread", "mail.activity.mixin"] - name = fields.Char(string="Name", compute="_computed_name") + name = fields.Char(string="Name", compute="_computed_name", store=True) patient_id = fields.Many2one('dental.patient', string="Patient", required=True) date = fields.Date(string="Date", default=fields.Date.today()) did_not_attend = fields.Boolean(string="Did not attend", required=True) @@ -50,10 +50,7 @@ class MedicalHistory(models.Model): attachments_removed = fields.Boolean(string="Attachments Removed") aligner_followup_scan = fields.Boolean(string="Aligner Follow-up Scan") - other_notes = fields.Text(string="Other Notes") - - # General notes field at the end - notes = fields.Text(string="Additional Notes") + notes = fields.Text(string="Other Notes") upper_18 = fields.Boolean(string="18 Staining") upper_17 = fields.Boolean(string="17 Staining") diff --git a/dental/views/medical_history_views.xml b/dental/views/medical_history_views.xml index 7d8b7b495b..2f2995203e 100644 --- a/dental/views/medical_history_views.xml +++ b/dental/views/medical_history_views.xml @@ -55,42 +55,86 @@ - + - - - - - - - - - - - - - - - - + +
+
18
+
17
+
16
+
15
+
14
+
13
+
12
+
11
+
28
+
27
+
26
+
25
+
24
+
23
+
22
+
21
+
+
+
+ + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + +
+
48
+
47
+
46
+
45
+
44
+
43
+
42
+
41
+
38
+
37
+
36
+
35
+
34
+
33
+
32
+
31
+
+
+
+ + + + + + + + + + + + + + + + +
@@ -107,7 +151,6 @@ -
diff --git a/dental/views/portal_template.xml b/dental/views/portal_template.xml index 1620a31c7a..6e03fee2c8 100644 --- a/dental/views/portal_template.xml +++ b/dental/views/portal_template.xml @@ -18,24 +18,31 @@ Dental
-

Dental

+

Dental

-