Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1747 Переглядів

I created a custom module and now I want to give a security rule, record rule that any doctor who logged in can see and edit their own Appointments

Profound Regards

javed ahamd


My Code


from odoo import api, fields, models


class HospitalAppointment(models.Model):
_name = "hospital.appointment"
_description = "This model will store data of Hospital appointment data"

# this is for inherit mail chatter
_inherit = ['mail.thread', 'mail.activity.mixin']

# this is Many2one or Select menu
patient_id = fields.Many2one('hospital.patient', string="Patient")
# get related value
gender = fields.Selection(related='patient_id.gender', readonly=True)
# get age of the selected patient
age = fields.Integer(string="Age", tracking=True)
# get current date and time
appointment_time = fields.Datetime(string="Appointment Time", default=fields.Datetime.now)
appointment_date = fields.Date(string="Appointment Date", default=fields.Date.context_today)
# add many2one field
doctor_id = fields.Many2one('res.users', string="Doctor")
# add HTML field in odoo
prescription = fields.Html(string="Prescription")
# add statusbar
state = fields.Selection([
('draft', 'Draft'),
('in_consultation', 'In Consultation'),
('done', 'Done'),
('cancel', 'Cancelled')],
string="Status", )
# add priority
priority = fields.Selection([
('0', 'Normal'),
('1', 'Low'),
('2', 'High'),
('3', 'Very High')],
string="Priority")


@api.onchange('patient_id')
def onchange_patient_id(self):
self.age = self.patient_id.age

class AppointmentPharamacyLines(models.Model):
_name = "appointment.pharmacy.lines"
_description = "Appointment Pharmacy Liens"
product_id = fields.Many2one('hospital.medicine')
sale_price = fields.Float(string="Sale Price")
qty = fields.Integer(string="Quantity")

@api.onchange('product_id')
def _onchange_product_id(self):
self.sale_price = self.product_id.sale_price



from odoo import api, fields, models


class HospitalDoctor(models.Model):
_name = "hospital.doctor"
_description = "This model will store data of Hospital doctors data"

# this is for inherit mail chatter
_inherit = ['mail.thread','mail.activity.mixin']

# these are the doctor table fields
name = fields.Char(string="Doctor Name", size=50, help="Write doctor name here")
father_name = fields.Char(string="Father name")
gender = fields.Selection([('male', 'Male'), ('female', 'Female')], string='Gender', default="male")
age = fields.Char(string="Age")
dob = fields.Date(string="Date of Birth")
qualification = fields.Char(string="Qualification")
status = fields.Selection([('active', 'Active'), ('in-active','In-Active')], default="active")
mobile = fields.Char(string="Mobile No")
email = fields.Char(string="Email")
address = fields.Char(string="Address")
# add priority, it means give star to work
priority = fields.Selection([
('0', 'Normal'),
('1', 'Low'),
('2', 'High'),
('3', 'Very High')], string="Priority",
help='Gives the sequence order when displaying a list of doctor documents.')
# add statusbar
state = fields.Selection([
('draft', 'Draft'),
('in_consultation', 'In Consultation'),
('done', 'Done'),
('cancel', 'Cancelled')],
string="Status",)


Аватар
Відмінити
Найкраща відповідь

Hi,

You can create a record rule for the appointment model for the doctor's user group with the following domain.

[('doctor_id', '=', user.doctor_id)]


Here you may have to link the doctor record to the corresponding user, ie, to identify which user belongs to which doctor.

So you can inherit the res.user model and add a field called: doctor_id, using this field you can link the doctor and user.


Once you done this, write a rule with above domain.


Thanks

Аватар
Відмінити