XH_Digital_Management/application/perf_mgnt/forms.py

68 lines
2.9 KiB
Python

import datetime
from django import forms
from .models import *
from ..org_mgnt.models import PrimaryDepartment
class GroupBusinessTargetForm(forms.ModelForm):
class Meta:
model = GroupBusinessTarget
fields = '__all__'
widgets = {
'project_nature': forms.Select(attrs={'class': 'form-control'}),
'year': forms.TextInput(attrs={'class': 'form-control', 'type': 'year'}),
'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)
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="一级部门"
)
for field_name in self.fields:
if field_name not in ['primary_department', 'year', 'sales']:
self.fields[field_name].required = False
class EmployeePerformanceTargetForm(forms.ModelForm):
class Meta:
model = EmployeePerformanceTarget
fields = '__all__'
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control'}),
'year': forms.TextInput(attrs={'class': 'form-control', 'type': 'year'}),
'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'}),
}
def __init__(self, *args, **kwargs):
super(EmployeePerformanceTargetForm, self).__init__(*args, **kwargs)
self.fields['department'] = forms.ChoiceField(
choices=[('', '---------')] + [(dept.department_name, dept.department_name) for dept in
PrimaryDepartment.objects.all()],
widget=forms.Select(attrs={'class': 'form-control'}),
label="一级部门"
)
for field_name in self.fields:
if field_name not in ['department', 'name', 'year']:
self.fields[field_name].required = False