1. 修改职级表删除错误:POST该为小写
2. tags中模板bug
3. 解决人员基本信息添加时部分字段做校验的问题
This commit is contained in:
彭森 2024-06-24 10:49:38 +08:00
parent 9de9d5a7e8
commit a1302d089d
5 changed files with 75 additions and 49 deletions

View File

@ -7,25 +7,6 @@ class EmployeeInformationForm(forms.ModelForm):
"""
人力资源管理-人员基本信息表单
"""
primary_department = forms.ChoiceField(
choices=[('', '---------')] + [(dept.department_name, dept.department_name) for dept in
PrimaryDepartment.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="一级部门"
)
position = forms.ChoiceField(
choices=[('', '---------')] + [(p.position_name, p.position_name) for p in Position.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="岗位"
)
rank = forms.ChoiceField(
choices=[('', '---------')] + [(r.rank_name, r.rank_name) for r in Rank.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="职级"
)
class Meta:
model = EmployeeInformation
exclude = ['resignation_type', 'resignation_reason', 'resignation_date']
@ -40,14 +21,11 @@ class EmployeeInformationForm(forms.ModelForm):
'blood_type': forms.Select(choices=EmployeeInformation.BLOOD_TYPE_CHOICES, attrs={'class': 'form-control'}),
'ethnicity': forms.TextInput(attrs={'class': 'form-control'}),
'domicile': forms.TextInput(attrs={'class': 'form-control'}),
'marital_status': forms.Select(choices=EmployeeInformation.MARITAL_STATUS_CHOICES,
attrs={'class': 'form-control'}),
'political_affiliation': forms.Select(choices=EmployeeInformation.POLITICAL_AFFILIATION_CHOICES,
attrs={'class': 'form-control'}),
'marital_status': forms.Select(choices=EmployeeInformation.MARITAL_STATUS_CHOICES, attrs={'class': 'form-control'}),
'political_affiliation': forms.Select(choices=EmployeeInformation.POLITICAL_AFFILIATION_CHOICES, attrs={'class': 'form-control'}),
'entry_date': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
'regularization_date': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
'employment_type': forms.Select(choices=EmployeeInformation.EMPLOYMENT_TYPE_CHOICES,
attrs={'class': 'form-control'}),
'employment_type': forms.Select(choices=EmployeeInformation.EMPLOYMENT_TYPE_CHOICES, attrs={'class': 'form-control'}),
'status': forms.Select(choices=EmployeeInformation.STATUS_CHOICES, attrs={'class': 'form-control'}),
'secondary_department': forms.Select(attrs={'class': 'form-control'}),
'contract_end_date': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
@ -71,19 +49,48 @@ class EmployeeInformationForm(forms.ModelForm):
is_edit = kwargs.pop('is_edit', False)
super(EmployeeInformationForm, self).__init__(*args, **kwargs)
self.fields['primary_department'] = forms.ChoiceField(
choices=[('', '---------')] + [(dept.department_name, dept.department_name) for dept in PrimaryDepartment.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="一级部门",
required=False
)
self.fields['position'] = forms.ChoiceField(
choices=[('', '---------')] + [(p.position_name, p.position_name) for p in Position.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="岗位",
required=False
)
self.fields['rank'] = forms.ChoiceField(
choices=[('', '---------')] + [(r.rank_name, r.rank_name) for r in Rank.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="职级",
required=False
)
for field_name in self.fields:
if field_name != 'name':
self.fields[field_name].required = False
if is_edit:
self.fields['resignation_type'] = forms.ChoiceField(
choices=EmployeeInformation.RESIGNATION_TYPE_CHOICES,
choices=[('', '---------')] + [(r[0], r[0]) for r in EmployeeInformation.RESIGNATION_TYPE_CHOICES],
widget=forms.Select(attrs={'class': 'form-control'}),
label="离职类型"
label="离职类型",
required=False
)
self.fields['resignation_reason'] = forms.CharField(
widget=forms.TextInput(attrs={'class': 'form-control'}),
label="离职原因"
label="离职原因",
required=False
)
self.fields['resignation_date'] = forms.DateField(
widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
label="离职日期"
label="离职日期",
required=False
)
if self.instance:
self.fields['resignation_type'].initial = self.instance.resignation_type

View File

@ -141,17 +141,21 @@ class EmployeeInformation(models.Model):
position = Position.objects.filter(position_name=self.position).first()
rank = Rank.objects.filter(rank_name=self.rank).first()
if not primary_department_name:
raise ValueError("一级部门不存在")
if self.primary_department:
if not primary_department_name:
raise ValueError("一级部门不存在")
if not secondary_department:
raise ValueError("二级部门不存在")
if self.secondary_department:
if not secondary_department:
raise ValueError("二级部门不存在")
if not position:
raise ValueError("岗位不存在")
if self.position:
if not position:
raise ValueError("岗位不存在")
if not rank:
raise ValueError("职级不存在")
if self.rank:
if not rank:
raise ValueError("职级不存在")
super(EmployeeInformation, self).save(*args, **kwargs)

View File

@ -714,7 +714,7 @@ def rk_list_delete(request):
"""
基础数据-人力资源管理-职级表-删除
"""
rank_id = request.post.get('id')
rank_id = request.POST.get('id')
if rank_id:
Rank.objects.filter(rank_id=rank_id).delete()
return JsonResponse({"message": "删除成功"})

View File

@ -65,18 +65,18 @@ def proj_ledger_list_view(request):
基础数据-项目管理-项目台账-列表视图
"""
# 声明查询集
# current_user = request.user.id
#
# try:
# account_profile = AccountProfile.objects.get(user=current_user)
# employee = account_profile.employee_information
# except AccountProfile.DoesNotExist:
# return JsonResponse({'message': '您的账户未关联到员工信息,请联系管理员。'}, status=405)
#
# # 声明查询集,只显示当前用户作为主办人的记录
# query_set = ProjectLedger.objects.filter(project_leader=employee.name).order_by('-project_id')
current_user = request.user.id
query_set = ProjectLedger.objects.filter().order_by('-project_id')
try:
account_profile = AccountProfile.objects.get(user=current_user)
employee = account_profile.employee_information
except AccountProfile.DoesNotExist:
return JsonResponse({'message': '您的账户未关联到员工信息,请联系管理员。'}, status=405)
# # 声明查询集,只显示当前用户作为主办人的记录
query_set = ProjectLedger.objects.filter(project_leader=employee.name).order_by('-project_id')
# query_set = ProjectLedger.objects.filter().order_by('-project_id')
# 获取查询参数
project_name = request.GET.get('project_name', '')

View File

@ -207,3 +207,18 @@ def thousands_separator(value):
return "{:,.2f}".format(value)
except (ValueError, TypeError):
return value
@register.filter
def mask_password(value):
if value:
return '' * 6
return '-'
@register.filter
def format_tax_rate(value):
try:
return f"{float(value)}%"
except (ValueError, TypeError):
return "-"