Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Commit 62ceb4c

Browse files
committed
[Issue KoalixSwitzerland#174] continued with the development of the feature
1 parent 43e2555 commit 62ceb4c

File tree

12 files changed

+113
-31
lines changed

12 files changed

+113
-31
lines changed
+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
.. highlight:: rst
2-
31
Code Documentation
42
==================
53

6-
.. automodule:: koalixcrm.crm.reporting.task
7-
:members:
4+
.. toctree::
5+
:maxdepth: 2
86

7+
code_documentation/project
8+
code_documentation/task
9+
code_documentation/work
10+
code_documentation/estimation
11+
code_documentation/agreement
12+
code_documentation/resource
913

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Agreement
4+
---------
5+
6+
.. automodule:: koalixcrm.crm.reporting.agreement
7+
:members:
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Estimation
4+
----------
5+
6+
.. automodule:: koalixcrm.crm.reporting.estimation
7+
:members:
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Project
4+
-------
5+
6+
.. automodule:: koalixcrm.crm.reporting.project
7+
:members:
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Resource
4+
--------
5+
6+
.. automodule:: koalixcrm.crm.reporting.resource
7+
:members:
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Task
4+
----
5+
6+
.. automodule:: koalixcrm.crm.reporting.task
7+
:members:
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. highlight:: rst
2+
3+
Work
4+
----
5+
6+
.. automodule:: koalixcrm.crm.reporting.work
7+
:members:
8+

koalixcrm/crm/documents/invoice.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def link_to_invoice(self):
3131
return format_html("<a href='/admin/crm/invoice/%s' >%s</a>" % (str(self.id), str(self.description)))
3232
else:
3333
return "Not present"
34-
link_to_invoice.short_description = _("Invoice");
34+
link_to_invoice.short_description = _("Invoice")
3535

3636
def create_from_reference(self, calling_model):
3737
self.create_sales_document(calling_model)
@@ -52,7 +52,7 @@ def register_invoice_in_accounting(self, request):
5252
if not self.is_complete_with_price():
5353
raise IncompleteInvoice(_("Complete invoice and run price recalculation. Price may not be Zero"))
5454
if len(activa_account) == 0:
55-
raise OpenInterestAccountMissing(_("Please specify one open intrest account in the accounting"))
55+
raise OpenInterestAccountMissing(_("Please specify one open interest account in the accounting"))
5656
for position in list(SalesDocumentPosition.objects.filter(sales_document=self.id)):
5757
profit_account = position.product.accounting_product_categorie.profitAccount
5858
dict_prices[profit_account] = position.last_calculated_price
@@ -103,7 +103,7 @@ class OptionInvoice(OptionSalesDocument):
103103
search_fields = OptionSalesDocument.search_fields
104104
fieldsets = OptionSalesDocument.fieldsets + (
105105
(_('Invoice specific'), {
106-
'fields': ( 'payable_until', 'status', 'payment_bank_reference' )
106+
'fields': ('payable_until', 'status', 'payment_bank_reference' )
107107
}),
108108
)
109109

koalixcrm/crm/reporting/agreement.py

+21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ def calculated_costs(self):
3232
currency = self.task.project.default_currency
3333
return 0
3434

35+
def match_with_work(self, work):
36+
"""This method checks whether the provided work can be covered by the agreement.
37+
the method checks whether the reported work corresponds with the resource and whether the
38+
reported work was within the time-frame of the agreement.
39+
The method returns False when the Agreement is not yet in status agreed
40+
41+
Args:
42+
work (koalixcrm.crm.reporting.work.Work)
43+
44+
Returns:
45+
True when no ValidationError was raised
46+
47+
Raises:
48+
should not raise exceptions"""
49+
matches = False
50+
if self.status.is_agreed:
51+
if (work.date >= self.date_from) and (work.date <= self.date_until):
52+
if self.resource.id == work.human_resource.id:
53+
matches = True
54+
return matches
55+
3556
def __str__(self):
3657
return _("Agreement of Resource Consumption") + ": " + str(self.id)
3758

koalixcrm/crm/reporting/task.py

+31-20
Original file line numberDiff line numberDiff line change
@@ -329,40 +329,51 @@ def effective_costs(self, reporting_period=None):
329329
"""
330330
agreements = Agreement.objects.filter(task=self)
331331
if reporting_period:
332-
work_objects = Work.objects.filter(task=self.id,
333-
reporting_period=reporting_period)
332+
all_work_in_task = Work.objects.filter(task=self.id,
333+
reporting_period=reporting_period)
334334
else:
335-
work_objects = Work.objects.filter(task=self.id)
336-
sum_seconds = 0
337-
effort_in_seconds = 0
335+
all_work_in_task = Work.objects.filter(task=self.id)
338336
sum_costs = 0
337+
work_with_agreement = list()
338+
work_without_agreement = list()
339+
work_calculated = list()
339340
human_resource_list = dict()
340-
for work_object in work_objects:
341-
effort_in_seconds += work_object.effort_seconds()
342-
sum_seconds += effort_in_seconds
341+
for work_object in all_work_in_task:
343342
if work_object.human_resource not in human_resource_list:
344343
human_resource_list[work_object.human_resource] = dict()
345344
for agreement in agreements:
346-
agreement_matches = True
347-
"""agreement.matches_with(work_object)"""
345+
agreement_matches = agreement.match_with_work(work_object)
348346
if agreement_matches:
347+
if work_object not in work_with_agreement:
348+
work_with_agreement.append(work_object)
349349
if agreement not in human_resource_list.get(work_object.human_resource):
350350
human_resource_list.get(work_object.human_resource)[agreement] = list()
351351
human_resource_list.get(work_object.human_resource).get(agreement).append(work_object)
352-
covered_work = list()
352+
if work_object not in work_with_agreement:
353+
work_without_agreement.append(work_object)
354+
353355
for human_resource_dict in human_resource_list:
354356
agreement_list = Agreement.objects.filter(task=self, resource=human_resource_dict).order_by('costs__price')
355357
for agreement in agreement_list:
356358
agreement_remaining_amount = agreement.amount
357-
for work in human_resource_list[human_resource_dict].get(agreement):
358-
if work not in covered_work:
359-
if (agreement_remaining_amount - work.worked_hours) > 0:
360-
agreement_remaining_amount -= work.worked_hours
361-
sum_costs += work.worked_hours*agreement.costs.price.price
362-
covered_work.append(work)
363-
for work in work_objects:
364-
if work not in covered_work:
365-
sum_costs += work.worked_hours*ResourcePrice.objects.get(work.human_resource).price
359+
if human_resource_list[human_resource_dict].get(agreement):
360+
for work in human_resource_list[human_resource_dict].get(agreement):
361+
if work in work_with_agreement:
362+
if (agreement_remaining_amount - work.worked_hours) > 0:
363+
agreement_remaining_amount -= work.worked_hours
364+
sum_costs += work.worked_hours*agreement.costs.price
365+
work_calculated.append(work)
366+
for work in all_work_in_task:
367+
if work not in work_calculated:
368+
if work not in work_without_agreement:
369+
work_without_agreement.append(work)
370+
for work in work_without_agreement:
371+
default_resource_price = ResourcePrice.objects.get(id=work.human_resource.id)
372+
if default_resource_price:
373+
sum_costs += work.worked_hours*default_resource_price.price
374+
else:
375+
sum_costs = "n/a"
376+
break
366377
return sum_costs.__str__()
367378
effective_costs.short_description = _("Effective costs")
368379
effective_costs.tags = True

koalixcrm/crm/reporting/work.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ def __str__(self):
9494
return _("Work") + ": " + str(self.id) + " " + _("from Person") + ": " + str(self.human_resource.id)
9595

9696
def check_working_hours(self):
97-
"""This method checks that the working hour is correctly proved either using the start_stop pattern
97+
"""This method checks that the working hour is correctly provided either using the start_stop pattern
9898
or by providing the worked_hours in total.
9999
100100
Args:
101-
cleaned_data (Dict): The cleaned_data must contain the values form the form validation.
102-
The django built in form validation must already have been passed
103101
104102
Returns:
105103
True when no ValidationError was raised

requirements/base_requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ django-filebrowser==3.9.1
33
lxml==3.8.0
44
olefile==0.44
55
Pillow==4.2.1
6-
psycopg2==2.7.3
6+
psycopg2-binary==2.7.3
77
pytz==2017.2
88
django-grappelli==2.10.1
99
djangorestframework==3.7.7

0 commit comments

Comments
 (0)