Skip to content

Commit

Permalink
[Issue #174] several adjustment to fix issues created by the massive …
Browse files Browse the repository at this point in the history
…change in the models. started to create the calculations for the final presentation of the planned vs effective chart
  • Loading branch information
scaphilo committed Sep 14, 2018
1 parent 5c2d57f commit 4d7b749
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 68 deletions.
4 changes: 4 additions & 0 deletions koalixcrm/crm/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from koalixcrm.crm.reporting.task import Task, TaskAdminView
from koalixcrm.crm.reporting.task_link_type import TaskLinkType, OptionTaskLinkType
from koalixcrm.crm.reporting.task_status import TaskStatus, OptionTaskStatus
from koalixcrm.crm.reporting.estimation_status import EstimationStatus, EstimationStatusAdminView
from koalixcrm.crm.reporting.agreement_status import AgreementStatus, AgreementStatusAdminView
from koalixcrm.crm.reporting.resource_type import ResourceType, ResourceTypeAdminView
from koalixcrm.crm.reporting.human_resource import HumanResource, HumanResourceAdminView
from koalixcrm.crm.reporting.resource_manager import ResourceManager, ResourceManagerAdminView
Expand Down Expand Up @@ -57,6 +59,8 @@
admin.site.register(Task, TaskAdminView)
admin.site.register(TaskLinkType, OptionTaskLinkType)
admin.site.register(TaskStatus, OptionTaskStatus)
admin.site.register(EstimationStatus, EstimationStatusAdminView)
admin.site.register(AgreementStatus, AgreementStatusAdminView)
admin.site.register(Work, WorkAdminView)
admin.site.register(HumanResource, HumanResourceAdminView)
admin.site.register(ResourceType, ResourceTypeAdminView)
Expand Down
36 changes: 19 additions & 17 deletions koalixcrm/crm/reporting/agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class Agreement(models.Model):
resource = models.ForeignKey("Resource")
unit = models.ForeignKey("Unit")
costs = models.ForeignKey(ResourcePrice)
agreement_type = models.ForeignKey("AgreementType")
agreement_status = models.ForeignKey("AgreementStatus")
agreement_from = models.DateField(verbose_name=_("Agreement From"),
blank=False,
null=False)
agreement_to = models.DateField(verbose_name=_("Agreement To"),
blank=False,
null=False)
agreement_amount = models.DecimalField(verbose_name=_("Amount"),
max_digits=5,
decimal_places=2,
blank=True,
null=True)
type = models.ForeignKey("AgreementType")
status = models.ForeignKey("AgreementStatus")
date_from = models.DateField(verbose_name=_("Agreement From"),
blank=False,
null=False)
date_until = models.DateField(verbose_name=_("Agreement To"),
blank=False,
null=False)
amount = models.DecimalField(verbose_name=_("Amount"),
max_digits=5,
decimal_places=2,
blank=True,
null=True)

def calculated_costs(self):
currency = self.task.project.default_currency
Expand All @@ -35,7 +35,7 @@ def calculated_costs(self):
self.product.get_costs(self, date, unit, currency)

def __str__(self):
return _("Estimation of Resource Consumption") + ": " + str(self.id)
return _("Agreement of Resource Consumption") + ": " + str(self.id)

class Meta:
app_label = "crm"
Expand All @@ -49,9 +49,11 @@ class AgreementInlineAdminView(admin.TabularInline):
(_('Work'), {
'fields': ('task',
'resource',
'agreement_amount',
'agreement_from',
'agreement_to')
'amount',
'date_from',
'date_until',
'type',
'status')
}),
)
extra = 1
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/agreement_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __str__(self):
return str(self.id) + " " + str(self.title)


class OptionProjectStatus(admin.ModelAdmin):
class AgreementStatusAdminView(admin.ModelAdmin):
list_display = ('id',
'title',
'description',
Expand Down
40 changes: 25 additions & 15 deletions koalixcrm/crm/reporting/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ class Estimation(models.Model):
blank=False,
null=False)
resource = models.ForeignKey("Resource")
estimation_from = models.DateField(verbose_name=_("Estimation From"),
blank=False,
null=False)
estimation_to = models.DateField(verbose_name=_("Estimation To"),
blank=False,
null=False)
estimation_amount = models.DecimalField(verbose_name=_("Amount"),
max_digits=5,
decimal_places=2,
blank=True,
null=True)
date_from = models.DateField(verbose_name=_("Estimation From"),
blank=False,
null=False)
date_until = models.DateField(verbose_name=_("Estimation To"),
blank=False,
null=False)
amount = models.DecimalField(verbose_name=_("Amount"),
max_digits=5,
decimal_places=2,
blank=True,
null=True)
status = models.ForeignKey("EstimationStatus",
verbose_name=_('Status of the estimation'),
blank=False,
null=False)
reporting_period = models.ForeignKey("ReportingPeriod",
verbose_name=_('Reporting Period based on which the estimation was done'),
blank=False,
null=False)

def calculated_costs(self):
currency = self.task.project.default_currency
unit = Unit.objects.filter(short_name="hrs")
date = self.estimation_from
date = self.date_from

self.product.get_costs(self, unit, date, currency)

Expand All @@ -46,9 +54,11 @@ class EstimationInlineAdminView(admin.TabularInline):
(_('Work'), {
'fields': ('task',
'resource',
'estimation_amount',
'estimation_from',
'estimation_to')
'amount',
'date_from',
'date_until',
'status',
'reporting_period')
}),
)
extra = 1
49 changes: 49 additions & 0 deletions koalixcrm/crm/reporting/estimation_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext as _
from django.contrib import admin
from rest_framework import serializers


class EstimationStatus(models.Model):
title = models.CharField(verbose_name=_("Title"),
max_length=250,
blank=False,
null=False)
description = models.TextField(verbose_name=_("Text"),
blank=True,
null=True)
is_obsolete = models.BooleanField(verbose_name=_("Status represents estimation is obsolete"),)

class Meta:
app_label = "crm"
verbose_name = _('Estimation Status')
verbose_name_plural = _('Estimation Status')

def __str__(self):
return str(self.id) + " " + str(self.title)


class EstimationStatusAdminView(admin.ModelAdmin):
list_display = ('id',
'title',
'description',
'is_obsolete')

fieldsets = (
(_('Agreement Status'), {
'fields': ('title',
'description',
'is_obsolete')
}),
)
save_as = True


class EstimationStatusJSONSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = EstimationStatus
fields = ('id',
'title',
'description',)
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/generic_project_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Meta:
verbose_name_plural = _('Project Links')


class InlineGenericLinks(admin.TabularInline):
class GenericLinkInlineAdminView(admin.TabularInline):
model = GenericProjectLink
readonly_fields = ('project_link_type',
'content_type',
Expand Down
3 changes: 3 additions & 0 deletions koalixcrm/crm/reporting/human_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class HumanResource(Resource):
user = models.ForeignKey(UserExtension,
verbose_name=_("User"))

def __str__(self):
return self.user.__str__()

def serialize_to_xml(self, **kwargs):
date_from = kwargs.get('date_from', datetime.date.today()-datetime.timedelta(days=60))
date_to = kwargs.get('date_to', datetime.date.today())
Expand Down
80 changes: 62 additions & 18 deletions koalixcrm/crm/reporting/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django.contrib import admin
from django.utils.translation import ugettext as _
from django.utils.html import format_html
from koalixcrm.crm.reporting.generic_project_link import InlineGenericLinks
from koalixcrm.crm.reporting.generic_project_link import GenericLinkInlineAdminView
from koalixcrm.crm.reporting.reporting_period import ReportingPeriodInlineAdminView
from koalixcrm.crm.reporting.task import TaskInlineAdminView
from koalixcrm.crm.documents.pdf_export import PDFExport
from koalixcrm.crm.exceptions import TemplateSetMissingInContract
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_xsl_file(self, template_set):

def get_reporting_period(self, search_date):
from koalixcrm.crm.reporting.reporting_period import ReportingPeriod
"""Returns the reporting period that is currently valid. Valid is a reporting period when the provided date
"""Returns the reporting period that is valid. Valid is a reporting period when the provided date
lies between begin and end of the reporting period
Args:
Expand Down Expand Up @@ -109,7 +110,7 @@ def serialize_to_xml(self, **kwargs):
main_xml = PDFExport.append_element_to_pattern(main_xml,
"object/[@model='crm.project']",
"Planned_Effort",
self.planned_effort())
self.planned_costs())
main_xml = PDFExport.append_element_to_pattern(main_xml,
"object/[@model='crm.project']",
"Effective_Duration",
Expand All @@ -120,24 +121,39 @@ def serialize_to_xml(self, **kwargs):
self.planned_duration())
return main_xml

def effective_effort_overall(self):
return self.effective_effort(reporting_period=None)
effective_effort_overall.short_description = _("Effective Effort [hrs]")
effective_effort_overall.tags = True
def effective_accumulated_costs(self, reporting_period=None):
effective_effort_accumulated = 0
for task in Task.objects.filter(project=self.id):
effective_effort_accumulated += task.effective_acucumulated_costs(reporting_period=reporting_period)
return effective_effort_accumulated
effective_accumulated_costs.short_description = _("Effective Effort [hrs]")
effective_accumulated_costs.tags = True

def effective_effort(self, reporting_period):
effective_effort_accumulated = 0
for task in Task.objects.filter(project=self.id):
effective_effort_accumulated += task.effective_effort(reporting_period=reporting_period)
return effective_effort_accumulated

def planned_effort(self):
planned_effort_accumulated = 0
for task in Task.objects.filter(project=self.id):
planned_effort_accumulated += task.planned_costs()
def planned_costs(self, reporting_period=None):
"""The function return the planned overall costs
Args:
no arguments
Returns:
planned costs (String)
Raises:
No exceptions planned"""
planned_effort_accumulated = "0"
all_project_tasks = Task.objects.filter(project=self.id)
if all_project_tasks:
for task in all_project_tasks:
planned_effort_accumulated += task.planned_costs(reporting_period)
return planned_effort_accumulated
planned_effort.short_description = _("Planned Effort [hrs]")
planned_effort.tags = True
planned_costs.short_description = _("Planned Costs")
planned_costs.tags = True

def effective_start(self):
"""The function return the effective start of a project as a date
Expand Down Expand Up @@ -236,10 +252,23 @@ def effective_duration(self):
effective_duration.tags = True

def planned_start(self):
""" The function return planned overall start of a project as a date
the function finds all tasks within this project and finds the earliest start date.
when no task is attached the task has which are attached have no start_date set, the
function returns a None value
Args:
no arguments
Returns:
planned_end (datetime.Date) or None
Raises:
No exceptions planned"""
tasks = Task.objects.filter(project=self.id)
if tasks:
i = 0
project_start = datetime.today()
project_start = None
for task in tasks:
if task.planned_start():
if i == 0:
Expand All @@ -252,10 +281,23 @@ def planned_start(self):
return None

def planned_end(self):
"""T he function return planned overall end of a project as a date
the function finds all tasks within this project and finds the latest start end_date.
when no task is attached the task has which are attached have no end_date set, the
function returns a None value
Args:
no arguments
Returns:
planned_end (datetime.Date)
Raises:
No exceptions planned"""
tasks = Task.objects.filter(project=self.id)
if tasks:
i = 0
project_end = datetime.today()
project_end = None
for task in tasks:
if task.planned_end():
if i == 0:
Expand Down Expand Up @@ -345,7 +387,7 @@ class ProjectAdminView(admin.ModelAdmin):
'default_currency',
'effective_effort_overall',
'planned_duration',
'effective_duration')
'effective_duration',)

list_display_links = ('id',)
ordering = ('-id',)
Expand All @@ -357,11 +399,13 @@ class ProjectAdminView(admin.ModelAdmin):
'project_name',
'description',
'default_currency',
'default_template_set')
'default_template_set',)
}),
)

inlines = [TaskInlineAdminView, InlineGenericLinks]
inlines = [TaskInlineAdminView,
GenericLinkInlineAdminView,
ReportingPeriodInlineAdminView]
actions = ['create_report_pdf', ]

def save_model(self, request, obj, form, change):
Expand Down
3 changes: 1 addition & 2 deletions koalixcrm/crm/reporting/reporting_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def create_report_pdf(self, request, queryset):
create_report_pdf.short_description = _("Create Report PDF")


class InlineReportingPeriod(admin.TabularInline):
class ReportingPeriodInlineAdminView(admin.TabularInline):
model = ReportingPeriod
fieldsets = (
(_('ReportingPeriod'), {
Expand All @@ -206,7 +206,6 @@ class InlineReportingPeriod(admin.TabularInline):
'status')
}),
)
extra = 0

def has_add_permission(self, request):
return False
Expand Down
9 changes: 9 additions & 0 deletions koalixcrm/crm/reporting/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ class Resource(models.Model):
verbose_name=_("Resource Type"),
blank=True,
null=True)

def __str__(self):
from koalixcrm.crm.reporting.human_resource import HumanResource
human_resource = HumanResource.objects.get(id=self.id)
if human_resource:
return human_resource.__str__()
else:
return "Resource"

Loading

0 comments on commit 4d7b749

Please sign in to comment.