move_standards.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. from openerp.exceptions import except_orm
  24. class MoveStandards(models.TransientModel):
  25. _name = 'move.standards'
  26. academic_year_id = fields.Many2one('academic.year', 'Academic Year',
  27. required=True)
  28. @api.multi
  29. def move_start(self):
  30. if self._context is None:
  31. self._context = {}
  32. if not self._context.get('active_ids'):
  33. return {}
  34. academic_obj = self.env['academic.year']
  35. school_standard_obj = self.env['school.standard']
  36. standard_obj = self.env["standard.standard"]
  37. result_obj = self.env['exam.result']
  38. history_obj = self.env["student.history"]
  39. for data in self:
  40. active_ids = self._context.get('active_ids')
  41. for standards in school_standard_obj.browse(active_ids):
  42. for student in standards.student_ids:
  43. academic_year_id = data.academic_year_id.id
  44. stud_year_ids = history_obj.search([('academice_year_id',
  45. '=',
  46. academic_year_id),
  47. ('student_id', '=',
  48. student.id)])
  49. year_id = academic_obj.next_year(student.year.sequence)
  50. if year_id and year_id != data.academic_year_id.id:
  51. continue
  52. if stud_year_ids:
  53. raise except_orm(_('Warning !'), _('Please Select \
  54. Next Academic \
  55. year.'))
  56. else:
  57. standard_id = student.standard_id.id
  58. division_id = student.division_id.id
  59. medium_id = student.medium_id.id
  60. res = result_obj.search([('standard_id', '=',
  61. standard_id),
  62. ('standard_id.division_id',
  63. '=', division_id),
  64. ('standard_id.medium_id',
  65. '=', medium_id),
  66. ('student_id', '=',
  67. student.id)])
  68. result_data = False
  69. if res:
  70. result_data = result_obj.browse(res.id)
  71. if result_data and result_data.result == "Pass":
  72. seq = standards.standard_id.sequence
  73. next_class_id = standard_obj.next_standard(seq)
  74. if next_class_id:
  75. student.write({'year':
  76. data.academic_year_id.id,
  77. 'standard_id': next_class_id,
  78. })
  79. year = student.year.id
  80. sta_id = standards.standard_id.id
  81. div_id = standards.division_id.id
  82. med_id = standards.medium_id.id
  83. result = result_data.result
  84. percent = result_data.percentage
  85. history_obj.create({'student_id': student.id,
  86. 'academice_year_id': year,
  87. 'standard_id': sta_id,
  88. 'division_id': div_id,
  89. 'medium_id': med_id,
  90. 'result': result,
  91. 'percentage': percent
  92. })
  93. else:
  94. raise except_orm(_("Error!"),
  95. _("Student is not eligible \
  96. for Next Standard."))
  97. return {}