Skip to content

Commit

Permalink
[Issue #174] continued with the development of the feature
Browse files Browse the repository at this point in the history
  • Loading branch information
scaphilo committed Sep 30, 2018
1 parent 62ceb4c commit b1b8fd2
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 44 deletions.
31 changes: 16 additions & 15 deletions koalixcrm/crm/documents/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from django.utils.html import format_html
from django.contrib.admin import helpers
from django.shortcuts import render
from django.contrib import messages
from django.template.context_processors import csrf
from koalixcrm.crm.const.status import *
from koalixcrm.crm.exceptions import *
from koalixcrm import accounting
from koalixcrm.crm.documents.sales_document import SalesDocument, OptionSalesDocument
from koalixcrm.crm.documents.sales_document_position import SalesDocumentPosition
from koalixcrm.plugin import *
from koalixcrm.accounting.models import Account
from django.contrib.admin import helpers
from django.shortcuts import render
from django.contrib import messages
from django.template.context_processors import csrf
from koalixcrm.global_support_functions import limit_string_length


class Invoice(SalesDocument):
Expand All @@ -28,7 +29,9 @@ class Invoice(SalesDocument):

def link_to_invoice(self):
if self.id:
return format_html("<a href='/admin/crm/invoice/%s' >%s</a>" % (str(self.id), str(self.description)))
return format_html("<a href='/admin/crm/invoice/%s' >%s</a>" % (str(self.id),
limit_string_length(str(self.description),
30)))
else:
return "Not present"
link_to_invoice.short_description = _("Invoice")
Expand Down Expand Up @@ -177,25 +180,23 @@ class InlineInvoice(admin.TabularInline):
can_delete = True
extra = 1
readonly_fields = ('link_to_invoice',
'last_pricing_date',
'last_calculated_price',
'last_calculated_tax',
'description',
'contract',
'customer',
'payable_until',
'status')
'status',
'last_pricing_date',
'last_calculated_price',
'last_calculated_tax')
fieldsets = (
(_('Invoice'), {
'fields': ('link_to_invoice',
'last_pricing_date',
'last_calculated_price',
'last_calculated_tax',
'description',
'contract',
'customer',
'payable_until',
'status')
'status',
'last_pricing_date',
'last_calculated_price',
'last_calculated_tax')
}),
)

Expand Down
5 changes: 4 additions & 1 deletion koalixcrm/crm/documents/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from koalixcrm.crm.const.status import *
from koalixcrm.plugin import *
from koalixcrm.crm.documents.sales_document import SalesDocument, OptionSalesDocument
from koalixcrm.global_support_functions import limit_string_length


class Quote(SalesDocument):
Expand All @@ -16,7 +17,9 @@ class Quote(SalesDocument):

def link_to_quote(self):
if self.id:
return format_html("<a href='/admin/crm/quote/%s' >%s</a>" % (str(self.id), str(self.description)))
return format_html("<a href='/admin/crm/quote/%s' >%s</a>" % (str(self.id),
limit_string_length(str(self.description),
30)))
else:
return "Not present"
link_to_quote.short_description = _("Quote");
Expand Down
3 changes: 3 additions & 0 deletions koalixcrm/crm/product/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Price(models.Model):
blank=True,
null=True)

def __str__(self):
return str(self.id) + " " +str(self.price) + " " + str(self.currency.short_name)

def is_valid_from_criteria_fulfilled(self, date):
if not self.valid_from:
return True
Expand Down
3 changes: 3 additions & 0 deletions koalixcrm/crm/product/product_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ProductPrice(models.Model):
blank=False,
verbose_name=_("Price"))

def __str__(self):
return str(self.price.price) + " " + str(self.price.currency.short_name)

def is_valid_from_criteria_fulfilled(self, date):
if not self.valid_from:
return True
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/agreement_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
verbose_name_plural = _('Agreement Type')

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


class AgreementTypeAdminView(admin.ModelAdmin):
Expand Down
12 changes: 6 additions & 6 deletions koalixcrm/crm/reporting/generic_project_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@


class GenericProjectLink(models.Model):
task = models.ForeignKey("Project",
verbose_name=_('Project'),
blank=False,
null=False)
project = models.ForeignKey("Project",
verbose_name=_('Project'),
blank=False,
null=False)
project_link_type = models.ForeignKey("ProjectLinkType",
verbose_name=_('Project Link Type'),
blank=True,
Expand All @@ -29,7 +29,7 @@ class GenericProjectLink(models.Model):
related_name="db_project_link_last_modified")

def __str__(self):
return _("Project Link")
return _("Link to") + " " + str(self.project)

class Meta:
app_label = "crm"
Expand Down Expand Up @@ -66,4 +66,4 @@ def has_add_permission(self, request):
return False

def has_delete_permission(self, request, obj=None):
return False
return False
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/generic_task_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GenericTaskLink(models.Model):
verbose_name=_("Last modified by"), related_name="db_task_link_last_modified")

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

class Meta:
app_label = "crm"
Expand Down
14 changes: 9 additions & 5 deletions koalixcrm/crm/reporting/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ def effective_accumulated_costs(self, reporting_period=None):
for single_reporting_period in reporting_periods:
all_project_tasks = Task.objects.filter(project=self.id)
for task in all_project_tasks:
effective_effort_accumulated += task.effective_acucumulated_costs(reporting_period=single_reporting_period)
return effective_effort_accumulated
effective_accumulated_costs.short_description = _("Effective Effort [hrs]")
effective_effort_accumulated += float(task.effective_costs(reporting_period=single_reporting_period))
return effective_effort_accumulated

effective_accumulated_costs.short_description = _("Effective Accumulated costs [hrs]")
effective_accumulated_costs.tags = True

def effective_costs(self, reporting_period):
Expand All @@ -152,7 +153,7 @@ def planned_costs(self, reporting_period=None):
Raises:
No exceptions planned"""
planned_effort_accumulated = "0"
planned_effort_accumulated = 0
all_project_tasks = Task.objects.filter(project=self.id)
if all_project_tasks:
for task in all_project_tasks:
Expand Down Expand Up @@ -391,7 +392,10 @@ class ProjectAdminView(admin.ModelAdmin):
'project_manager',
'default_currency',
'planned_duration',
'effective_duration',)
'planned_costs',
'effective_duration',
'effective_accumulated_costs'
)

list_display_links = ('id',)
ordering = ('-id',)
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/project_link_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
verbose_name_plural = _('Project Link Type')

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


class OptionProjectLinkType(admin.ModelAdmin):
Expand Down
3 changes: 3 additions & 0 deletions koalixcrm/crm/reporting/resource_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class ResourcePrice(Price):
blank=False,
null=False)

def __str__(self):
return str(self.price) + " " + str(self.currency.short_name)


class ResourcePriceInlineAdminView(admin.TabularInline):
model = ResourcePrice
Expand Down
6 changes: 3 additions & 3 deletions koalixcrm/crm/reporting/resource_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ResourceType(models.Model):
blank=True,
null=True)

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

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

def __str__(self):
return str(self.title)


class ResourceTypeAdminView(admin.ModelAdmin):
list_display = ('id',
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/task_link_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
verbose_name_plural = _('Task Link Type')

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


class OptionTaskLinkType(admin.ModelAdmin):
Expand Down
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/task_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Meta:
verbose_name_plural = _('Task Status')

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


class OptionTaskStatus(admin.ModelAdmin):
Expand Down
7 changes: 4 additions & 3 deletions koalixcrm/crm/views/time_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from koalixcrm.djangoUserExtension.exceptions import UserExtensionMissing, TooManyUserExtensionsAvailable
from koalixcrm.crm.views.range_selection_form import RangeSelectionForm
from koalixcrm.crm.views.work_entry_formset import BaseWorkEntryFormset
from koalixcrm.crm.reporting.human_resource import HumanResource


@login_required
def work_report(request):
try:
employee = UserExtension.get_user_extension(request.user)
human_resource = HumanResource.objects.get(user=UserExtension.get_user_extension(request.user))
if request.POST.get('post'):
if 'cancel' in request.POST:
return HttpResponseRedirect('/admin/')
Expand All @@ -36,7 +37,7 @@ def work_report(request):
form.update_work(request)
messages.success(request, _('you have successfully updated your work'))
formset = BaseWorkEntryFormset.create_updated_formset(range_selection_form,
employee)
human_resource)
range_selection_form.update_from_input()
c = {'range_selection_form': range_selection_form,
'formset': formset}
Expand All @@ -50,7 +51,7 @@ def work_report(request):
range_selection_form = RangeSelectionForm.create_range_selection_form(from_date, to_date)
formset = BaseWorkEntryFormset.create_new_formset(from_date,
to_date,
employee)
human_resource)
c = {'formset': formset,
'range_selection_form': range_selection_form}
c.update(csrf(request))
Expand Down
12 changes: 6 additions & 6 deletions koalixcrm/crm/views/work_entry_formset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def __init__(self, *args, **kwargs):
super(BaseWorkEntryFormset, self).__init__(*args, **kwargs)

@staticmethod
def generate_initial_data(start_date, stop_date, employee):
def generate_initial_data(start_date, stop_date, human_resource):
from koalixcrm.crm.reporting.work import Work
list_of_work = Work.objects.filter(employee=employee).filter(date__lte=stop_date).filter(date__gte=start_date).order_by("date")
list_of_work = Work.objects.filter(human_resource=human_resource).filter(date__lte=stop_date).filter(date__gte=start_date).order_by("date")
initial = []
for work in list_of_work:
initial.append({'work_id': work.id,
Expand Down Expand Up @@ -44,7 +44,7 @@ def compose_form_kwargs(from_date, to_date):
return form_kwargs

@staticmethod
def create_updated_formset(range_selection_form, employee):
def create_updated_formset(range_selection_form, human_resource):
WorkEntryFormSet = forms.formset_factory(WorkEntry,
extra=1,
max_num=60,
Expand All @@ -54,22 +54,22 @@ def create_updated_formset(range_selection_form, employee):
to_date = range_selection_form.cleaned_data['to_date']
initial_formset_data = BaseWorkEntryFormset.generate_initial_data(from_date,
to_date,
employee)
human_resource)
form_kwargs = BaseWorkEntryFormset.compose_form_kwargs(from_date, to_date)
formset = WorkEntryFormSet(initial=initial_formset_data,
form_kwargs=form_kwargs)
return formset

@staticmethod
def create_new_formset(from_date, to_date, employee):
def create_new_formset(from_date, to_date, human_resource):
WorkEntryFormSet = forms.formset_factory(WorkEntry,
extra=1,
max_num=60,
can_delete=True,
formset=BaseWorkEntryFormset)
initial_formset_data = BaseWorkEntryFormset.generate_initial_data(from_date,
to_date,
employee)
human_resource)
form_kwargs = BaseWorkEntryFormset.compose_form_kwargs(from_date,
to_date)
formset = WorkEntryFormSet(initial=initial_formset_data,
Expand Down

0 comments on commit b1b8fd2

Please sign in to comment.