Test coverage report: payslip.models

# payslip.models: 49 total statements, 100.0% covered

Generated: Sun 2014-11-09 09:00 CET

Source file: /home/tobi/Projects/django-payslip/src/payslip/models.py

Stats: 32 executed, 0 missed, 17 excluded, 208 ignored

1. `"""Models for the ``payslip`` application."""`
2. `from django.db import models`
3. `from django.utils.timezone import now`
4. `from django.utils.translation import ugettext_lazy as _`
5. ``
6. ``
7. `class Company(models.Model):`
8. `"""`
9. `Model, which holds general information of a company.`
10. ``
11. `:name: Name of the company.`
12. `:address: Full address model fields.`
13. `:extra_fields: Custom fields to hold more information.`
14. ``
15. `"""`
16. `name = models.CharField(`
17. `max_length=100,`
18. `verbose_name=_('Name'),`
19. `)`
20. ``
21. `address = models.TextField(`
22. `verbose_name=_('Address'),`
23. `blank=True, null=True,`
24. `)`
25. ``
26. `extra_fields = models.ManyToManyField(`
27. `'payslip.ExtraField',`
28. `verbose_name=_('Extra fields'),`
29. `blank=True, null=True,`
30. `)`
31. ``
32. `def __unicode__(self):`
33. `return '{0}'.format(self.name)`
34. ``
35. ``
36. `class Employee(models.Model):`
37. `"""`
38. `Model, which holds personal information of employee.`
39. ``
40. `:user: Connection to the django user model, to allow a login.`
41. `:company: Connection to the employee's company.`
42. `:hr_number: ID to connect some non-digital documents or to use as a`
43. `reference.`
44. `:address: Full address model fields.`
45. `:title: Title of the employee.`
46. `:extra_fields: Custom fields like e.g. confession, tax class.`
47. ``
48. `"""`
49. `user = models.ForeignKey(`
50. `'auth.User',`
51. `verbose_name=_('User'),`
52. `related_name='employees',`
53. `)`
54. ``
55. `company = models.ForeignKey(`
56. `'payslip.Company',`
57. `verbose_name=_('Company'),`
58. `related_name='employees',`
59. `)`
60. ``
61. `hr_number = models.PositiveIntegerField(`
62. `verbose_name=_('HR number'),`
63. `blank=True, null=True,`
64. `)`
65. ``
66. `address = models.TextField(`
67. `verbose_name=_('Address'),`
68. `blank=True, null=True,`
69. `)`
70. ``
71. `title = models.CharField(`
72. `max_length=1,`
73. `verbose_name=_('Title'),`
74. `choices=(`
75. `('1', 'Ms.'),`
76. `('2', 'Mrs.'),`
77. `('3', 'Mr.'),`
78. `('4', 'Dr.'),`
79. `)`
80. `)`
81. ``
82. `extra_fields = models.ManyToManyField(`
83. `'payslip.ExtraField',`
84. `verbose_name=_('Extra fields'),`
85. `blank=True, null=True,`
86. `)`
87. ``
88. `is_manager = models.BooleanField(`
89. `default=False,`
90. `verbose_name=_('is Manager'),`
91. `)`
92. ``
93. `def __unicode__(self):`
94. `return '{0} {1}'.format(self.user.first_name, self.user.last_name)`
95. ``
96. ``
97. `class ExtraFieldType(models.Model):`
98. `"""`
99. `Model to create custom information holders.`
100. ``
101. `:name: Name of the attribute.`
102. `:description: Description of the attribute.`
103. `:model: Can be set in order to allow the use of only one model.`
104. `:fixed_values: Can transform related exta fields into choices.`
105. ``
106. `"""`
107. `name = models.CharField(`
108. `max_length=100,`
109. `verbose_name=_('Name'),`
110. `)`
111. ``
112. `description = models.CharField(`
113. `max_length=100,`
114. `blank=True, null=True,`
115. `verbose_name=_('Description'),`
116. `)`
117. ``
118. `model = models.CharField(`
119. `max_length=10,`
120. `choices=(`
121. `('Employee', 'Employee'),`
122. `('Payment', 'Payment'),`
123. `('Company', 'Company'),`
124. `),`
125. `verbose_name=_('Model'),`
126. `blank=True, null=True,`
127. `)`
128. ``
129. `fixed_values = models.BooleanField(`
130. `default=False,`
131. `verbose_name=_('Fixed values'),`
132. `)`
133. ``
134. `def __unicode__(self):`
135. `return '{0}'.format(self.name)`
136. ``
137. ``
138. `class ExtraField(models.Model):`
139. `"""`
140. `Model to create custom fields.`
141. ``
142. `:field_type: Connection to the field type.`
143. `:value: Current value of this extra field.`
144. ``
145. `"""`
146. `field_type = models.ForeignKey(`
147. `'payslip.ExtraFieldType',`
148. `verbose_name=_('Field type'),`
149. `related_name='extra_fields',`
150. `help_text=_('Only field types with fixed values can be chosen to add'`
151. `' global values.'),`
152. `)`
153. ``
154. `value = models.CharField(`
155. `max_length=200,`
156. `verbose_name=_('Value'),`
157. `)`
158. ``
159. `def __unicode__(self):`
160. `return '{0} ({1}) - {2}'.format(`
161. `self.field_type, self.field_type.get_model_display() or 'general',`
162. `self.value)`
163. ``
164. ``
165. `class PaymentType(models.Model):`
166. `"""`
167. `Model to create payment types.`
168. ``
169. `:name: Name of the type.`
170. `:rrule: Recurring rule setting.`
171. `:description: Description of the type.`
172. ``
173. `"""`
174. `name = models.CharField(`
175. `max_length=100,`
176. `verbose_name=_('Name'),`
177. `)`
178. ``
179. `rrule = models.CharField(`
180. `max_length=10,`
181. `verbose_name=_('Recurring rule'),`
182. `blank=True,`
183. `choices=(`
184. `('MONTHLY', _('Monthly')),`
185. `('YEARLY', _('Yearly')),`
186. `)`
187. `)`
188. ``
189. `description = models.CharField(`
190. `max_length=100,`
191. `blank=True, null=True,`
192. `verbose_name=_('Description'),`
193. `)`
194. ``
195. `def __unicode__(self):`
196. `if self.rrule:`
197. `return '{0} ({1})'.format(self.name, self.get_rrule_display())`
198. `return '{0}'.format(self.name)`
199. ``
200. ``
201. `class Payment(models.Model):`
202. `"""`
203. `Model, which represents one single payment.`
204. ``
205. `:payment_type: Type of the payment.`
206. `:employee: Connection to the payment receiver.`
207. `:amount: Current amount of the payment.`
208. `:date: Date the payment should accrue.`
209. `:end_date: Optional end date, if payment type has a rrule.`
210. `:extra_fields: Custom fields like e.g. quantity, bonus.`
211. ``
212. `"""`
213. `payment_type = models.ForeignKey(`
214. `'payslip.PaymentType',`
215. `verbose_name=_('Payment type'),`
216. `related_name='payments',`
217. `)`
218. ``
219. `employee = models.ForeignKey(`
220. `'payslip.Employee',`
221. `verbose_name=_('Employee'),`
222. `related_name='payments',`
223. `)`
224. ``
225. `amount = models.DecimalField(`
226. `decimal_places=2,`
227. `max_digits=10,`
228. `verbose_name=_('Amount'),`
229. `)`
230. ``
231. `date = models.DateTimeField(`
232. `verbose_name=_('Date'),`
233. `default=now().today(),`
234. `)`
235. ``
236. `end_date = models.DateTimeField(`
237. `verbose_name=_('End of recurring period'),`
238. `blank=True, null=True,`
239. `help_text=_('This field is only considered, if the payment type has a'`
240. `' recurring rule.'),`
241. `)`
242. ``
243. `extra_fields = models.ManyToManyField(`
244. `'payslip.ExtraField',`
245. `verbose_name=_('Extra fields'),`
246. `blank=True, null=True,`
247. `)`
248. ``
249. `description = models.CharField(`
250. `max_length=100,`
251. `blank=True, null=True,`
252. `verbose_name=_('Description'),`
253. `)`
254. ``
255. `def __unicode__(self):`
256. `return '{0} - {1} ({2})'.format(self.payment_type, self.amount,`
257. `self.employee)`