feat: institutional + support + training admin sections (backend + frontend)

Ship three fully-wired admin areas end-to-end with APIs, seeds, tests and docs.

Backend (new `encoach_lms_api` addon + existing addons):
- Institutional: academic years/terms, departments, admission registers & admissions,
  courses/batches, lessons, fees (terms + student fees + invoicing with income-account
  auto-wiring), gradebook (assignments/grades), library, facilities (encoach.asset),
  student leave, result templates + marksheets (incl. delete-with-cascade).
- Support: `encoach.ticket` model + CRUD/assignee routes; payment records derived
  from `op.student.fees.details` and `account.move`; platform settings backed by
  `encoach.code` and `ir.config_parameter` (packages + grading config).
- Training: `encoach.vocab.item` + `encoach.grammar.rule` (plus progress models)
  with CRUD, pagination, search/level filters, and upsert-style progress endpoints.
  Odoo 19 compatibility: `_sql_constraints` replaced with `@api.constrains`;
  `ValidationError`/`UserError` mapped to HTTP 400.

Frontend:
- Rewire institutional admin pages (Academic Year Manager, Admissions, Courses,
  Lessons, Fees, Gradebook, Library, Facilities, Student Leave, Marksheets,
  Taxonomy, Resources) to real APIs with React Query invalidation and dialogs.
- New typed services: `payments.service.ts`, `platformSettings.service.ts`,
  `training.service.ts`. Updated `fees/gradebook/lms/courseware/taxonomy/
  resources/student-progress/generation` services + related types.
- Rewrite `VocabularyPage`, `GrammarPage`, `PaymentRecordPage`, `SettingsPage`,
  `TicketsPage` to consume live data with search/filter/progress/CRUD flows.
- New shared components: `TaxonomyCascade`, `MaterialViewer`, `teacher/TeacherLibrary`.
- Favicons/branding assets and misc. UX polish across teacher/student pages.

Tooling & QA:
- Seeders: `seed_demo.py`, `seed_demo_data.py`, `seed_institutional.py` (idempotent,
  covers institutional + support + training fixtures incl. income-account wiring).
- API write-flow test suites: `test_write_flows.py` (institutional),
  `test_support_flows.py` (support), `test_training_flows.py` (training),
  `test_ai_full.py`. All suites pass end-to-end.
- Docs: add `docs/PROJECT_SUMMARY.md` with per-section scope, artifacts and QA.
- `.gitignore`: ignore `pgdata_bak_*/`, `frontend/.vite/`, `frontend/dist/`,
  `frontend/node_modules/`.

Made-with: Cursor
This commit is contained in:
Yamen Ahmad
2026-04-19 03:13:23 +04:00
parent 74d83af57f
commit 6ec68160c8
59 changed files with 9076 additions and 143 deletions

View File

@@ -0,0 +1,176 @@
import logging
from odoo import http
from odoo.http import request
from odoo.addons.encoach_api.controllers.base import (
jwt_required, _json_response, _error_response, _get_json_body,
)
_logger = logging.getLogger(__name__)
def _ser_ticket(t):
return {
'id': t.id,
'subject': t.subject or '',
'description': t.description or '',
'type': t.type or 'support',
'status': t.status or 'open',
'source': t.source or 'platform',
'page_context': t.page_context or '',
'reporter_id': t.reporter_id.id if t.reporter_id else None,
'reporter_name': t.reporter_id.name if t.reporter_id else '',
'assignee_id': t.assignee_id.id if t.assignee_id else None,
'assignee_name': t.assignee_id.name if t.assignee_id else '',
'entity_id': t.entity_id.id if t.entity_id else None,
'entity_name': t.entity_id.name if t.entity_id else '',
'created_at': t.create_date.isoformat() if t.create_date else '',
'resolved_at': t.resolved_at.isoformat() if t.resolved_at else '',
}
class TicketsController(http.Controller):
@http.route('/api/tickets', type='http', auth='public', methods=['GET'], csrf=False)
@jwt_required
def list_tickets(self, **kw):
try:
Ticket = request.env['encoach.ticket'].sudo()
domain = []
status = kw.get('status')
if status and status != 'all':
domain.append(('status', '=', status))
t = kw.get('type')
if t and t != 'all':
domain.append(('type', '=', t))
src = kw.get('source')
if src and src != 'all':
domain.append(('source', '=', src))
assignee = kw.get('assignee_id')
if assignee:
try:
domain.append(('assignee_id', '=', int(assignee)))
except (TypeError, ValueError):
pass
search = kw.get('search') or kw.get('q')
if search:
domain.append('|')
domain.append(('subject', 'ilike', search))
domain.append(('description', 'ilike', search))
try:
size = min(int(kw.get('size') or 50), 200)
except (TypeError, ValueError):
size = 50
try:
page = max(int(kw.get('page') or 1), 1)
except (TypeError, ValueError):
page = 1
total = Ticket.search_count(domain)
recs = Ticket.search(domain, limit=size, offset=(page - 1) * size)
items = [_ser_ticket(t) for t in recs]
return _json_response({
'data': items,
'items': items,
'total': total,
'page': page,
'size': size,
})
except Exception as e:
_logger.exception('list_tickets')
return _error_response(str(e), 500)
@http.route('/api/tickets', type='http', auth='public', methods=['POST'], csrf=False)
@jwt_required
def create_ticket(self, **kw):
try:
body = _get_json_body()
if not body.get('subject'):
return _error_response('subject is required', 400)
vals = {
'subject': body['subject'],
'description': body.get('description') or '',
'type': body.get('type') or 'support',
'status': body.get('status') or 'open',
'source': body.get('source') or 'platform',
'page_context': body.get('page_context') or '',
}
if body.get('assignee_id'):
vals['assignee_id'] = int(body['assignee_id'])
if body.get('entity_id'):
vals['entity_id'] = int(body['entity_id'])
# reporter defaults to current user via the model default.
rec = request.env['encoach.ticket'].sudo().create(vals)
return _json_response(_ser_ticket(rec))
except Exception as e:
_logger.exception('create_ticket')
return _error_response(str(e), 500)
@http.route('/api/tickets/<int:tid>', type='http', auth='public',
methods=['GET'], csrf=False)
@jwt_required
def get_ticket(self, tid, **kw):
try:
rec = request.env['encoach.ticket'].sudo().browse(tid)
if not rec.exists():
return _error_response('Not found', 404)
return _json_response(_ser_ticket(rec))
except Exception as e:
_logger.exception('get_ticket')
return _error_response(str(e), 500)
@http.route('/api/tickets/<int:tid>', type='http', auth='public',
methods=['PATCH', 'PUT'], csrf=False)
@jwt_required
def update_ticket(self, tid, **kw):
try:
from odoo import fields as odoo_fields
body = _get_json_body()
rec = request.env['encoach.ticket'].sudo().browse(tid)
if not rec.exists():
return _error_response('Not found', 404)
vals = {}
for k in ('subject', 'description', 'type', 'status', 'source', 'page_context'):
if k in body:
vals[k] = body[k]
if 'assignee_id' in body:
vals['assignee_id'] = int(body['assignee_id']) if body['assignee_id'] else False
if 'entity_id' in body:
vals['entity_id'] = int(body['entity_id']) if body['entity_id'] else False
# Auto-stamp resolved_at when transitioning to resolved/closed.
if vals.get('status') in ('resolved', 'closed') and not rec.resolved_at:
vals['resolved_at'] = odoo_fields.Datetime.now()
if vals:
rec.write(vals)
return _json_response(_ser_ticket(rec))
except Exception as e:
_logger.exception('update_ticket')
return _error_response(str(e), 500)
@http.route('/api/tickets/<int:tid>', type='http', auth='public',
methods=['DELETE'], csrf=False)
@jwt_required
def delete_ticket(self, tid, **kw):
try:
rec = request.env['encoach.ticket'].sudo().browse(tid)
if rec.exists():
rec.unlink()
return _json_response({'success': True})
except Exception as e:
_logger.exception('delete_ticket')
return _error_response(str(e), 500)
@http.route('/api/tickets/assignedToUser', type='http', auth='public',
methods=['GET'], csrf=False)
@jwt_required
def assigned_to_user(self, **kw):
try:
uid = request.env.user.id
recs = request.env['encoach.ticket'].sudo().search([
('assignee_id', '=', uid),
], limit=100)
items = [_ser_ticket(t) for t in recs]
return _json_response({'data': items, 'items': items, 'total': len(items)})
except Exception as e:
_logger.exception('assigned_to_user')
return _error_response(str(e), 500)