Skip to content

Commit

Permalink
[Issue #174] sketched use of agreement and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
scaphilo committed Sep 12, 2018
1 parent c975630 commit 662e8fd
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 34 deletions.
2 changes: 1 addition & 1 deletion koalixcrm/crm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from koalixcrm.crm.product.tax import *
from koalixcrm.crm.product.unit import *

from koalixcrm.crm.reporting.estimation_of_resource_consumption import *
from koalixcrm.crm.reporting.agreement import *
from koalixcrm.crm.reporting.generic_task_link import *
from koalixcrm.crm.reporting.task import *
from koalixcrm.crm.reporting.task_link_type import *
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/product/product_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProductType(models.Model):
title = models.CharField(verbose_name=_("Title"),
max_length=200)
product_identifier = models.CharField(verbose_name=_("Product Number"),
max_lenghth=200,
max_length=200,
null=True,
blank=True)
default_unit = models.ForeignKey("Unit", verbose_name=_("Unit"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext as _
from django.forms import ValidationError
from django.contrib import admin
from django.utils.html import format_html
from django.utils.translation import ugettext as _
from koalixcrm.crm.documents.pdf_export import PDFExport
from koalixcrm.global_support_functions import *
from koalixcrm.crm.exceptions import ReportingPeriodDoneDeleteNotPossible
from django.contrib import messages


class EstimationOfResourceConsumption(models.Model):
class Agreement(models.Model):
task = models.ForeignKey("Task",
verbose_name=_('Task'),
blank=False,
null=False)
product = models.ForeignKey("Product",
verbose_name="Resource Type",
blank=False,
null=False)
reporting_period = models.ForeignKey("ReportingPeriod",
verbose_name="Reporting Period",
blank=False,
null=False)
amount = models.DecimalField(verbose_name=_("Estimated Amount"),
max_digits=10,
decimal_places=2,
blank=True,
null=True)
start_date = models.DateField(verbose_name=_("Estimated Start"),
blank=True,
null=True)
end_date = models.DateField(verbose_name=_("Estimated End"),
blank=True,
null=True)
resource = models.ForeignKey("Resource")
resource_manager = models.ForeignKey("ResourceManager")
unit = models.ForeignKey("Unit")
costs = models.ForeignKey("Cost")
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)

def calculated_costs(self):
currency = self.task.project.default_currency
Expand Down
49 changes: 49 additions & 0 deletions koalixcrm/crm/reporting/agreement_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 AgreementStatus(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_agreed = models.BooleanField(verbose_name=_("Status represents agreement exists"),)

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

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


class OptionProjectStatus(admin.ModelAdmin):
list_display = ('id',
'title',
'description',
'is_agreed')

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


class AgreementStatusJSONSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = AgreementStatus
fields = ('id',
'title',
'description',)
32 changes: 32 additions & 0 deletions koalixcrm/crm/reporting/agreement_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

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


class AgreementType(models.Model):
title = models.CharField(verbose_name=_("Title"), max_length=300, blank=False, null=False)
description = models.TextField(verbose_name=_("Text"), blank=True, null=True)

class Meta:
app_label = "crm"
verbose_name = _('Agreement Type')
verbose_name_plural = _('Agreement Type')

def __str__(self):
return _("Agreement Type") + " ID: " + str(self.id) + " title: " + str(self.title)


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

fieldsets = (
(_('AgreementType'), {
'fields': ('title',
'description')
}),
)
save_as = True
16 changes: 16 additions & 0 deletions koalixcrm/crm/reporting/resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.forms import ValidationError
from django.contrib import admin
from django.utils.html import format_html
from django.utils.translation import ugettext as _
from koalixcrm.crm.documents.pdf_export import PDFExport
from koalixcrm.global_support_functions import *
from koalixcrm.crm.exceptions import ReportingPeriodDoneDeleteNotPossible
from django.contrib import messages


class Resource(models.Model):
default_cost
ressource_type
14 changes: 14 additions & 0 deletions koalixcrm/crm/reporting/resource_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.forms import ValidationError
from django.contrib import admin
from django.utils.html import format_html
from django.utils.translation import ugettext as _
from koalixcrm.crm.documents.pdf_export import PDFExport
from koalixcrm.global_support_functions import *
from koalixcrm.crm.exceptions import ReportingPeriodDoneDeleteNotPossible
from django.contrib import messages


class ResourceManager(models.Model):
16 changes: 8 additions & 8 deletions koalixcrm/crm/reporting/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from django.utils.translation import ugettext as _
from django.contrib import admin
from django.utils.html import format_html
from koalixcrm.crm.reporting.estimation_of_resource_consumption import EstimationOfResourceConsumption
from koalixcrm.crm.reporting.estimation_of_resource_consumption import InlineEstimationOfResourceConsumption
from koalixcrm.crm.reporting.agreement import Agreement
from koalixcrm.crm.reporting.agreement import InlineAgreement
from koalixcrm.crm.reporting.generic_task_link import InlineGenericTaskLink
from koalixcrm.crm.reporting.work import InlineWork, Work
from koalixcrm.crm.reporting.reporting_period import ReportingPeriod
Expand Down Expand Up @@ -74,7 +74,7 @@ def planned_costs(self, reporting_period):
no arguments
Returns:
planned costs (Decimal), 0 if when no estimations are present
planned costs (Decimal), 0 if when no agreements are present
Raises:
No exceptions planned"""
Expand All @@ -83,11 +83,11 @@ def planned_costs(self, reporting_period):
global_support_functions.get_today_date())
else:
reporting_period_internal = reporting_period
estimations_to_this_task = EstimationOfResourceConsumption.objects.filter(task=self.id,
reporting_period=reporting_period_internal)
agreements_to_this_task = Agreement.objects.filter(task=self.id,
reporting_period=reporting_period_internal)
sum_costs = 0
for estimation_to_this_task in estimations_to_this_task:
sum_costs += estimation_to_this_task.calculated_costs
for agreement_to_this_task in agreements_to_this_task:
sum_costs += agreement_to_this_task.calculated_costs
return sum_costs
planned_costs.short_description = _("Planned Costs")
planned_costs.tags = True
Expand Down Expand Up @@ -336,7 +336,7 @@ class OptionTask(admin.ModelAdmin):
}),
)
save_as = True
inlines = [InlineEstimationOfResourceConsumption,
inlines = [InlineAgreement,
InlineGenericTaskLink,
InlineWork]

Expand Down
12 changes: 6 additions & 6 deletions koalixcrm/crm/reporting/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Work(models.Model):
employee = models.ForeignKey("djangoUserExtension.UserExtension")
resource = models.ForeignKey("Resource")
date = models.DateField(verbose_name=_("Date"), blank=False, null=False)
start_time = models.DateTimeField(verbose_name=_("Start Time"), blank=True, null=True)
stop_time = models.DateTimeField(verbose_name=_("Stop Time"), blank=True, null=True)
Expand Down Expand Up @@ -74,7 +74,7 @@ def start_stop_pattern_start_missing(self):
return bool(self.stop_time) & (not bool(self.start_time))

def __str__(self):
return _("Work") + ": " + str(self.id) + " " + _("from Person") + ": " + str(self.employee.id)
return _("Work") + ": " + str(self.id) + " " + _("from Person") + ": " + str(self.resource.id)

def check_working_hours(self):
"""This method checks that the working hour is correctly proved either using the start_stop pattern
Expand Down Expand Up @@ -114,7 +114,7 @@ class Meta:

class OptionWork(admin.ModelAdmin):
list_display = ('link_to_work',
'employee',
'resource',
'task',
'get_short_description',
'date',
Expand All @@ -126,7 +126,7 @@ class OptionWork(admin.ModelAdmin):

fieldsets = (
(_('Work'), {
'fields': ('employee',
'fields': ('resource',
'date',
'start_time',
'stop_time',
Expand Down Expand Up @@ -158,14 +158,14 @@ class InlineWork(admin.TabularInline):
model = Work
readonly_fields = ('link_to_work',
'get_short_description',
'employee',
'resource',
'date',
'effort_as_string',)
fieldsets = (
(_('Work'), {
'fields': ('link_to_work',
'get_short_description',
'employee',
'resource',
'date',
'effort_as_string',)
}),
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/views/work_entry_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_work(self, request):
work.task = self.cleaned_data['task']
work.reporting_period = ReportingPeriod.get_reporting_period(project=self.cleaned_data['task'].project,
search_date=self.cleaned_data['date'])
work.employee = UserExtension.get_user_extension(request.user)
work.resource = UserExtension.get_user_extension(request.user)
work.date = self.cleaned_data['date']
if bool(self.cleaned_data['start_time']) & bool(self.cleaned_data['stop_time']):
work.start_time = datetime.datetime.combine(self.cleaned_data['date'],
Expand Down

0 comments on commit 662e8fd

Please sign in to comment.