school.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. # Copyright (C) 2011-Today Serpent Consulting Services PVT. LTD.
  7. # (<http://www.serpentcs.com>)
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields, api
  23. import time
  24. import openerp
  25. from datetime import date
  26. from datetime import datetime
  27. from openerp.tools.translate import _
  28. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, image_colorize
  29. from openerp.tools import image_resize_image_big
  30. from openerp.exceptions import except_orm, Warning as UserError
  31. class AcademicYear(models.Model):
  32. ''' Defining an academic year '''
  33. _name = "academic.year"
  34. _description = "Academic Year"
  35. _order = "sequence"
  36. sequence = fields.Integer('Sequence', required=True,
  37. help="In which sequence order you want to \
  38. see this year.")
  39. name = fields.Char('Name', required=True, select=1,
  40. help='Name of academic year')
  41. code = fields.Char('Code', required=True, select=1,
  42. help='Code of academic year')
  43. date_start = fields.Date('Start Date', required=True,
  44. help='Starting date of academic year')
  45. date_stop = fields.Date('End Date', required=True,
  46. help='Ending of academic year')
  47. month_ids = fields.One2many('academic.month', 'year_id', string='Months',
  48. help="related Academic months")
  49. grade_id = fields.Many2one('grade.master', "Grade")
  50. description = fields.Text('Description')
  51. @api.model
  52. def next_year(self, sequence):
  53. year_ids = self.search([('sequence', '>', sequence)], order='id ASC',
  54. limit=1)
  55. if year_ids:
  56. return year_ids.id
  57. return False
  58. @api.multi
  59. def name_get(self):
  60. res = []
  61. for acd_year_rec in self:
  62. name = "[" + acd_year_rec['code'] + "]" + acd_year_rec['name']
  63. res.append((acd_year_rec['id'], name))
  64. return res
  65. @api.constrains('date_start', 'date_stop')
  66. def _check_academic_year(self):
  67. obj_academic_ids = self.search([])
  68. academic_list = []
  69. for rec_academic in obj_academic_ids:
  70. academic_list.append(rec_academic.id)
  71. for current_academic_yr in self:
  72. academic_list.remove(current_academic_yr.id)
  73. data_academic_yr = self.browse(academic_list)
  74. for old_ac in data_academic_yr:
  75. if old_ac.date_start <= self.date_start <= old_ac.date_stop \
  76. or old_ac.date_start <= self.date_stop <= old_ac.date_stop:
  77. raise UserError(_('Error! You cannot define \
  78. overlapping academic years.'))
  79. @api.constrains('date_start', 'date_stop')
  80. def _check_duration(self):
  81. if self.date_stop and self.date_start:
  82. if self.date_stop < self.date_start:
  83. raise UserError(_('Error! The duration of the academic \
  84. year is invalid.'))
  85. class AcademicMonth(models.Model):
  86. ''' Defining a month of an academic year '''
  87. _name = "academic.month"
  88. _description = "Academic Month"
  89. _order = "date_start"
  90. name = fields.Char('Name', required=True, help='Name of Academic month')
  91. code = fields.Char('Code', required=True, help='Code of Academic month')
  92. date_start = fields.Date('Start of Period', required=True,
  93. help='Starting of Academic month')
  94. date_stop = fields.Date('End of Period', required=True,
  95. help='Ending of Academic month')
  96. year_id = fields.Many2one('academic.year', 'Academic Year', required=True,
  97. help="Related Academic year ")
  98. description = fields.Text('Description')
  99. @api.constrains('date_start', 'date_stop')
  100. def _check_duration(self):
  101. if self.date_stop and self.date_start and \
  102. self.date_stop < self.date_start:
  103. raise UserError(_('Error ! The duration of the\
  104. Month(s) is/are invalid.'))
  105. @api.constrains('year_id', 'date_start', 'date_stop')
  106. def _check_year_limit(self):
  107. if self.year_id and self.date_start and self.date_stop:
  108. if self.year_id.date_stop < self.date_stop or \
  109. self.year_id.date_stop < self.date_start or \
  110. self.year_id.date_start > self.date_start or \
  111. self.year_id.date_start > self.date_stop:
  112. raise UserError(_('Invalid Months ! Some months overlap or\
  113. the date period is not in the scope of \
  114. the academic year.'))
  115. class StandardMedium(models.Model):
  116. ''' Defining a medium(English, Hindi, Gujarati) related to standard'''
  117. _name = "standard.medium"
  118. _description = "Standard Medium"
  119. _order = "sequence"
  120. sequence = fields.Integer('Sequence', required=True)
  121. name = fields.Char('Name', required=True)
  122. code = fields.Char('Code', required=True)
  123. description = fields.Text('Description')
  124. class StandardDivision(models.Model):
  125. ''' Defining a division(A, B, C) related to standard'''
  126. _name = "standard.division"
  127. _description = "Standard Division"
  128. _order = "sequence"
  129. sequence = fields.Integer('Sequence', required=True)
  130. name = fields.Char('Name', required=True)
  131. code = fields.Char('Code', required=True)
  132. description = fields.Text('Description')
  133. class StandardStandard(models.Model):
  134. ''' Defining Standard Information '''
  135. _name = 'standard.standard'
  136. _description = 'Standard Information'
  137. _order = "sequence"
  138. sequence = fields.Integer('Sequence', required=True)
  139. name = fields.Char('Name', required=True)
  140. code = fields.Char('Code', required=True)
  141. description = fields.Text('Description')
  142. @api.model
  143. def next_standard(self, sequence):
  144. stand_ids = self.search([('sequence', '>', sequence)], order='id ASC',
  145. limit=1)
  146. if stand_ids:
  147. return stand_ids.id
  148. return False
  149. class SchoolStandard(models.Model):
  150. ''' Defining a standard related to school '''
  151. _name = 'school.standard'
  152. _description = 'School Standards'
  153. _rec_name = "school_id"
  154. @api.one
  155. @api.depends('standard_id')
  156. def _compute_student(self):
  157. self.student_ids = False
  158. if self.standard_id:
  159. stud_obj = self.env['student.student']
  160. self.student_ids = stud_obj.search([('standard_id', '=',
  161. self.standard_id.id)])
  162. @api.multi
  163. def import_subject(self):
  164. for im_ob in self:
  165. import_sub_ids = self.search([('standard_id', '=',
  166. int(im_ob.standard_id) - 1)])
  167. val = [last.id for sub in import_sub_ids
  168. for last in sub.subject_ids]
  169. self.write({'subject_ids': [(6, 0, val)]})
  170. return True
  171. school_id = fields.Many2one('school.school', 'School', required=True)
  172. standard_id = fields.Many2one('standard.standard', 'Class', required=True)
  173. division_id = fields.Many2one('standard.division', 'Division',
  174. required=True)
  175. medium_id = fields.Many2one('standard.medium', 'Medium', required=True)
  176. subject_ids = fields.Many2many('subject.subject',
  177. 'subject_standards_rel', 'subject_id',
  178. 'standard_id', 'Subject')
  179. user_id = fields.Many2one('hr.employee', string='Class Teacher')
  180. student_ids = fields.One2many('student.student',
  181. compute='_compute_student',
  182. string='Student In Class')
  183. color = fields.Integer('Color Index')
  184. passing = fields.Integer('No Of ATKT', help="Allowed No of ATKTs")
  185. cmp_id = fields.Many2one('res.company', related='school_id.company_id',
  186. string="Company Name", store=True)
  187. @api.multi
  188. def name_get(self):
  189. res = []
  190. for standard in self:
  191. name = (standard.standard_id.name + "[" +
  192. standard.division_id.name + "]")
  193. res.append((standard.id, name))
  194. return res
  195. class SchoolSchool(models.Model):
  196. ''' Defining School Information '''
  197. _name = 'school.school'
  198. _inherits = {'res.company': 'company_id'}
  199. _description = 'School Information'
  200. _rec_name = "com_name"
  201. @api.model
  202. def _lang_get(self):
  203. languages = self.env['res.lang'].search([])
  204. return [(language.code, language.name) for language in languages]
  205. company_id = fields.Many2one('res.company', 'Company', ondelete="cascade",
  206. required=True)
  207. com_name = fields.Char(related='company_id.name', string="School Name",
  208. store=True)
  209. code = fields.Char('Code', required=True, select=1)
  210. standards = fields.One2many('school.standard', 'school_id',
  211. string='Standards')
  212. lang = fields.Selection(_lang_get, string='Language', help="If the \
  213. selected language is loaded in the system, all documents related to this \
  214. partner will be printed in this language. If not, it will be english.")
  215. class SubjectSubject(models.Model):
  216. '''Defining a subject '''
  217. _name = "subject.subject"
  218. _description = "Subjects"
  219. name = fields.Char('Name', required=True)
  220. code = fields.Char('Code', required=True)
  221. maximum_marks = fields.Integer("Maximum marks")
  222. minimum_marks = fields.Integer("Minimum marks")
  223. weightage = fields.Integer("Weightage")
  224. teacher_ids = fields.Many2many('hr.employee', 'subject_teacher_rel',
  225. 'subject_id', 'teacher_id', 'Teachers')
  226. standard_ids = fields.Many2many('school.standard',
  227. 'subject_standards_rel', 'standard_id',
  228. 'subject_id', 'Standards')
  229. standard_id = fields.Many2one('standard.standard', 'Class')
  230. is_practical = fields.Boolean('Is Practical', help='Check this if \
  231. subject is practical.')
  232. no_exam = fields.Boolean("No Exam", help='Check this if \
  233. subject has no exam.')
  234. elective_id = fields.Many2one('subject.elective')
  235. student_ids = fields.Many2many('student.student',
  236. 'elective_subject_student_rel',
  237. 'subject_id', 'student_id', 'Students')
  238. syllabus_ids = fields.One2many('subject.syllabus', 'subject_id',
  239. string='Syllabus')
  240. class SubjectSyllabus(models.Model):
  241. '''Defining a syllabus'''
  242. _name = "subject.syllabus"
  243. _description = "Syllabus"
  244. _rec_name = "duration"
  245. subject_id = fields.Many2one('subject.subject', 'Subject')
  246. duration = fields.Char("Duration")
  247. topic = fields.Text("Topic")
  248. class SubjectElective(models.Model):
  249. ''' Defining Subject Elective '''
  250. _name = 'subject.elective'
  251. name = fields.Char("Name")
  252. subject_ids = fields.One2many('subject.subject', 'elective_id',
  253. string='Elective Subjects')
  254. class StudentStudent(models.Model):
  255. ''' Defining a student information '''
  256. _name = 'student.student'
  257. _table = "student_student"
  258. _description = 'Student Information'
  259. _inherits = {'res.users': 'user_id'}
  260. @api.one
  261. @api.depends('date_of_birth')
  262. def _calc_age(self):
  263. self.age = 0
  264. if self.date_of_birth:
  265. start = datetime.strptime(self.date_of_birth,
  266. DEFAULT_SERVER_DATE_FORMAT)
  267. end = datetime.strptime(time.strftime(DEFAULT_SERVER_DATE_FORMAT),
  268. DEFAULT_SERVER_DATE_FORMAT)
  269. self.age = ((end - start).days / 365)
  270. @api.model
  271. def create(self, vals):
  272. if vals.get('pid', False):
  273. vals['login'] = vals['pid']
  274. vals['password'] = vals['pid']
  275. else:
  276. raise except_orm(_('Error!'), _('PID not valid, so record will \
  277. not save.'))
  278. result = super(StudentStudent, self).create(vals)
  279. return result
  280. @api.model
  281. def _get_photo(self):
  282. company = self._context.get('default_is_company', False)
  283. return self._get_default_image(company)
  284. @api.model
  285. def _get_default_image(self, is_company, colorize=False):
  286. avatar = openerp.modules.get_module_resource('base',
  287. 'static/src/img',
  288. 'avatar.png')
  289. image = image_colorize(open(avatar).read())
  290. return image_resize_image_big(image.encode('base64'))
  291. user_id = fields.Many2one('res.users', string='User ID',
  292. ondelete="cascade", select=True, required=True)
  293. student_name = fields.Char(related='user_id.name', string='Name',
  294. store=True, readonly=True)
  295. pid = fields.Char('Student ID', required=True, default=lambda obj:
  296. obj.env['ir.sequence'].get('student.student'),
  297. help='Personal IDentification Number')
  298. reg_code = fields.Char('Registration Code', help='Student \
  299. Registration Code')
  300. student_code = fields.Char('Student Code')
  301. contact_phone1 = fields.Char('Phone no.')
  302. contact_mobile1 = fields.Char('Mobile no')
  303. roll_no = fields.Integer('Roll No.', readonly=True)
  304. # If windows system use this filed
  305. # photo = fields.Binary('Photo')
  306. # If ubuntu system use this filed
  307. photo = fields.Binary('Photo', default=_get_photo)
  308. year = fields.Many2one('academic.year', 'Academic Year', required=True,
  309. states={'done': [('readonly', True)]})
  310. cast_id = fields.Many2one('student.cast', 'Religion')
  311. admission_date = fields.Date('Admission Date', default=date.today())
  312. middle = fields.Char('Middle Name', required=True,
  313. states={'done': [('readonly', True)]})
  314. last = fields.Char('Surname', required=True, states={'done': [('readonly',
  315. True)]})
  316. gender = fields.Selection([('male', 'Male'),
  317. ('female', 'Female')], 'Gender',
  318. states={'done': [('readonly', True)]})
  319. date_of_birth = fields.Date('Birthdate', required=True,
  320. states={'done': [('readonly', True)]})
  321. mother_tongue = fields.Many2one('mother.toungue', "Mother Tongue")
  322. age = fields.Integer(compute='_calc_age', string='Age', readonly=True)
  323. maritual_status = fields.Selection([('unmarried', 'Unmarried'),
  324. ('married', 'Married')],
  325. 'Maritual Status',
  326. states={'done': [('readonly',
  327. True)]})
  328. reference_ids = fields.One2many('student.reference', 'reference_id',
  329. string='References',
  330. states={'done': [('readonly', True)]})
  331. previous_school_ids = fields.One2many('student.previous.school',
  332. 'previous_school_id',
  333. string='Previous School Detail',
  334. states={'done': [('readonly',
  335. True)]})
  336. family_con_ids = fields.One2many('student.family.contact',
  337. 'family_contact_id',
  338. string='Family Contact Detail',
  339. states={'done': [('readonly', True)]})
  340. doctor = fields.Char('Doctor Name', states={'done': [('readonly', True)]})
  341. designation = fields.Char('Designation')
  342. doctor_phone = fields.Char('Phone')
  343. blood_group = fields.Char('Blood Group',)
  344. height = fields.Float('Height')
  345. weight = fields.Float('Weight')
  346. eye = fields.Boolean('Eyes')
  347. ear = fields.Boolean('Ears')
  348. nose_throat = fields.Boolean('Nose & Throat')
  349. respiratory = fields.Boolean('Respiratory')
  350. cardiovascular = fields.Boolean('Cardiovascular')
  351. neurological = fields.Boolean('Neurological')
  352. muskoskeletal = fields.Boolean('Musculoskeletal')
  353. dermatological = fields.Boolean('Dermatological')
  354. blood_pressure = fields.Boolean('Blood Pressure')
  355. remark = fields.Text('Remark', states={'done': [('readonly', True)]})
  356. school_id = fields.Many2one('school.school', 'School',
  357. states={'done': [('readonly', True)]})
  358. state = fields.Selection([('draft', 'Draft'),
  359. ('done', 'Done'),
  360. ('terminate', 'Terminate'),
  361. ('alumni', 'Alumni')], 'State',
  362. readonly=True, default='draft')
  363. history_ids = fields.One2many('student.history', 'student_id',
  364. string='History')
  365. certificate_ids = fields.One2many('student.certificate', 'student_id',
  366. string='Certificate')
  367. # 'attendance_ids': fields.one2many('attendance.sheet.line','name',
  368. # 'Attendance History',readonly=True)
  369. # 'exam_results_ids': fields.one2many('exam.result','student_id',
  370. # 'Exam History',readonly=True)
  371. # 'student_attachment_line': fields.one2many('student.attachment',
  372. # 'student_id','Attachment')
  373. student_discipline_line = fields.One2many('student.descipline',
  374. 'student_id',
  375. string='Descipline')
  376. address_ids = fields.One2many('res.partner', 'student_id',
  377. string='Contacts')
  378. document = fields.One2many('student.document', 'doc_id',
  379. string='Documents')
  380. description = fields.One2many('student.description', 'des_id',
  381. string='Description')
  382. student_id = fields.Many2one('student.student', 'name')
  383. # contact_phone = fields.related('student_id','phone',type='char',
  384. # relation='student.student',string='Phone No')
  385. contact_phone = fields.Char(related='student_id.phone', string='Phone No')
  386. # contact_mobile = fields.related('student_id','mobile',type='char',
  387. # relation='student.student',string='Mobile No')
  388. contact_mobile = fields.Char(related='student_id.mobile',
  389. string='Mobile No')
  390. student_id = fields.Many2one('student.student', 'Name')
  391. contact_phone = fields.Char(related='student_id.phone', string='Phone No',
  392. readonly=True)
  393. contact_mobile = fields.Char(related='student_id.mobile',
  394. string='Mobile No', readonly=True)
  395. contact_email = fields.Char(related='student_id.email', string='Email',
  396. readonly=True)
  397. contact_website = fields.Char(related='student_id.website',
  398. string='Website', readonly=True)
  399. award_list = fields.One2many('student.award', 'award_list_id',
  400. string='Award List')
  401. student_status = fields.Selection(related='student_id.state',
  402. string='Status', help="Show the \
  403. Status Of Student", readonly=True)
  404. stu_name = fields.Char(related='user_id.name', string='First Name',
  405. readonly=True)
  406. Acadamic_year = fields.Char(related='year.name', string='Academic Year',
  407. help="Academic Year", readonly=True)
  408. grn_number = fields.Many2one('student.grn', 'GR No.',
  409. help="General reg number")
  410. standard_id = fields.Many2one('standard.standard', 'Class')
  411. division_id = fields.Many2one('standard.division', 'Division')
  412. medium_id = fields.Many2one('standard.medium', 'Medium')
  413. cmp_id = fields.Many2one('res.company', string="Company Name",
  414. related='school_id.company_id', store=True)
  415. _sql_constraints = [('grn_unique', 'unique(grn_number)',
  416. 'GRN Number must be unique!')]
  417. @api.multi
  418. def set_to_draft(self):
  419. self.write({'state': 'draft'})
  420. return True
  421. @api.multi
  422. def set_alumni(self):
  423. self.write({'state': 'alumni'})
  424. return True
  425. @api.multi
  426. def set_terminate(self):
  427. self.write({'state': 'terminate'})
  428. return True
  429. @api.multi
  430. def set_done(self):
  431. self.write({'state': 'done'})
  432. return True
  433. @api.multi
  434. def admission_draft(self):
  435. self.write({'state': 'draft'})
  436. return True
  437. @api.multi
  438. def admission_done(self):
  439. school_stand_obj = self.env['school.standard']
  440. for student_data in self:
  441. if student_data.age <= 5:
  442. raise except_orm(_('Warning'), _('The student is not \
  443. eligible. Age is not \
  444. valid.'))
  445. standard_id = student_data.standard_id.id
  446. school_stand_search_ids = school_stand_obj.search([('standard_id',
  447. '=',
  448. standard_id)])
  449. if not school_stand_search_ids:
  450. raise except_orm(_('Warning'), _('The standard is not \
  451. defined in a school'))
  452. student_search_ids = self.search([('standard_id', '=',
  453. student_data.standard_id.id)])
  454. number = 1
  455. for student in student_search_ids:
  456. student.write({'roll_no': number})
  457. number += 1
  458. reg_code = self.env['ir.sequence'].get('student.registration')
  459. registation_code = (str(student_data.school_id.state_id.name) +
  460. str('/') + str(student_data.school_id.city) +
  461. str('/') + str(student_data.school_id.name) +
  462. str('/') + str(reg_code))
  463. stu_code = self.env['ir.sequence'].get('student.code')
  464. student_code = (str(student_data.school_id.code) + str('/') +
  465. str(student_data.year.code) + str('/') +
  466. str(stu_code))
  467. self.write({'state': 'done',
  468. 'admission_date': time.strftime('%Y-%m-%d'),
  469. 'student_code': student_code,
  470. 'reg_code': registation_code})
  471. return True
  472. class StudentGrn(models.Model):
  473. _name = "student.grn"
  474. _rec_name = "grn_no"
  475. @api.one
  476. def _grn_no(self):
  477. for stud_grn in self:
  478. grn_no1 = " "
  479. grn_no2 = " "
  480. grn_no1 = stud_grn['grn']
  481. if stud_grn['prefix'] == 'static':
  482. grn_no1 = stud_grn['static_prefix'] + stud_grn['grn']
  483. elif stud_grn['prefix'] == 'school':
  484. a = stud_grn.schoolprefix_id.code
  485. grn_no1 = a + stud_grn['grn']
  486. elif stud_grn['prefix'] == 'year':
  487. grn_no1 = time.strftime('%Y') + stud_grn['grn']
  488. elif stud_grn['prefix'] == 'month':
  489. grn_no1 = time.strftime('%m') + stud_grn['grn']
  490. grn_no2 = grn_no1
  491. if stud_grn['postfix'] == 'static':
  492. grn_no2 = grn_no1 + stud_grn['static_postfix']
  493. elif stud_grn['postfix'] == 'school':
  494. b = stud_grn.schoolpostfix_id.code
  495. grn_no2 = grn_no1 + b
  496. elif stud_grn['postfix'] == 'year':
  497. grn_no2 = grn_no1 + time.strftime('%Y')
  498. elif stud_grn['postfix'] == 'month':
  499. grn_no2 = grn_no1 + time.strftime('%m')
  500. self.grn_no = grn_no2
  501. grn = fields.Char('GR no', help='General Reg Number', readonly=True,
  502. default=lambda obj:
  503. obj.env['ir.sequence'].get('student.grn'))
  504. name = fields.Char('GRN Format Name', required=True)
  505. prefix = fields.Selection([('school', 'School Name'),
  506. ('year', 'Year'), ('month', 'Month'),
  507. ('static', 'Static String')], 'Prefix')
  508. schoolprefix_id = fields.Many2one('school.school',
  509. 'School Name for Prefix')
  510. schoolpostfix_id = fields.Many2one('school.school',
  511. 'School Name for Suffix')
  512. postfix = fields.Selection([('school', 'School Name'), ('year', 'Year'),
  513. ('month', 'Month'),
  514. ('static', 'Static String')], 'Suffix')
  515. static_prefix = fields.Char('Static String for Prefix',)
  516. static_postfix = fields.Char('Static String for Suffix')
  517. grn_no = fields.Char(compute='_grn_no', string='Generated GR No')
  518. class MotherTongue(models.Model):
  519. _name = 'mother.toungue'
  520. name = fields.Char("Mother Tongue")
  521. class StudentAward(models.Model):
  522. _name = 'student.award'
  523. award_list_id = fields.Many2one('student.student', 'Student')
  524. name = fields.Char('Award Name')
  525. description = fields.Char('Description')
  526. class AttendanceType(models.Model):
  527. _name = "attendance.type"
  528. _description = "School Type"
  529. name = fields.Char('Name', required=True)
  530. code = fields.Char('Code', required=True)
  531. class StudentDocument(models.Model):
  532. _name = 'student.document'
  533. _rec_name = "doc_type"
  534. doc_id = fields.Many2one('student.student', 'Student')
  535. file_no = fields.Char('File No', readonly="1", default=lambda obj:
  536. obj.env['ir.sequence'].get('student.document'))
  537. submited_date = fields.Date('Submitted Date')
  538. doc_type = fields.Many2one('document.type', 'Document Type',
  539. required=True)
  540. file_name = fields.Char('File Name',)
  541. return_date = fields.Date('Return Date')
  542. new_datas = fields.Binary('Attachments')
  543. class DocumentType(models.Model):
  544. ''' Defining a Document Type(SSC,Leaving)'''
  545. _name = "document.type"
  546. _description = "Document Type"
  547. _rec_name = "doc_type"
  548. _order = "seq_no"
  549. seq_no = fields.Char('Sequence', readonly=True, default=lambda obj:
  550. obj.env['ir.sequence'].get('document.type'))
  551. doc_type = fields.Char('Document Type', required=True)
  552. class StudentDescription(models.Model):
  553. ''' Defining a Student Description'''
  554. _name = 'student.description'
  555. des_id = fields.Many2one('student.student', 'Description')
  556. name = fields.Char('Name')
  557. description = fields.Char('Description')
  558. class StudentDescipline(models.Model):
  559. _name = 'student.descipline'
  560. student_id = fields.Many2one('student.student', 'Student')
  561. teacher_id = fields.Many2one('hr.employee', 'Teacher')
  562. date = fields.Date('Date')
  563. class_id = fields.Many2one('standard.standard', 'Class')
  564. note = fields.Text('Note')
  565. action_taken = fields.Text('Action Taken')
  566. class StudentHistory(models.Model):
  567. _name = "student.history"
  568. student_id = fields.Many2one('student.student', 'Student')
  569. academice_year_id = fields.Many2one('academic.year', 'Academic Year',
  570. required=True)
  571. standard_id = fields.Many2one('school.standard', 'Standard',
  572. required=True)
  573. percentage = fields.Float("Percentage", readonly=True)
  574. result = fields.Char(string='Result', readonly=True, store=True)
  575. class StudentCertificate(models.Model):
  576. _name = "student.certificate"
  577. student_id = fields.Many2one('student.student', 'Student')
  578. description = fields.Char('Description')
  579. certi = fields.Binary('Certificate', required=True)
  580. class HrEmployee(models.Model):
  581. ''' Defining a teacher information '''
  582. _name = 'hr.employee'
  583. _inherit = 'hr.employee'
  584. _description = 'Teacher Information'
  585. @api.one
  586. def _compute_subject(self):
  587. ''' This function will automatically computes the subjects related \
  588. to particular teacher.'''
  589. subject_obj = self.env['subject.subject']
  590. subject_ids = subject_obj.search([('teacher_ids', '=', self.id)])
  591. sub_list = []
  592. for sub_rec in subject_ids:
  593. sub_list.append(sub_rec.id)
  594. self.subject_ids = sub_list
  595. subject_ids = fields.Many2many('subject.subject', 'hr_employee_rel',
  596. compute='_compute_subject',
  597. string='Subjects')
  598. class ResPartner(models.Model):
  599. '''Defining a address information '''
  600. _inherit = 'res.partner'
  601. _description = 'Address Information'
  602. student_id = fields.Many2one('student.student', 'Student')
  603. class StudentReference(models.Model):
  604. ''' Defining a student reference information '''
  605. _name = "student.reference"
  606. _description = "Student Reference"
  607. reference_id = fields.Many2one('student.student', 'Student')
  608. name = fields.Char('First Name', required=True)
  609. middle = fields.Char('Middle Name', required=True)
  610. last = fields.Char('Surname', required=True)
  611. designation = fields.Char('Designation', required=True)
  612. phone = fields.Char('Phone', required=True)
  613. gender = fields.Selection([('male', 'Male'), ('female', 'Female')],
  614. 'Gender')
  615. class StudentPreviousSchool(models.Model):
  616. ''' Defining a student previous school information '''
  617. _name = "student.previous.school"
  618. _description = "Student Previous School"
  619. previous_school_id = fields.Many2one('student.student', 'Student')
  620. name = fields.Char('Name', required=True)
  621. registration_no = fields.Char('Registration No.', required=True)
  622. admission_date = fields.Date('Admission Date')
  623. exit_date = fields.Date('Exit Date')
  624. course_id = fields.Many2one('standard.standard', 'Course', required=True)
  625. add_sub = fields.One2many('academic.subject', 'add_sub_id',
  626. string='Add Subjects')
  627. class AcademicSubject(models.Model):
  628. ''' Defining a student previous school information '''
  629. _name = "academic.subject"
  630. _description = "Student Previous School"
  631. add_sub_id = fields.Many2one('student.previous.school', 'Add Subjects',
  632. invisible=True)
  633. name = fields.Char('Name', required=True)
  634. maximum_marks = fields.Integer("Maximum marks")
  635. minimum_marks = fields.Integer("Minimum marks")
  636. class StudentFamilyContact(models.Model):
  637. ''' Defining a student emergency contact information '''
  638. _name = "student.family.contact"
  639. _description = "Student Family Contact"
  640. family_contact_id = fields.Many2one('student.student', string='Student')
  641. rel_name = fields.Selection([('exist', 'Link to Existing Student'),
  642. ('new', 'Create New Relative Name')],
  643. 'Related Student', help="Select Name",
  644. required=True)
  645. user_id = fields.Many2one('res.users', string='User ID',
  646. ondelete="cascade", select=True, required=True)
  647. stu_name = fields.Char(related='user_id.name', string='Name',
  648. help="Select Student From Existing List")
  649. name = fields.Char('Name')
  650. relation = fields.Many2one('student.relation.master', string='Relation',
  651. required=True)
  652. phone = fields.Char('Phone', required=True)
  653. email = fields.Char('E-Mail')
  654. class StudentRelationMaster(models.Model):
  655. ''' Student Relation Information '''
  656. _name = "student.relation.master"
  657. _description = "Student Relation Master"
  658. name = fields.Char('Name', required=True, help="Enter Relation name")
  659. seq_no = fields.Integer('Sequence')
  660. class GradeMaster(models.Model):
  661. _name = 'grade.master'
  662. name = fields.Char('Grade', select=1, required=True)
  663. grade_ids = fields.One2many('grade.line', 'grade_id', string='Grade Name')
  664. class GradeLine(models.Model):
  665. _name = 'grade.line'
  666. from_mark = fields.Integer("From Marks", required=True, help="The grade \
  667. will starts from this marks.")
  668. to_mark = fields.Integer('To Marks', required=True, help="The grade will\
  669. ends to this marks.")
  670. grade = fields.Char('Grade', required=True, help="Grade")
  671. sequence = fields.Integer('Sequence', help="Sequence order of the grade.")
  672. fail = fields.Boolean("Fail", help="If fail field is set to True, it will\
  673. allow you to set the grade as fail.")
  674. grade_id = fields.Many2one("grade.master", 'Grade')
  675. name = fields.Char('Name')
  676. class StudentNews(models.Model):
  677. _name = 'student.news'
  678. _description = 'Student News'
  679. _rec_name = 'subject'
  680. subject = fields.Char('Subject', required=True, help="Subject \
  681. of the news.")
  682. description = fields.Text('Description', help="Description")
  683. date = fields.Datetime('Expiry Date', help="Expiry date of the news.")
  684. user_ids = fields.Many2many('res.users', 'user_news_rel', 'id',
  685. 'user_ids', 'User News', help="Name to whom \
  686. this news is related.")
  687. color = fields.Integer('Color Index', default=0)
  688. # @api.v7
  689. # def news_update(self, cr, uid, ids, context = None):
  690. # emp_obj = self.pool.get("hr.employee")
  691. # obj_mail_server = self.pool.get('ir.mail_server')
  692. # mail_server_ids = obj_mail_server.search(cr, uid, [], context=context)
  693. # if not mail_server_ids:
  694. # raise osv.except_osv(_('Mail Error'), _('No mail outgoing mail\
  695. # server specified!'))
  696. # mail_server_record = obj_mail_server.browse(cr, uid,
  697. # mail_server_ids[0])
  698. # email_list = []
  699. # for news in self.browse(cr, uid, ids, context):
  700. # if news.user_ids:
  701. # for user in news.user_ids:
  702. # if user.email:
  703. # email_list.append(user.email)
  704. # if not email_list:
  705. # raise osv.except_osv(_('User Email Configuration '),
  706. # _("Email not found in users !"))
  707. # else:
  708. # emp_ids = emp_obj.search(cr, uid, [], context = context)
  709. # for employee in emp_obj.browse(cr, uid,emp_ids,
  710. # context=context ):
  711. # if employee.work_email:
  712. # email_list.append(employee.work_email)
  713. # elif employee.user_id and employee.user_id.email:
  714. # email_list.append(employee.user_id.email)
  715. # if not email_list:
  716. # raise osv.except_osv(_('Mail Error' ), _("Email not defined!"))
  717. # rec_date = fields.Datetime.context_timestamp(cr, uid,
  718. # datetime.strptime(news.date, DEFAULT_SERVER_DATETIME_FORMAT),
  719. # context=context)
  720. # body = 'Hi,<br/><br/> \
  721. # This is a news update from <b>%s</b> posted at %s<br/><br/>\
  722. # %s <br/><br/>\
  723. # Thank you.' % (cr.dbname,
  724. # rec_date.strftime('%d-%m-%Y %H:%M:%S'), news.description )
  725. # message = obj_mail_server.build_email(
  726. # email_from=mail_server_record.smtp_user,
  727. # email_to=email_list,
  728. # subject='Notification for news update.',
  729. # body=body,
  730. # body_alternative=body,
  731. # email_cc=None,
  732. # email_bcc=None,
  733. # reply_to=mail_server_record.smtp_user,
  734. # attachments=None,
  735. # references = None,
  736. # object_id=None,
  737. # subtype='html', #It can be plain or html
  738. # subtype_alternative=None,
  739. # headers=None)
  740. # obj_mail_server.send_email(cr, uid, message=message,
  741. # mail_server_id=mail_server_ids[0], context=context)
  742. # return True
  743. @api.multi
  744. def news_update(self):
  745. emp_obj = self.env['hr.employee']
  746. mail_server = self.env['ir.mail_server']
  747. mail_server_ids = mail_server.search([])
  748. if not mail_server_ids:
  749. raise except_orm(_('Mail Error'), _('No mail outgoing mail \
  750. server specified!'))
  751. server_rec = mail_server_ids[0]
  752. email_list = []
  753. for news in self:
  754. if news.user_ids:
  755. for user in news.user_ids:
  756. if user.email:
  757. email_list.append(user.email)
  758. if not email_list:
  759. raise except_orm(_('User Email Configuration '),
  760. _("Email not found in users !"))
  761. else:
  762. for employee in emp_obj.search([]):
  763. if employee.work_email:
  764. email_list.append(employee.work_email)
  765. elif employee.user_id and employee.user_id.email:
  766. email_list.append(employee.user_id.email)
  767. if not email_list:
  768. raise except_orm(_('Mail Error'), _("Email not defined!"))
  769. # rec_date = fields.datetime.context_timestamp(datetime.strptime(news.date,
  770. # DEFAULT_SERVER_DATETIME_FORMAT))
  771. t = datetime.strptime(news.date, '%Y-%m-%d %H:%M:%S')
  772. body = 'Hi,<br/><br/> \
  773. This is a news update from <b>%s</b> posted at %s<br/><br/>\
  774. %s <br/><br/>\
  775. Thank you.' % (self._cr.dbname,
  776. t.strftime('%d-%m-%Y %H:%M:%S'),
  777. news.description)
  778. message = mail_server.build_email(email_from=server_rec.smtp_user,
  779. email_to=email_list,
  780. subject='Notification for\
  781. news update.',
  782. body=body,
  783. body_alternative=body,
  784. email_cc=None,
  785. email_bcc=None,
  786. reply_to=server_rec.smtp_user,
  787. attachments=None,
  788. references=None,
  789. object_id=None,
  790. subtype='html',
  791. subtype_alternative=None,
  792. headers=None)
  793. mail_server.send_email(message=message,
  794. mail_server_id=mail_server_ids[0].id)
  795. return True
  796. class StudentReminder(models.Model):
  797. _name = 'student.reminder'
  798. stu_id = fields.Many2one('student.student', ' Student Name',
  799. required=True)
  800. name = fields.Char('Title')
  801. date = fields.Date('Date')
  802. description = fields.Text('Description')
  803. color = fields.Integer('Color Index', default=0)
  804. class StudentCast(models.Model):
  805. _name = "student.cast"
  806. name = fields.Char("Name", required=True)
  807. class ResUsers(models.Model):
  808. _inherit = 'res.users'
  809. @api.model
  810. def create(self, vals):
  811. vals.update({'employee_ids': False})
  812. return super(ResUsers, self).create(vals)
  813. class EmailTemplate(models.Model):
  814. _inherit = "email.template"
  815. def generate_email(self, cr, uid, template_id, res_id, context=None):
  816. if context is None:
  817. context = {}
  818. ret = super(EmailTemplate,
  819. self).generate_email(cr, uid,
  820. template_id,
  821. res_id, context=context)
  822. body_text = context.get('body_text', False)
  823. subject = context.get('subject', False)
  824. email_to = context.get('email_to', False)
  825. if (body_text or subject or email_to):
  826. ret['body_text'] = body_text
  827. ret['subject'] = subject
  828. ret['email_to'] = email_to
  829. return ret
  830. # @api.multi
  831. # def generate_email(self, template_id, res_id):
  832. # if self._context is None:
  833. # self._context = {}
  834. # ret = super(EmailTemplate, self).generate_email(self._cr, self._uid,
  835. # template_id, res_id,
  836. # context=self._context)
  837. # if self._context.get('body_text', False) or \
  838. # self._context.get('subject', False) or \
  839. # self._context.get('email_to', False):
  840. # ret['body_text'] = self._context['body_text']
  841. # ret['subject'] = self._context['subject']
  842. # ret['email_to'] = self._context['email_to']
  843. # return ret