assign_roll_no.py.svn-base 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. # Copyright (C) 2011-2012 Serpent Consulting Services (<http://www.serpentcs.com>)
  7. #
  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 osv import fields,osv
  23. # This wizard is designed for assigning the roll number to a student.
  24. class assign_roll_no(osv.osv_memory):
  25. _name = 'assign.roll.no'
  26. _description = 'Assign Roll Number'
  27. _columns = {
  28. 'class_id': fields.many2one('standard.standard', 'Class', required=True),
  29. 'medium_id': fields.many2one('standard.medium', 'Medium', required=True),
  30. 'division_id': fields.many2one('standard.division', 'Division', required=True),
  31. }
  32. def assign_rollno(self, cr, uid, ids, context=None):
  33. res = {}
  34. student_obj = self.pool.get('student.student')
  35. for student_data in self.browse(cr, uid, ids, context=context):
  36. domain = [('class_id', '=', student_data.class_id.id), ('medium_id' ,'=', student_data.medium_id.id), ('division_id', '=', student_data.division_id.id)]
  37. search_student_ids = student_obj.search(cr, uid, domain, context=context)
  38. number = 1
  39. for student in student_obj.browse(cr, uid, search_student_ids, context=context):
  40. student_obj.write(cr, uid, student.id, {'roll_no':number}, context=context)
  41. number = number + 1
  42. return res
  43. assign_roll_no()
  44. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: