vkk.workhours.accounting.costs.forms
A collection of forms used throughout the costs
module.
1""" 2A collection of forms used throughout the `costs` module. 3""" 4 5from django import forms 6from vkk.workhours.models import ( 7 GeneralCosts, DepartmentDate, DepartmentCosts, 8 SalaryLevelDate, SalaryLevelCosts, ReceiptTemplate, 9 Department, SalaryLevel 10) 11from vkk.workhours.forms import CustomDateInput 12 13class DepartmentCostForm(forms.ModelForm): 14 """ 15 A `ModelForm` subclass for entering `DepartmentCost`s associated to a `DepartmentDate` (model). 16 """ 17 class Meta: 18 model = DepartmentDate 19 fields = ['date'] 20 widgets = { 21 'date': CustomDateInput(), 22 } 23 24 def __init__(self, *args, **kwargs): 25 """ 26 Initializes and returns an instance of this class. 27 """ 28 super().__init__(*args, **kwargs) 29 30 # Collect all associated departments to create fields 31 self._departments = Department.objects.all().order_by('name') 32 field_class = DepartmentCosts.equivalents_per_hour.field.formfield 33 for department in self._departments: 34 self.fields[ 35 'dep_' + str(department.accounting_entry) 36 ] = field_class( 37 label=department.name 38 ) 39 40 # Look for model instance and fill associated fields accordingly 41 if self.instance is not None: 42 department_cost_instances = DepartmentCosts.objects.filter( 43 start=self.instance 44 ).select_related('department') 45 for department_cost_instance in department_cost_instances: 46 self.fields[ 47 'dep_' + str( 48 department_cost_instance.department.accounting_entry 49 ) 50 ].initial = department_cost_instance.equivalents_per_hour 51 52 def save(self, commit=True): 53 """ 54 Attempts to save the associated data of this object to the database. 55 Returns the assocaiated `DepartmentDate` instance of this class. 56 """ 57 # save instance 58 super().save(commit) 59 # save all associated instances 60 if self.is_valid() and self.has_changed(): 61 department_costs_list = [] 62 for department in self._departments: 63 equivalents_per_hour = self.cleaned_data.get( 64 'dep_' + str(department.accounting_entry) 65 ) 66 department_costs_list.append( 67 DepartmentCosts( 68 department=department, 69 start=self.instance, 70 equivalents_per_hour=equivalents_per_hour, 71 ) 72 ) 73 DepartmentCosts.objects.bulk_create( 74 department_costs_list, 75 update_conflicts=True, 76 update_fields=['equivalents_per_hour'], 77 unique_fields=['department_id', 'start_id'] 78 ) 79 return self.instance 80 81class SalaryLevelCostForm(forms.ModelForm): 82 """ 83 A `ModelForm` subclass for entering `SalaryLevelCosts`s associated to a `SalaryLevelDate` (model). 84 """ 85 class Meta: 86 model = SalaryLevelDate 87 fields = ['date'] 88 widgets = { 89 'date': CustomDateInput(), 90 } 91 92 def __init__(self, *args, **kwargs): 93 """ 94 Initializes and returns an instance of this class. 95 """ 96 super().__init__(*args, **kwargs) 97 98 # Collect all associated departments to create fields 99 self._salary_levels = SalaryLevel.objects.all() 100 field_class = SalaryLevelCosts.brutto_per_hour.field.formfield 101 for salary_level in self._salary_levels: 102 self.fields[ 103 'sal_' + str(salary_level.salary_code) 104 ] = field_class( 105 label=salary_level.salary_code 106 ) 107 108 # Look for model instance and fill associated fields accordingly 109 if self.instance is not None: 110 salary_level_cost_instances = SalaryLevelCosts.objects.filter( 111 start=self.instance 112 ).select_related('salary_level') 113 for salary_level_cost_instance in salary_level_cost_instances: 114 self.fields[ 115 'sal_' + str( 116 salary_level_cost_instance.salary_level.salary_code 117 ) 118 ].initial = salary_level_cost_instance.brutto_per_hour 119 120 def save(self, commit=True): 121 """ 122 Attempts to save the associated data of this object to the database. 123 Returns the assocaiated `SalaryLevelDate` instance of this class. 124 """ 125 # save instance 126 super().save(commit) 127 # save all associated instances 128 if self.is_valid() and self.has_changed(): 129 salary_level_costs_list = [] 130 for salary_level in self._salary_levels: 131 brutto_per_hour = self.cleaned_data.get( 132 'sal_' + str(salary_level.salary_code) 133 ) 134 salary_level_costs_list.append( 135 SalaryLevelCosts( 136 salary_level=salary_level, 137 start=self.instance, 138 brutto_per_hour=brutto_per_hour, 139 ) 140 ) 141 SalaryLevelCosts.objects.bulk_create( 142 salary_level_costs_list, 143 update_conflicts=True, 144 update_fields=['brutto_per_hour'], 145 unique_fields=['salary_level_id', 'start_id'] 146 ) 147 return self.instance
class
DepartmentCostForm(django.forms.models.ModelForm):
14class DepartmentCostForm(forms.ModelForm): 15 """ 16 A `ModelForm` subclass for entering `DepartmentCost`s associated to a `DepartmentDate` (model). 17 """ 18 class Meta: 19 model = DepartmentDate 20 fields = ['date'] 21 widgets = { 22 'date': CustomDateInput(), 23 } 24 25 def __init__(self, *args, **kwargs): 26 """ 27 Initializes and returns an instance of this class. 28 """ 29 super().__init__(*args, **kwargs) 30 31 # Collect all associated departments to create fields 32 self._departments = Department.objects.all().order_by('name') 33 field_class = DepartmentCosts.equivalents_per_hour.field.formfield 34 for department in self._departments: 35 self.fields[ 36 'dep_' + str(department.accounting_entry) 37 ] = field_class( 38 label=department.name 39 ) 40 41 # Look for model instance and fill associated fields accordingly 42 if self.instance is not None: 43 department_cost_instances = DepartmentCosts.objects.filter( 44 start=self.instance 45 ).select_related('department') 46 for department_cost_instance in department_cost_instances: 47 self.fields[ 48 'dep_' + str( 49 department_cost_instance.department.accounting_entry 50 ) 51 ].initial = department_cost_instance.equivalents_per_hour 52 53 def save(self, commit=True): 54 """ 55 Attempts to save the associated data of this object to the database. 56 Returns the assocaiated `DepartmentDate` instance of this class. 57 """ 58 # save instance 59 super().save(commit) 60 # save all associated instances 61 if self.is_valid() and self.has_changed(): 62 department_costs_list = [] 63 for department in self._departments: 64 equivalents_per_hour = self.cleaned_data.get( 65 'dep_' + str(department.accounting_entry) 66 ) 67 department_costs_list.append( 68 DepartmentCosts( 69 department=department, 70 start=self.instance, 71 equivalents_per_hour=equivalents_per_hour, 72 ) 73 ) 74 DepartmentCosts.objects.bulk_create( 75 department_costs_list, 76 update_conflicts=True, 77 update_fields=['equivalents_per_hour'], 78 unique_fields=['department_id', 'start_id'] 79 ) 80 return self.instance
A ModelForm
subclass for entering DepartmentCost
s associated to a DepartmentDate
(model).
DepartmentCostForm(*args, **kwargs)
25 def __init__(self, *args, **kwargs): 26 """ 27 Initializes and returns an instance of this class. 28 """ 29 super().__init__(*args, **kwargs) 30 31 # Collect all associated departments to create fields 32 self._departments = Department.objects.all().order_by('name') 33 field_class = DepartmentCosts.equivalents_per_hour.field.formfield 34 for department in self._departments: 35 self.fields[ 36 'dep_' + str(department.accounting_entry) 37 ] = field_class( 38 label=department.name 39 ) 40 41 # Look for model instance and fill associated fields accordingly 42 if self.instance is not None: 43 department_cost_instances = DepartmentCosts.objects.filter( 44 start=self.instance 45 ).select_related('department') 46 for department_cost_instance in department_cost_instances: 47 self.fields[ 48 'dep_' + str( 49 department_cost_instance.department.accounting_entry 50 ) 51 ].initial = department_cost_instance.equivalents_per_hour
Initializes and returns an instance of this class.
def
save(self, commit=True):
53 def save(self, commit=True): 54 """ 55 Attempts to save the associated data of this object to the database. 56 Returns the assocaiated `DepartmentDate` instance of this class. 57 """ 58 # save instance 59 super().save(commit) 60 # save all associated instances 61 if self.is_valid() and self.has_changed(): 62 department_costs_list = [] 63 for department in self._departments: 64 equivalents_per_hour = self.cleaned_data.get( 65 'dep_' + str(department.accounting_entry) 66 ) 67 department_costs_list.append( 68 DepartmentCosts( 69 department=department, 70 start=self.instance, 71 equivalents_per_hour=equivalents_per_hour, 72 ) 73 ) 74 DepartmentCosts.objects.bulk_create( 75 department_costs_list, 76 update_conflicts=True, 77 update_fields=['equivalents_per_hour'], 78 unique_fields=['department_id', 'start_id'] 79 ) 80 return self.instance
Attempts to save the associated data of this object to the database.
Returns the assocaiated DepartmentDate
instance of this class.
Inherited Members
- django.forms.models.BaseModelForm
- clean
- validate_unique
- django.forms.forms.BaseForm
- default_renderer
- field_order
- prefix
- use_required_attribute
- template_name_div
- template_name_p
- template_name_table
- template_name_ul
- template_name_label
- is_bound
- data
- files
- auto_id
- initial
- error_class
- label_suffix
- empty_permitted
- fields
- renderer
- order_fields
- errors
- is_valid
- add_prefix
- add_initial_prefix
- template_name
- get_context
- non_field_errors
- add_error
- has_error
- full_clean
- has_changed
- changed_data
- is_multipart
- visible_fields
- get_initial_for_field
- django.forms.utils.RenderableFormMixin
- as_p
- as_table
- as_ul
- as_div
- django.forms.utils.RenderableMixin
- render
class
DepartmentCostForm.Meta:
18 class Meta: 19 model = DepartmentDate 20 fields = ['date'] 21 widgets = { 22 'date': CustomDateInput(), 23 }
model =
<class 'vkk.workhours.models.DepartmentDate'>
widgets =
{'date': <vkk.workhours.forms.CustomDateInput object>}
class
SalaryLevelCostForm(django.forms.models.ModelForm):
82class SalaryLevelCostForm(forms.ModelForm): 83 """ 84 A `ModelForm` subclass for entering `SalaryLevelCosts`s associated to a `SalaryLevelDate` (model). 85 """ 86 class Meta: 87 model = SalaryLevelDate 88 fields = ['date'] 89 widgets = { 90 'date': CustomDateInput(), 91 } 92 93 def __init__(self, *args, **kwargs): 94 """ 95 Initializes and returns an instance of this class. 96 """ 97 super().__init__(*args, **kwargs) 98 99 # Collect all associated departments to create fields 100 self._salary_levels = SalaryLevel.objects.all() 101 field_class = SalaryLevelCosts.brutto_per_hour.field.formfield 102 for salary_level in self._salary_levels: 103 self.fields[ 104 'sal_' + str(salary_level.salary_code) 105 ] = field_class( 106 label=salary_level.salary_code 107 ) 108 109 # Look for model instance and fill associated fields accordingly 110 if self.instance is not None: 111 salary_level_cost_instances = SalaryLevelCosts.objects.filter( 112 start=self.instance 113 ).select_related('salary_level') 114 for salary_level_cost_instance in salary_level_cost_instances: 115 self.fields[ 116 'sal_' + str( 117 salary_level_cost_instance.salary_level.salary_code 118 ) 119 ].initial = salary_level_cost_instance.brutto_per_hour 120 121 def save(self, commit=True): 122 """ 123 Attempts to save the associated data of this object to the database. 124 Returns the assocaiated `SalaryLevelDate` instance of this class. 125 """ 126 # save instance 127 super().save(commit) 128 # save all associated instances 129 if self.is_valid() and self.has_changed(): 130 salary_level_costs_list = [] 131 for salary_level in self._salary_levels: 132 brutto_per_hour = self.cleaned_data.get( 133 'sal_' + str(salary_level.salary_code) 134 ) 135 salary_level_costs_list.append( 136 SalaryLevelCosts( 137 salary_level=salary_level, 138 start=self.instance, 139 brutto_per_hour=brutto_per_hour, 140 ) 141 ) 142 SalaryLevelCosts.objects.bulk_create( 143 salary_level_costs_list, 144 update_conflicts=True, 145 update_fields=['brutto_per_hour'], 146 unique_fields=['salary_level_id', 'start_id'] 147 ) 148 return self.instance
A ModelForm
subclass for entering SalaryLevelCosts
s associated to a SalaryLevelDate
(model).
SalaryLevelCostForm(*args, **kwargs)
93 def __init__(self, *args, **kwargs): 94 """ 95 Initializes and returns an instance of this class. 96 """ 97 super().__init__(*args, **kwargs) 98 99 # Collect all associated departments to create fields 100 self._salary_levels = SalaryLevel.objects.all() 101 field_class = SalaryLevelCosts.brutto_per_hour.field.formfield 102 for salary_level in self._salary_levels: 103 self.fields[ 104 'sal_' + str(salary_level.salary_code) 105 ] = field_class( 106 label=salary_level.salary_code 107 ) 108 109 # Look for model instance and fill associated fields accordingly 110 if self.instance is not None: 111 salary_level_cost_instances = SalaryLevelCosts.objects.filter( 112 start=self.instance 113 ).select_related('salary_level') 114 for salary_level_cost_instance in salary_level_cost_instances: 115 self.fields[ 116 'sal_' + str( 117 salary_level_cost_instance.salary_level.salary_code 118 ) 119 ].initial = salary_level_cost_instance.brutto_per_hour
Initializes and returns an instance of this class.
def
save(self, commit=True):
121 def save(self, commit=True): 122 """ 123 Attempts to save the associated data of this object to the database. 124 Returns the assocaiated `SalaryLevelDate` instance of this class. 125 """ 126 # save instance 127 super().save(commit) 128 # save all associated instances 129 if self.is_valid() and self.has_changed(): 130 salary_level_costs_list = [] 131 for salary_level in self._salary_levels: 132 brutto_per_hour = self.cleaned_data.get( 133 'sal_' + str(salary_level.salary_code) 134 ) 135 salary_level_costs_list.append( 136 SalaryLevelCosts( 137 salary_level=salary_level, 138 start=self.instance, 139 brutto_per_hour=brutto_per_hour, 140 ) 141 ) 142 SalaryLevelCosts.objects.bulk_create( 143 salary_level_costs_list, 144 update_conflicts=True, 145 update_fields=['brutto_per_hour'], 146 unique_fields=['salary_level_id', 'start_id'] 147 ) 148 return self.instance
Attempts to save the associated data of this object to the database.
Returns the assocaiated SalaryLevelDate
instance of this class.
Inherited Members
- django.forms.models.BaseModelForm
- clean
- validate_unique
- django.forms.forms.BaseForm
- default_renderer
- field_order
- prefix
- use_required_attribute
- template_name_div
- template_name_p
- template_name_table
- template_name_ul
- template_name_label
- is_bound
- data
- files
- auto_id
- initial
- error_class
- label_suffix
- empty_permitted
- fields
- renderer
- order_fields
- errors
- is_valid
- add_prefix
- add_initial_prefix
- template_name
- get_context
- non_field_errors
- add_error
- has_error
- full_clean
- has_changed
- changed_data
- is_multipart
- visible_fields
- get_initial_for_field
- django.forms.utils.RenderableFormMixin
- as_p
- as_table
- as_ul
- as_div
- django.forms.utils.RenderableMixin
- render
class
SalaryLevelCostForm.Meta:
86 class Meta: 87 model = SalaryLevelDate 88 fields = ['date'] 89 widgets = { 90 'date': CustomDateInput(), 91 }
model =
<class 'vkk.workhours.models.SalaryLevelDate'>
widgets =
{'date': <vkk.workhours.forms.CustomDateInput object>}