move_standards.py.svn-base 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from osv import fields,osv
  22. from tools.translate import _
  23. class move_standards(osv.osv_memory):
  24. _name = 'move.standards'
  25. _columns = {
  26. 'academic_year_id':fields.many2one('academic.year', 'Academic Year', required=True),
  27. }
  28. def move_start(self, cr, uid, ids, context=None):
  29. if context is None:
  30. context = {}
  31. if not context.get('active_ids'):
  32. return {}
  33. academic_obj = self.pool.get('academic.year')
  34. school_standard_obj = self.pool.get('school.standard')
  35. standard_obj = self.pool.get("standard.standard")
  36. result_obj = self.pool.get('exam.result')
  37. student_obj = self.pool.get('student.student')
  38. student_history_obj = self.pool.get("student.history")
  39. for data in self.browse(cr, uid, ids, context):
  40. for standards in school_standard_obj.browse(cr, uid, context.get('active_ids'), context):
  41. for student in standards.student_ids:
  42. stud_year_ids = student_history_obj.search(cr, uid, [('academice_year_id', '=', data.academic_year_id.id), ('student_id', '=', student.id)])
  43. year_id = academic_obj.next_year(cr, uid, student.year.sequence, context)
  44. if year_id and year_id != data.academic_year_id.id:
  45. continue
  46. if stud_year_ids:
  47. raise osv.except_osv(_('Warning !'), _('Please Select Next Academic year.'))
  48. else:
  49. result_exists = result_obj.search(cr, uid, [('standard_id', '=', student.class_id.id), ('division_id', '=', student.division_id.id), ('medium_id', '=', student.medium_id.id), ('student_id','=', student.id)])
  50. if result_exists:
  51. result = result_obj.browse(cr, uid, result_exists[0], context).result
  52. if result == "Pass":
  53. next_class_id = standard_obj.next_standard(cr, uid, standards.standard_id.sequence, context)
  54. if next_class_id:
  55. student_obj.write(cr, uid, student.id, {'year': data.academic_year_id.id,
  56. 'class_id': next_class_id})
  57. student_history_obj.create(cr, uid, {'student_id':student.id,
  58. 'academice_year_id':student.year.id,
  59. 'class_id': standards.standard_id.id,
  60. 'division_id': standards.division_id.id,
  61. 'medium_id': standards.medium_id.id})
  62. pass
  63. return {}
  64. move_standards()
  65. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: