Test coverage report: payslip.models

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

Generated: Mon 2014-11-10 12:51 CET

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

Stats: 50 executed, 0 missed, 17 excluded, 218 ignored

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