2
2
# For copyright and license notices, see __manifest__.py file in module root
3
3
# directory
4
4
##############################################################################
5
- from odoo import api , models , fields
6
- from datetime import date
7
5
import random
8
6
import string
7
+ from datetime import date
8
+
9
+ from odoo import api , fields , models
9
10
10
11
11
12
class AcademicGroup (models .Model ):
12
- _name = ' academic.group'
13
- _description = ' group'
14
- _order = ' name'
13
+ _name = " academic.group"
14
+ _description = " group"
15
+ _order = " name"
15
16
16
17
_sql_constraints = [
17
- ('group_unique' ,
18
- 'unique(subject_id, company_id, level_id, year, division_id)' ,
19
- 'Group should be unique per Institution, Subject,'
20
- ' Course-Division and Year' )]
18
+ (
19
+ "group_unique" ,
20
+ "unique(subject_id, company_id, level_id, year, division_id)" ,
21
+ "Group should be unique per Institution, Subject," " Course-Division and Year" ,
22
+ )
23
+ ]
21
24
22
- type = fields .Selection ([
23
- ('student' , 'Student' ),
24
- ('teacher' , 'Teacher' ),
25
- ('administrator' , 'Administrator' ),
26
- ('gral_administrator' , 'gral_administrator' ),
27
- ('parent' , 'Relative' )]
28
- )
29
- year = fields .Integer (
30
- required = True ,
31
- default = date .today ().year ,
32
- index = True
25
+ type = fields .Selection (
26
+ [
27
+ ("student" , "Student" ),
28
+ ("teacher" , "Teacher" ),
29
+ ("administrator" , "Administrator" ),
30
+ ("gral_administrator" , "gral_administrator" ),
31
+ ("parent" , "Relative" ),
32
+ ]
33
33
)
34
+ year = fields .Integer (required = True , default = date .today ().year , index = True )
34
35
division_id = fields .Many2one (
35
- ' academic.division' ,
36
- string = ' Division' ,
36
+ " academic.division" ,
37
+ string = " Division" ,
37
38
)
38
39
company_id = fields .Many2one (
39
- ' res.company' ,
40
- string = ' Company' ,
40
+ " res.company" ,
41
+ string = " Company" ,
41
42
required = True ,
42
- context = {' default_is_company' : True },
43
- default = lambda self : self .env .company
43
+ context = {" default_is_company" : True },
44
+ default = lambda self : self .env .company ,
44
45
)
45
- study_plan_level_ids = fields .Many2many (related = ' company_id.study_plan_id.level_ids' )
46
+ study_plan_level_ids = fields .Many2many (related = " company_id.study_plan_id.level_ids" )
46
47
level_id = fields .Many2one (
47
- ' academic.level' ,
48
- string = ' Level' ,
48
+ " academic.level" ,
49
+ string = " Level" ,
49
50
required = True ,
50
51
)
51
- subject_id = fields .Many2one (
52
- 'academic.subject' ,
53
- string = 'Subject' ,
54
- required = False ,
55
- index = True
56
- )
52
+ subject_id = fields .Many2one ("academic.subject" , string = "Subject" , required = False , index = True )
57
53
teacher_id = fields .Many2one (
58
- ' res.partner' ,
59
- string = ' Teacher' ,
54
+ " res.partner" ,
55
+ string = " Teacher" ,
60
56
required = False ,
61
- context = {' default_partner_type' : ' teacher' },
62
- domain = [(' partner_type' , '=' , ' teacher' )],
57
+ context = {" default_partner_type" : " teacher" },
58
+ domain = [(" partner_type" , "=" , " teacher" )],
63
59
)
64
60
student_ids = fields .Many2many (
65
- 'res.partner' ,
66
- 'academic_student_group_ids_student_ids_rel' ,
67
- 'group_id' ,
68
- 'partner_id' ,
69
- string = 'Student' ,
70
- context = {'default_partner_type' : 'student' },
71
- domain = [('partner_type' , '=' , 'student' )],
72
- )
73
- name = fields .Char (
74
- compute = '_compute_name' ,
75
- store = True
61
+ "res.partner" ,
62
+ "academic_student_group_ids_student_ids_rel" ,
63
+ "group_id" ,
64
+ "partner_id" ,
65
+ string = "Student" ,
66
+ context = {"default_partner_type" : "student" },
67
+ domain = [("partner_type" , "=" , "student" )],
76
68
)
69
+ name = fields .Char (compute = "_compute_name" , store = True )
77
70
active = fields .Boolean (default = True )
78
71
student_ids_count = fields .Integer (
79
- string = ' Student Count' ,
80
- compute = ' _compute_student_ids_count' ,
72
+ string = " Student Count" ,
73
+ compute = " _compute_student_ids_count" ,
81
74
)
82
75
83
- @api .depends (' company_id' , ' level_id' , ' division_id' , ' year' )
76
+ @api .depends (" company_id" , " level_id" , " division_id" , " year" )
84
77
def _compute_name (self ):
85
78
for line in self :
86
79
name_parts = [
@@ -90,34 +83,33 @@ def _compute_name(self):
90
83
line .level_id .section_id .name if line .level_id and line .level_id .section_id else None ,
91
84
f"{ self .env ._ ('Year:' )} { line .year } " ,
92
85
]
93
- line .name = ' - ' .join (filter (None , name_parts ))
86
+ line .name = " - " .join (filter (None , name_parts ))
94
87
95
88
def create_students_users (self ):
96
- '''
89
+ """
97
90
This function create users if they don't exist for students related
98
91
to this group.
99
- '''
92
+ """
100
93
self .student_ids .quickly_create_portal_user ()
101
94
# Creamos contrasenas para todos los students que no tengan una
102
95
# explicita (no hashed)
103
- for user in \
104
- self .student_ids .mapped ('user_ids' )\
105
- .filtered (lambda x : not x .password ):
106
- user .password = '' .join (random .choice (
107
- string .ascii_uppercase + string .digits ) for _ in range (6 ))
96
+ for user in self .student_ids .mapped ("user_ids" ).filtered (lambda x : not x .password ):
97
+ user .password = "" .join (random .choice (string .ascii_uppercase + string .digits ) for _ in range (6 ))
108
98
109
99
def print_users (self ):
110
- '''
100
+ """
111
101
This function prints a report with users login and password.
112
- '''
102
+ """
113
103
self .ensure_one ()
114
104
self .create_students_users ()
115
- report = self .env ['ir.actions.report' ].search (
116
- [('report_name' , '=' , 'academic.template_report_users' )],
117
- limit = 1 ).report_action (self )
105
+ report = (
106
+ self .env ["ir.actions.report" ]
107
+ .search ([("report_name" , "=" , "academic.template_report_users" )], limit = 1 )
108
+ .report_action (self )
109
+ )
118
110
return report
119
111
120
- @api .depends (' student_ids' )
112
+ @api .depends (" student_ids" )
121
113
def _compute_student_ids_count (self ):
122
114
for group in self :
123
115
group .student_ids_count = len (group .student_ids )
@@ -126,17 +118,22 @@ def create_next_year_groups(self):
126
118
# estamos pasando de un año a otro sin usar study plan por lo siguiente:
127
119
# a) hay muchos colegios que no lo tienen bien implmentado
128
120
# b) los study plan no pueden reflejar todos los casos todavia (por )
129
-
121
+
130
122
for rec in self :
131
- next_group = rec .env ['academic.group' ].search ([
132
- ('year' , '=' , rec .year + 1 ),
133
- ('company_id' , '=' , rec .company_id .id ),
134
- ('level_id' , '=' , rec .level_id .id ),
135
- ('division_id' , '=' , rec .division_id .id )
136
- ], limit = 1 )
123
+ next_group = rec .env ["academic.group" ].search (
124
+ [
125
+ ("year" , "=" , rec .year + 1 ),
126
+ ("company_id" , "=" , rec .company_id .id ),
127
+ ("level_id" , "=" , rec .level_id .id ),
128
+ ("division_id" , "=" , rec .division_id .id ),
129
+ ],
130
+ limit = 1 ,
131
+ )
137
132
138
133
if not next_group :
139
- next_group = rec .copy (default = {
140
- 'year' : rec .year + 1 ,
141
- 'student_ids' : False ,
142
- })
134
+ next_group = rec .copy (
135
+ default = {
136
+ "year" : rec .year + 1 ,
137
+ "student_ids" : False ,
138
+ }
139
+ )
0 commit comments