1.基本设定(basic)模块
1.1.models.py 设定
1.1.1.户口
class Residence(models.Model):
title = models.CharField(max_length=8, unique=True, blank=False, verbose_name='名称')
def __str__(self):
return self.title
class Meta:
verbose_name = '户口'
verbose_name_plural = verbose_name
1.1.2.单位
例如:行政/保育/教师。
class Depart(models.Model):
title = models.CharField(max_length=8, unique=True, blank=False, verbose_name='名称')
def __str__(self):
return self.title
class Meta:
verbose_name = '单位'
verbose_name_plural = verbose_name
1.1.3.职位
每位职员只能有且必须要有一个职位。
class Position(models.Model):
depart = models.ForeignKey(Depart, verbose_name='单位', on_delete=models.PROTECT)
title = models.CharField(max_length=16, unique=True, blank=False, verbose_name='名称')
subsidy = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='职位津贴')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='position_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='position_update_user', null=True)
def __str__(self):
return self.title
class Meta:
verbose_name = '职位'
verbose_name_plural = verbose_name
1.1.4.证照
当职员拥有的特定证照时,工资明细的[幼儿出勤]明细金额就会比较高。
CARE_CHOICES = (
('0', '否'),
('1', '是'),
)
class Licence(models.Model):
title = models.CharField(max_length=16, unique=True, blank=False, verbose_name='名称')
is_care = models.CharField(max_length=1, choices=CARE_CHOICES, default='0', verbose_name='保育员证照')
attend2_multiple = models.DecimalField(max_digits=8, default=1, decimal_places=2, blank=False, null=False,
help_text='[保育员证照]为否时,自动更新为1', verbose_name='保育员幼儿出勤倍数')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='licence_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='licence_update_user', null=True)
def __str__(self):
return self.title
class Meta:
verbose_name = '证照'
verbose_name_plural = verbose_name
1.1.5.职务
每位职员只能有一个职位,但是可以兼任多个职务。
class Duty(models.Model):
title = models.CharField(max_length=16, unique=True, blank=False, verbose_name='名称')
subsidy = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='职务津贴')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='duty_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='duty_update_user', null=True)
def __str__(self):
return self.title
class Meta:
verbose_name = '职务'
verbose_name_plural = verbose_name
1.1.6.年级
年级可能有:幼班/小班/中班/大班。
class Grade(models.Model):
title = models.CharField(max_length=8, unique=True, blank=False, verbose_name='名称')
quota = models.PositiveIntegerField(default=1, verbose_name='班额')
over_fee = models.DecimalField(max_digits=16, decimal_places=2, verbose_name='超班额人头费')
delay_fee = models.DecimalField(max_digits=16, decimal_places=2, verbose_name='延时学生费用')
delay_wage1 = models.DecimalField(max_digits=16, default=0.00, decimal_places=2, verbose_name='延时教师时薪')
delay_wage2 = models.DecimalField(max_digits=16, default=0.00, decimal_places=2, verbose_name='延时保育时薪')
attend_bonus1 = models.DecimalField(max_digits=16, decimal_places=2, default=0.0, verbose_name='班级出勤奖金(教师)')
attend_bonus2 = models.DecimalField(max_digits=16, decimal_places=2, default=0.0, verbose_name='班级出勤奖金(保育员)')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='grade_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='grade_update_user', null=True)
def __str__(self):
return self.title
class Meta:
verbose_name = '年级'
verbose_name_plural = verbose_name
1.1.7.班级
每个年级有不一样的班级,例如幼班有幼一班,幼二班等。
STATUS_CHOICES = (
('1', '正常'),
('0', '停用'),
)
class Banji(models.Model):
grade = models.ForeignKey(Grade, verbose_name='年级', on_delete=models.PROTECT)
title = models.CharField(max_length=16, unique=True, blank=False, verbose_name='名称')
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='1', verbose_name='状态')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='banji_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='banji_update_user', null=True)
def __str__(self):
return self.title
class Meta:
verbose_name = '班级'
verbose_name_plural = verbose_name
1.1.8.职员
class Employee(models.Model):
title = models.CharField(max_length=16, blank=False, verbose_name='名称')
number = models.CharField(max_length=4, unique=True, null=False, blank=False, verbose_name='工号')
residence = models.ForeignKey(Residence, verbose_name='户口', on_delete=models.PROTECT)
entry_date = models.DateField(blank=False, null=False, verbose_name='入职日期')
regular_date = models.DateField(blank=True, null=True, verbose_name='转正日期')
departure_date = models.DateField(blank=True, null=True, verbose_name='离职日期')
position = models.ForeignKey(Position, verbose_name='职位', on_delete=models.PROTECT)
basic_wage = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='基本工资')
maintain_pre = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='养保')
medical_pre = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='医保')
unemploy_pre = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='失保')
acc_fund = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='公积金')
union_fee = models.DecimalField(max_digits=8, decimal_places=2, blank=False, null=False, verbose_name='工会费用')
full_bonus = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='全勤奖金')
asses_bonus = models.DecimalField(max_digits=16, decimal_places=2, blank=False, null=False, verbose_name='考核奖金')
att_percentage = models.DecimalField(max_digits=8, decimal_places=2, default=0, blank=False, null=False,
help_text='[职位]为[园长]时专用',
verbose_name='幼儿出勤奖金比例')
att_bonus = models.DecimalField(max_digits=8, decimal_places=2, default=0, blank=False, null=False,
help_text='[职位]为[营养员/驾驶员/总务]时专用',
verbose_name='幼儿出勤奖金')
att_wageo = models.DecimalField(max_digits=8, decimal_places=2, default=0, blank=False, null=False,
help_text='[职位]为非[园长/教师/保育员/营养员/驾驶员/总务]时使用',
verbose_name='幼儿出勤人头费用')
created = models.DateTimeField(auto_now_add=True, verbose_name='建立时间')
create_user = models.ForeignKey('auth.User', verbose_name='建立人员', on_delete=models.PROTECT,
related_name='employee_create_user')
updated = models.DateTimeField(auto_now=True, verbose_name='异动时间')
update_user = models.ForeignKey('auth.User', verbose_name='异动人员', on_delete=models.PROTECT,
related_name='employee_update_user', null=True)
def __str__(self):
return '{}-{}'.format(self.number, self.title)
class Meta:
verbose_name = '职员'
verbose_name_plural = verbose_name
1.1.9.兼任
记录哪些职员有兼任哪些职务。
class Parttime(models.Model):
employee = models.ForeignKey(Employee, verbose_name='职员', on_delete=models.PROTECT)
duty = models.ForeignKey(Duty, verbose_name='职务', on_delete=models.PROTECT)
def __str__(self):
return '{}'.format(self.id)
class Meta:
verbose_name = '兼任'
verbose_name_plural = verbose_name
1.1.10.教学
记录哪些职员是哪些班级的教师,担任教师的职员其职位必须是教师。
class Teachship(models.Model):
employee = models.ForeignKey(Employee, verbose_name='职员', on_delete=models.PROTECT,
limit_choices_to={'position': 1})
banji = models.ForeignKey(Banji, verbose_name='班级', on_delete=models.PROTECT)
def __str__(self):
return '{}'.format(self.id)
class Meta:
verbose_name = '教学'
verbose_name_plural = verbose_name
1.1.11.保育
记录哪些职员是哪些班级的保育员,担任保育员的职员其职位必须是保育员。
class Careship(models.Model):
employee = models.ForeignKey(Employee, verbose_name='职员', on_delete=models.PROTECT,
limit_choices_to={'position': 2})
banji = models.ForeignKey(Banji, verbose_name='班级', on_delete=models.PROTECT)
def __str__(self):
return '{}'.format(self.id)
class Meta:
verbose_name = '保育'
verbose_name_plural = verbose_name
1.1.12.拥有证照
记录哪些职员拥有哪些证照。
class Licenceship(models.Model):
employee = models.ForeignKey(Employee, verbose_name='职员', on_delete=models.PROTECT)
licence = models.ForeignKey(Licence, verbose_name='证照', on_delete=models.PROTECT)
def __str__(self):
return '{}'.format(self.id)
class Meta:
verbose_name = '拥有证照'
verbose_name_plural = verbose_name
1.2.admin.py 设定
已在代码的备注注明检查事项请自行参考。
@admin.register(Residence)
class ResidenceAdmin(admin.ModelAdmin):
list_display = ['id', 'title']
view_on_site = False
def has_delete_permission(self, request, obj=None):
return False
"""
单位检查
1.单位1/2/3/4不可异动
"""
class DepartCheckForm(forms.ModelForm):
def clean(self):
updated_data = super(DepartCheckForm, self).clean()
if self.instance.id in (1, 2, 3, 4) and self.instance.title != updated_data['title']:
raise forms.ValidationError('单位1(行政)/2(教师)/3(保育)/4(后勤)不可异动。')
@admin.register(Depart)
class DepartAdmin(admin.ModelAdmin):
list_display = ['id', 'title']
form = DepartCheckForm
view_on_site = False
def has_delete_permission(self, request, obj=None):
return False
"""
职位检查
1.职位1/2/3/11/12/13名称与单位不可异动
"""
class PositionCheckForm(forms.ModelForm):
def clean(self):
updated_data = super(PositionCheckForm, self).clean()
if self.instance.id in (1, 2, 3, 11, 12, 13) and (self.instance.title != updated_data['title'] or
self.instance.depart != updated_data['depart']):
raise forms.ValidationError('职位1(教师)/2(保育员)/3(园长)/11(营养员)/12(驾驶员)/13(总务)'
'的名称与单位不可异动。')
@admin.register(Position)
class PositionAdmin(admin.ModelAdmin):
list_display = ['id', 'depart', 'title', 'subsidy', 'created', 'create_user', 'updated', 'update_user']
fields = ['title', 'depart', 'subsidy']
form = PositionCheckForm
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False
"""
兼任检查
1.同一位职员不得兼任同一个职务多余一次
"""
class ParttimeCheckInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
duty_list = []
for form in self.forms:
if form.cleaned_data:
duty = form.cleaned_data.get('duty')
if duty.id in duty_list:
raise forms.ValidationError("该职员兼任职务[{}-{}]已重复。".format(duty.id, duty.title))
else:
duty_list.append(duty.id)
class ParttimeInline(admin.TabularInline):
model = Parttime
formset = ParttimeCheckInlineFormset
fields = ['employee', 'duty']
raw_id_fields = ['employee', 'duty']
extra = 0
@admin.register(Duty)
class DutyAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'subsidy', 'created', 'create_user', 'updated', 'update_user']
fields = ['title', 'subsidy']
inlines = [ParttimeInline]
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False
@admin.register(Grade)
class GradeAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'quota', 'over_fee', 'delay_fee', 'delay_wage1', 'delay_wage2',
'attend_bonus1', 'attend_bonus2', 'created', 'create_user', 'updated', 'update_user']
fields = ['title', 'quota', 'over_fee', 'delay_fee', 'delay_wage1', 'delay_wage2', 'attend_bonus1', 'attend_bonus2']
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False
"""
教学检查
1.一位职员只能担任一个班级的教学
2.担任班级教师的职员职务必须为教师
"""
class TeachshipCheckInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
for form in self.forms:
if form.cleaned_data:
employee = form.cleaned_data.get('employee')
if employee.position.id != 1:
right_position = Position.objects.get(id=1)
raise forms.ValidationError("担任班级教师的职员其职务须"
"为[{}-{}]。".format(right_position.id, right_position.title))
teachships = Teachship.objects.filter(employee=employee)
if teachships.count() > 1:
raise forms.ValidationError("该职员已担任其他班级的教师。")
class TeachshipInline(admin.TabularInline):
model = Teachship
formset = TeachshipCheckInlineFormset
fields = ['employee', 'banji']
raw_id_fields = ['employee', 'banji']
extra = 0
"""
保育检查
1.一位职员只能担任一个班级的保育
2.担任班级保育的职员职务必须为保育员
"""
class CareshipCheckInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
for form in self.forms:
if form.cleaned_data:
employee = form.cleaned_data.get('employee')
if employee.position.id != 2:
right_position = Position.objects.get(id=2)
raise forms.ValidationError("担任班级保育的职员其职务须"
"为[{}-{}]。".format(right_position.id, right_position.title))
careships = Careship.objects.filter(employee=employee)
if careships.count() > 1:
raise forms.ValidationError("该职员已担任其他班级的保育员。")
class CareshipInline(admin.TabularInline):
model = Careship
formset = CareshipCheckInlineFormset
fields = ['employee', 'banji']
raw_id_fields = ['employee', 'banji']
extra = 0
"""
证照检查
1.职员其职位(position)为保育员时才能拥有保育员的证照
2.职员只能拥有一次相同的证照
"""
class LicenceshipCheckInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
for form in self.forms:
if form.cleaned_data:
employee = form.cleaned_data.get('employee')
licence = form.cleaned_data.get('licence')
if licence.is_care == '1' and employee.position.id != 2:
raise forms.ValidationError("职员其职位为[保育员]时才能拥有保育员的证照。")
licenceships = Licenceship.objects.filter(employee=employee, licence=licence)
if licenceships.count() > 1:
raise forms.ValidationError("职员只能拥有一次相同的证照。")
class LicenceshipInline(admin.TabularInline):
model = Licenceship
formset = LicenceshipCheckInlineFormset
fields = ['employee', 'licence']
raw_id_fields = ['employee', 'licence']
extra = 0
@admin.register(Banji)
class BanjiAdmin(admin.ModelAdmin):
list_display = ['id', 'grade', 'title', 'status', 'created', 'create_user', 'updated', 'update_user']
fields = ['title', 'grade', 'status']
inlines = [TeachshipInline, CareshipInline]
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False
@admin.register(Employee)
class EmployeeAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'number', 'residence', 'entry_date', 'departure_date', 'regular_date', 'position',
'basic_wage', 'maintain_pre', 'medical_pre', 'unemploy_pre', 'acc_fund', 'union_fee',
'full_bonus', 'asses_bonus', 'att_percentage', 'att_bonus', 'att_wageo', 'created', 'create_user',
'updated', 'update_user']
fields = ['title', 'number', 'residence', 'entry_date', 'departure_date', 'regular_date', 'position',
'basic_wage', 'maintain_pre', 'medical_pre', 'unemploy_pre', 'acc_fund', 'union_fee',
'full_bonus', 'asses_bonus', 'att_percentage', 'att_bonus', 'att_wageo']
inlines = [ParttimeInline, TeachshipInline, CareshipInline, LicenceshipInline]
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
#当职员的[职位]非[园长]时,[幼儿出勤奖金比例]自动等于0
if obj.position.id != 3:
obj.att_percentage = 0
#当职员的[职位]非[营养员/驾驶员/总务]时,[幼儿出勤奖金]自动等于0
if obj.position.id not in (11, 12, 13):
obj.att_bonus = 0
#当职员的[职位]是[园长/教师/保育员]时,[幼儿出勤人头费用]自动等于0
if obj.position.id in (1, 2, 3):
obj.att_wageo = 0
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False
"""
证照检查
1.[保育员证照]使用='1'时,延时保育时薪倍数才可以不等于1
"""
class LicenceCheckForm(forms.ModelForm):
def clean(self):
#updated_data = super(LicenceCheckForm, self).clean()
if self.instance.is_care != '1' and self.instance.attend2_multiple != 1:
raise forms.ValidationError('当[保育员证照]使用为"是"时,[延时保育时薪倍数]才可以不等于1。')
@admin.register(Licence)
class LicenceAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'is_care', 'attend2_multiple', 'created', 'create_user', 'updated', 'update_user']
fields = ['title', 'is_care', 'attend2_multiple']
form = LicenceCheckForm
view_on_site = False
def save_model(self, request, obj, form, change):
if not change:
obj.create_user = request.user
else:
obj.update_user = request.user
obj.updated = datetime.now()
"""
[保育员证照]使用='0'时,保育员幼儿出勤倍数自动等于1
"""
if obj.is_care == '0':
obj.attend2_multiple = 1
super().save_model(request, obj, form, change)
def has_delete_permission(self, request, obj=None):
return False