Skip to content

Commit

Permalink
[IMP] dental: updated web controller
Browse files Browse the repository at this point in the history
After this commit:
-added patient creation form
  • Loading branch information
smee-odoo committed Sep 16, 2024
1 parent 64b32ec commit f04efc0
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 178 deletions.
2 changes: 2 additions & 0 deletions dental/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
'data': [
'security/ir.model.access.csv',

'data/data.xml',
'data/dental_data.xml',
'data/dental_tags.xml',

'views/dental_stage_views.xml',
'views/portal_template.xml',
'views/tag_views.xml',
'views/medical_history_views.xml',
Expand Down
22 changes: 22 additions & 0 deletions dental/controller/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,25 @@ def portal_my_dental_medical_history_form(self, patient_id, history_id, **kw):
return request.render('dental.portal_teeth_staining', {
'medical_history': medical_history,
})

@http.route('/dentalappointment', type='http', auth='user', website=True)
def portal_dental_appointment(self, **kw):
return request.render('dental.create_patient_form', {})

@http.route('/createpatient', type='http', auth='user', website=True)
def portal_create_patient(self, **kw):
vals = {
'name': kw.get("name"),
'birthdate': kw.get("birthdate"),
'stage_id': 1
}
new_patient = request.env['dental.patient'].sudo().create(vals)
return request.render('dental.create_patient_details_form', {
'patient_id': new_patient.id
})

@http.route('/createpatient/<int:patient_id>', type='http', auth='user', website=True)
def portal_dental_appointment_details(self, patient_id, **kw):
patient = request.env['dental.patient'].browse(patient_id)
patient.sudo().write(kw)
return request.render('dental.patient_created', {})
11 changes: 11 additions & 0 deletions dental/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<odoo>

<record id="menu_dental" model="website.menu">
<field name="name">Dental Appointment</field>
<field name="url">/dentalappointment</field>
<field name="parent_id" ref="website.main_menu" />
<field name="sequence" type="int">100</field>
</record>

</odoo>
20 changes: 20 additions & 0 deletions dental/data/dental_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@
<record model="dental.medication" id="medication_type4">
<field name="name">Pilocarpine</field>
</record>

<!-- Stage DATA -->

<record model="dental.stage" id="dental_stage_type1">
<field name="name">New</field>
<field name="sequence">1</field>
</record>
<record model="dental.stage" id="dental_stage_type2">
<field name="name">To Do Today</field>
<field name="sequence">2</field>
</record>
<record model="dental.stage" id="dental_stage_type3">
<field name="name">Done</field>
<field name="sequence">3</field>
</record>
<record model="dental.stage" id="dental_stage_type4">
<field name="name">To Invoice</field>
<field name="sequence">4</field>
</record>

</odoo>
2 changes: 1 addition & 1 deletion dental/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from . import medication
from . import medical_history
from . import dental_tags
# from . import account_move
from . import dental_stage
15 changes: 6 additions & 9 deletions dental/models/dental_patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ class DentalPatients(models.Model):
_inherit = ["mail.thread", "mail.activity.mixin"]

name = fields.Char(string='Name', required=True)
stage = fields.Selection(
string='Stage',
selection=[('new', 'New'), ('to do today', 'To Do Today'), ('done', 'Done'), ('to invoice', 'To Invoice')],
help='stage of the appointment',
required=True,
default='new')

stage_id = fields.Many2one('dental.stage', string="Stage")

doctor_id = fields.Many2one(
'res.partner',
string="GP's Name",
Expand Down Expand Up @@ -79,9 +76,9 @@ 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")
@api.onchange("stage_id")
def _onchange_stage(self):
if self.stage == 'to invoice':
if self.stage_id.name == 'To Invoice':
self.guarantor_id = self.env.user.id
move_vals = {
'partner_id': self.guarantor_id.id,
Expand All @@ -97,7 +94,7 @@ def _onchange_stage(self):
self.env['account.move'].create(move_vals)

def book_invoice_button(self):
self.stage = 'to invoice'
self.stage_id.name = 'To Invoice'
self.guarantor_id = self.env.user.id
move_vals = {
'partner_id': self.guarantor_id.id,
Expand Down
10 changes: 10 additions & 0 deletions dental/models/dental_stage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class DentalStage(models.Model):

_name = "dental.stage"
_description = "dental stages"

name = fields.Char(string="Name", required=True)
sequence = fields.Integer(default=1, string="Sequence")
3 changes: 2 additions & 1 deletion dental/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dental.access_dental_allergies,access_dental_allergies,dental.model_dental_aller
dental.access_habits_substance,access_habits_substance,dental.model_habits_substance,base.group_user,1,1,1,1
dental.access_dental_medication,access_dental_medication,dental.model_dental_medication,base.group_user,1,1,1,1
dental.access_medical_history,access_medical_history,dental.model_medical_history,base.group_user,1,1,1,1
dental.access_dental_tags,access_dental_tags,dental.model_dental_tags,base.group_user,1,1,1,1
dental.access_dental_tags,access_dental_tags,dental.model_dental_tags,base.group_user,1,1,1,1
dental.access_dental_stage,access_dental_stage,dental.model_dental_stage,base.group_user,1,1,1,1
6 changes: 5 additions & 1 deletion dental/views/dental_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@

<menuitem id="dental_fourth_menu" name="Medication" parent="dental_menu_root" action="dental_medication_menu_action" />

<menuitem id="dental_fifth_menu" name="Configuration" parent="dental_menu_root" action="action_dental_tags"/>
<menuitem id="dental_fifth_menu" name="Configuration" parent="dental_menu_root" />

<menuitem id="dental_seventh_menu" name="Dental Tags" parent="dental_fifth_menu" action="action_dental_tags"/>

<menuitem id="dental_sixth_menu" parent="dental_fifth_menu" name="Stages" action="dental_stage_action"/>
</odoo>
55 changes: 55 additions & 0 deletions dental/views/dental_stage_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="dental_stage_search" model="ir.ui.view">
<field name="name">Stage - Search</field>
<field name="model">dental.stage</field>
<field name="arch" type="xml">
<search string="Stage Search">
<field name="name"/>
<field name="sequence"/>
</search>
</field>
</record>

<record id="dental_stage_tree" model="ir.ui.view">
<field name="name">dental.stage.tree</field>
<field name="model">dental.stage</field>
<field name="arch" type="xml">
<tree string="Stages" multi_edit="1">
<field name="sequence" widget="handle"/>
<field name="name" readonly="1"/>
</tree>
</field>
</record>

<record id="dental_stage_form" model="ir.ui.view">
<field name="name">dental.stage.form</field>
<field name="model">dental.stage</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<form string="Stage">
<sheet>
<div class="oe_title">
<label for="name"/>
<h1>
<field name="name" />
</h1>
</div>
</sheet>
</form>
</field>
</record>

<record id="dental_stage_action" model="ir.actions.act_window">
<field name="name">Stages</field>
<field name="res_model">dental.stage</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Set a new stage in your opportunity pipeline
</p>
</field>
</record>

</odoo>
14 changes: 4 additions & 10 deletions dental/views/dental_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<field name="name">dental.patient.kanban</field>
<field name="model">dental.patient</field>
<field name="arch" type="xml">
<kanban default_group_by="stage" sortable="True">
<field name="stage" invisible="1" />
<kanban default_group_by="stage_id" sortable="True" quick_create="False">
<field name="stage_id" invisible="1" />
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
Expand All @@ -43,12 +43,6 @@
</div>
</t>
</templates>
<quick_create name="stage" />
<column name="stage" options="{'sortable': True, 'foldable': True}">
<header>
<field name="name" />
</header>
</column>
</kanban>
</field>
</record>
Expand All @@ -59,9 +53,9 @@
<field name="arch" type="xml">
<form>
<header>
<button name="book_invoice_button" type="object" string="Invoice" invisible="stage == 'to invoice'"/>
<button name="book_invoice_button" type="object" string="Invoice" invisible="stage_id.name == 'To Invoice'"/>
<button name="book_appointment_button" type="object" string="Book Appointment" />
<field name="stage" widget="statusbar" options="{'clickable': '1'}" />
<field name="stage_id" widget="statusbar" options="{'clickable': '1'}" />
</header>
<sheet>
<group>
Expand Down
Loading

0 comments on commit f04efc0

Please sign in to comment.