odoo_18_Education_management/models/school_misc_menus.py

189 lines
8.1 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import ValidationError
class SchoolNotice(models.Model):
_name = 'school.notice.board'
_description = 'School Notice Board'
title = fields.Char("Title", required=True)
start_date = fields.Date("Start Date", required=True)
end_date = fields.Date("End Date")
description = fields.Text("Description")
school_id = fields.Many2one('res.company', string="School", default=lambda self: self.env.company)
visible_to = fields.Selection([
('all', 'All'),
('students', 'Students'),
('teachers', 'Teachers')
], string="Visible To", default='all', required=True)
class SchoolReportDummy(models.Model):
_name = 'school.reporting.dummy'
_description = 'Reporting Dummy'
name = fields.Char("Report Name")
date_generated = fields.Date("Generated On", default=fields.Date.today)
class SchoolFeesReport(models.Model):
_name = 'school.fees.report'
_description = 'Fees Report'
name = fields.Char("Report Name")
amount = fields.Float("Amount")
class TranscriptReport(models.Model):
_name = 'school.transcript.report'
_description = 'Transcript Report'
name = fields.Char(string="Report Name", default="Transcript Report", readonly=True)
session = fields.Selection([
('2023-24', '2023-24'),
('2024-25', '2024-25'),
('2025-26', '2025-26'),
('2026-27', '2026-27'),
], string="Session", required=True)
student_id = fields.Many2one('school.application', string="Student", required=True)
# Student Information Fields (computed from student_id)
student_name = fields.Char(related='student_id.name', string="Student Name", readonly=True)
student_address = fields.Text(related='student_id.address', string="Address", readonly=True)
student_phone = fields.Char(related='student_id.phone_no', string="Phone", readonly=True)
student_email = fields.Char(related='student_id.email', string="Email", readonly=True)
student_dob = fields.Date(related='student_id.date_of_birth', string="Date of Birth", readonly=True)
student_guardian = fields.Char(related='student_id.father_name', string="Guardian", readonly=True)
student_academic_year = fields.Char(related='student_id.academic_year', string="Academic Year", readonly=True)
student_class = fields.Selection(related='student_id.class_name', string="Class", readonly=True)
# School Information Fields
school_id = fields.Many2one('res.company', string="School", default=lambda self: self.env.company, readonly=True)
school_name = fields.Char(related='school_id.name', string="School Name", readonly=True)
school_address = fields.Text(string="School Address", compute='_compute_school_address', readonly=True)
school_state = fields.Char(related='school_id.state_id.name', string="State", readonly=True)
school_phone = fields.Char(related='school_id.phone', string="School Phone", readonly=True)
school_email = fields.Char(related='school_id.email', string="School Email", readonly=True)
school_academic_year = fields.Char(string="School Academic Year", default="2024-25", readonly=True)
school_classes = fields.Char(string="Classes", default="Class 1-12", readonly=True)
# Subject Information
subject_ids = fields.Many2many('school.subject', string="Subjects", compute='_compute_subjects', readonly=True)
subject_names = fields.Char(string="Subject Names", compute='_compute_subject_names', readonly=True)
# Report Status
report_generated = fields.Boolean(string="Report Generated", default=False)
generated_date = fields.Datetime(string="Generated Date")
@api.depends('school_id')
def _compute_school_address(self):
for record in self:
if record.school_id:
address_parts = []
if record.school_id.street:
address_parts.append(record.school_id.street)
if record.school_id.street2:
address_parts.append(record.school_id.street2)
if record.school_id.city:
address_parts.append(record.school_id.city)
if record.school_id.zip:
address_parts.append(record.school_id.zip)
record.school_address = ', '.join(address_parts)
else:
record.school_address = ''
@api.depends('student_id')
def _compute_subjects(self):
for record in self:
if record.student_id and record.student_id.class_name:
# Get subjects for the student's class
subjects = self.env['school.subject'].search([
('class_name', '=', 'Class ' + record.student_id.class_name)
])
record.subject_ids = subjects
else:
record.subject_ids = False
@api.depends('subject_ids')
def _compute_subject_names(self):
for record in self:
if record.subject_ids:
subject_names = []
for subject in record.subject_ids:
# Get the display name for the subject
subject_display = dict(subject._fields['name'].selection).get(subject.name, subject.name)
subject_names.append(subject_display)
record.subject_names = ', '.join(subject_names)
else:
record.subject_names = ''
def action_fetch_report(self):
"""Fetch and prepare the report data"""
self.ensure_one()
if not self.student_id:
raise ValidationError("Please select a student first.")
if not self.session:
raise ValidationError("Please select a session first.")
# Mark report as generated
self.report_generated = True
self.generated_date = fields.Datetime.now()
# You can add more logic here to fetch additional data
# For example: get grades, attendance, etc.
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'success',
'message': 'Report data fetched successfully!',
'next': {'type': 'ir.actions.act_window_close'},
}
}
def action_download_report(self):
"""Download the transcript report"""
self.ensure_one()
if not self.report_generated:
raise ValidationError("Please fetch the report first before downloading.")
# Here you would typically call a report action
# For now, we'll show a notification
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'success',
'message': 'Report download functionality will be implemented with PDF generation.',
'sticky': False,
}
}
@api.model
def create(self, vals):
# Auto-generate report name with session and student info
if 'student_id' in vals and 'session' in vals:
student = self.env['school.application'].browse(vals['student_id'])
vals['name'] = f"Transcript Report - {student.name} - {vals['session']}"
return super().create(vals)
class SchoolScholarshipReport(models.Model):
_name = 'school.scholarship.report'
_description = 'Scholarship Report'
student_id = fields.Many2one('school.application', string="Student", ondelete='set null')
scholarship_name = fields.Char("Scholarship Name")
awarded_amount = fields.Float("Awarded Amount")
class SchoolReportCard(models.Model):
_name = 'school.report.card'
_description = 'Report Card'
student_id = fields.Many2one('school.application', string="Student", ondelete='set null')
subject_id = fields.Many2one('school.subject', string="Subject Name", required=True)
score = fields.Float("Score")
class SchoolConfigSettings(models.Model):
_name = 'school.config.settings'
_description = 'School Configuration Settings'
key = fields.Char("Setting Key", required=True)
value = fields.Char("Setting Value")