XH_Digital_Management/application/perf_mgnt/forms.py

77 lines
3.3 KiB
Python
Raw Normal View History

2024-06-19 10:39:14 +08:00
import datetime
2024-06-07 03:47:15 +08:00
from django import forms
2024-06-07 03:47:15 +08:00
from .models import *
from ..org_mgnt.models import PrimaryDepartment
2024-06-07 03:47:15 +08:00
class GroupBusinessTargetForm(forms.ModelForm):
2024-06-19 10:39:14 +08:00
current_year = datetime.datetime.now().year
2024-06-19 02:03:59 +08:00
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="一级部门"
)
2024-06-19 10:39:14 +08:00
year = forms.ChoiceField(
choices=[('', '---------')] + [(year, year) for year in range(current_year-1, current_year+2)],
widget=forms.Select(attrs={'class': 'form-control'}),
label="年份",
required=False
)
2024-06-07 03:47:15 +08:00
class Meta:
model = GroupBusinessTarget
fields = '__all__'
widgets = {
'project_nature': forms.Select(attrs={'class': 'form-control'}),
'sales': forms.NumberInput(attrs={'class': 'form-control'}),
'total_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
'new_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
'existing_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
'cost_limit': forms.NumberInput(attrs={'class': 'form-control'}),
'gross_profit': forms.NumberInput(attrs={'class': 'form-control'}),
'expense_limit': forms.NumberInput(attrs={'class': 'form-control'}),
'operating_profit': forms.NumberInput(attrs={'class': 'form-control'}),
}
def __init__(self, *args, **kwargs):
super(GroupBusinessTargetForm, self).__init__(*args, **kwargs)
def clean(self):
cleaned_data = super().clean()
primary_department = cleaned_data.get('primary_department')
year = cleaned_data.get('year')
project_nature = cleaned_data.get('project_nature')
if primary_department and year and project_nature:
if GroupBusinessTarget.objects.filter(primary_department=primary_department, year=year, project_nature=project_nature).exists():
raise forms.ValidationError("该一级部门在同一年已经有一个相同项目性质的业绩目标。")
return cleaned_data
2024-06-07 03:47:15 +08:00
class EmployeePerformanceTargetForm(forms.ModelForm):
2024-06-19 10:39:14 +08:00
department = forms.ChoiceField(
choices=[('', '---------')] + [(dept.department_name, dept.department_name) for dept in PrimaryDepartment.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="一级部门"
)
2024-06-07 03:47:15 +08:00
class Meta:
model = EmployeePerformanceTarget
fields = '__all__'
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control'}),
'year': forms.NumberInput(attrs={'class': 'form-control'}),
'project_nature': forms.Select(attrs={'class': 'form-control'}),
'sales_target': forms.NumberInput(attrs={'class': 'form-control'}),
'total_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
'new_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
'existing_revenue_target': forms.NumberInput(attrs={'class': 'form-control'}),
}
2024-06-19 10:39:14 +08:00
def __init__(self, *args, **kwargs):
super(EmployeePerformanceTargetForm, self).__init__(*args, **kwargs)