Skip to content

Commit

Permalink
Merge pull request #288 from scaphilo/FeatrueIssue287
Browse files Browse the repository at this point in the history
Featrue issue287
  • Loading branch information
scaphilo authored Jun 27, 2019
2 parents 0acf996 + bceaa1a commit a4fccb8
Show file tree
Hide file tree
Showing 35 changed files with 1,598 additions and 79 deletions.
40 changes: 20 additions & 20 deletions koalixcrm/accounting/rest/booking_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,47 +88,47 @@ def create(self, validated_data):
booking.save()
return booking

def update(self, instance, validated_data):
instance.description = validated_data['description']
instance.amount = validated_data['amount']
instance.booking_date = validated_data['booking_date']
instance.booking_reference = validated_data['booking_reference']
def update(self, booking, validated_data):
booking.description = validated_data['description']
booking.amount = validated_data['amount']
booking.booking_date = validated_data['booking_date']
booking.booking_reference = validated_data['booking_reference']

# Deserialize from staff
request = self.context.get('request')
koalixcrm_user = request.META.get('HTTP_KOALIXCRM_USER')
user = User.objects.get(username=koalixcrm_user)
instance.staff = user
booking.staff = user

# Deserialize from account
from_account = validated_data.pop('from_account')
if from_account:
if from_account.get('id', instance.from_account):
instance.from_account = Account.objects.get(id=from_account.get('id', None))
if from_account.get('id', booking.from_account):
booking.from_account = Account.objects.get(id=from_account.get('id', None))
else:
instance.from_account = instance.from_account_id
booking.from_account = booking.from_account_id
else:
instance.from_account = None
booking.from_account = None

# Deserialize to account
to_account = validated_data.pop('to_account')
if to_account:
if to_account.get('id', instance.to_account):
instance.to_account = Account.objects.get(id=to_account.get('id', None))
if to_account.get('id', booking.to_account):
booking.to_account = Account.objects.get(id=to_account.get('id', None))
else:
instance.to_account = instance.to_account_id
booking.to_account = booking.to_account_id
else:
instance.to_account = None
booking.to_account = None

# Deserialize to accounting period
accounting_period = validated_data.pop('accounting_period')
if accounting_period:
if accounting_period.get('id', instance.accounting_period):
instance.accounting_period = AccountingPeriod.objects.get(id=accounting_period.get('id', None))
if accounting_period.get('id', booking.accounting_period):
booking.accounting_period = AccountingPeriod.objects.get(id=accounting_period.get('id', None))
else:
instance.accounting_period = instance.accounting_period_id
booking.accounting_period = booking.accounting_period_id
else:
instance.accounting_period = None
booking.accounting_period = None

instance.save()
return instance
booking.save()
return booking
2 changes: 1 addition & 1 deletion koalixcrm/crm/factories/factory_reporting_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class Meta:
project = factory.SubFactory(StandardProjectFactory)
title = "This is a test project"
begin = '2018-06-15'
end = '2019-06-15'
end = '2044-06-15'
status = factory.SubFactory(ReportingReportingPeriodStatusFactory)
21 changes: 0 additions & 21 deletions koalixcrm/crm/reporting/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,24 +595,3 @@ def has_add_permission(self, request):

def has_delete_permission(self, request, obj=None):
return False


class ProjectJSONSerializer(serializers.ModelSerializer):
from koalixcrm.crm.reporting.task import TaskSerializer
tasks = TaskSerializer(many=True, read_only=True)

is_reporting_allowed = serializers.SerializerMethodField()

def get_is_reporting_allowed(self, obj):
if obj.is_reporting_allowed():
return "True"
else:
return "False"

class Meta:
model = Project
fields = ('id',
'project_manager',
'project_name',
'tasks',
'is_reporting_allowed')
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/reporting_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,4 @@ class Meta:
'project',
'title',
'begin',
'end')
'end')
2 changes: 1 addition & 1 deletion koalixcrm/crm/reporting/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class ResourceManagerAdminView(admin.ModelAdmin):
(_('Basics'), {
'fields': ('user',)
}),
)
)
21 changes: 0 additions & 21 deletions koalixcrm/crm/reporting/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,24 +577,3 @@ def has_add_permission(self, request):

def has_delete_permission(self, request, obj=None):
return False


class TaskSerializer(serializers.ModelSerializer):
is_reporting_allowed = serializers.SerializerMethodField()

def get_is_reporting_allowed(self, obj):
if obj.is_reporting_allowed():
return "True"
else:
return "False"

class Meta:
model = Task
fields = ('id',
'title',
'planned_end',
'planned_start',
'project',
'description',
'status',
'is_reporting_allowed')
152 changes: 152 additions & 0 deletions koalixcrm/crm/rest/agreement_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# -*- coding: utf-8 -*-
from rest_framework import serializers
from koalixcrm.crm.reporting.agreement import Agreement
from koalixcrm.crm.reporting.agreement_type import AgreementType
from koalixcrm.crm.reporting.agreement_status import AgreementStatus
from koalixcrm.crm.reporting.resource_price import ResourcePrice
from koalixcrm.crm.reporting.resource import Resource
from koalixcrm.crm.reporting.task import Task
from koalixcrm.crm.product.unit import Unit
from koalixcrm.crm.rest.task_rest import OptionTaskJSONSerializer
from koalixcrm.crm.rest.unit_rest import OptionUnitJSONSerializer
from koalixcrm.crm.rest.resource_price_rest import OptionResourcePriceJSONSerializer
from koalixcrm.crm.rest.agreement_type_rest import OptionAgreementTypeJSONSerializer
from koalixcrm.crm.rest.agreement_status_rest import OptionAgreementStatusJSONSerializer
from koalixcrm.crm.rest.resource_rest import OptionResourceJSONSerializer


class AgreementJSONSerializer(serializers.HyperlinkedModelSerializer):
task = OptionTaskJSONSerializer(source='task', allow_null=False)
resource = OptionResourceJSONSerializer(source='resource', allow_null=False)
unit = OptionUnitJSONSerializer(source='unit', allow_null=False)
type = OptionAgreementTypeJSONSerializer(source='type', allow_null=False)
status = OptionAgreementStatusJSONSerializer(source='status', allow_null=False)
costs = OptionResourcePriceJSONSerializer(source='costs', allow_null=False)

class Meta:
model = Agreement
fields = ('amount',
'date_from',
'date_until',
'task',
'resource',
'unit',
'costs',
'type',
'status')

def create(self, validated_data):
agreement = Agreement()
agreement.amount = validated_data['amount']
agreement.date_from = validated_data['dateFrom']
agreement.date_until = validated_data['dateUntil']
# Deserialize task
task = validated_data.pop('task')
if task:
if task.get('id', None):
agreement.task = Task.objects.get(id=task.get('id', None))
else:
agreement.task = None
# Deserialize resource
resource = validated_data.pop('resource')
if resource:
if resource.get('id', None):
agreement.resource = Resource.objects.get(id=resource.get('id', None))
else:
agreement.resource = None
# Deserialize unit
unit = validated_data.pop('unit')
if unit:
if unit.get('id', None):
agreement.unit = Unit.objects.get(id=unit.get('id', None))
else:
agreement.unit = None
# Deserialize costs
costs = validated_data.pop('costs')
if costs:
if costs.get('id', None):
agreement.costs = ResourcePrice.objects.get(id=costs.get('id', None))
else:
agreement.costs = None
# Deserialize type
type = validated_data.pop('type')
if type:
if type.get('id', None):
agreement.type = AgreementType.objects.get(id=type.get('id', None))
else:
agreement.type = None
# Deserialize status
status = validated_data.pop('status')
if status:
if type.get('id', None):
agreement.status = AgreementStatus.objects.get(id=status.get('id', None))
else:
agreement.status = None

agreement.save()
return agreement

def update(self, agreement, validated_data):
agreement.amount = validated_data['amount']
agreement.date_from = validated_data['dateFrom']
agreement.date_until = validated_data['dateUntil']
task = validated_data.pop('task')
if task:
if task.get('id', agreement.task):
agreement.task = Task.objects.get(id=task.get('id', None))
else:
agreement.task = agreement.task_id
else:
agreement.task = None
# Deserialize resource
resource = validated_data.pop('resource')
if resource:
if resource.get('id', agreement.resource):
agreement.resource = Resource.objects.get(id=resource.get('id', None))
else:
agreement.resource = agreement.resource_id
else:
agreement.resource = None
# Deserialize unit
unit = validated_data.pop('unit')
if task:
if unit.get('id', agreement.unit):
agreement.unit = Unit.objects.get(id=unit.get('id', None))
else:
agreement.unit = agreement.unit_id
else:
agreement.unit = None
# Deserialize costs
costs = validated_data.pop('costs')
if costs:
if costs.get('id', agreement.costs):
agreement.costs = ResourcePrice.objects.get(id=costs.get('id', None))
else:
agreement.costs = agreement.costs_id
else:
agreement.costs = None
# Deserialize type
type = validated_data.pop('type')
if type:
if type.get('id', agreement.type):
agreement.type = Task.objects.get(id=type.get('id', None))
else:
agreement.type = agreement.type_id
else:
agreement.type = None
# Deserialize status
status = validated_data.pop('status')
if status:
if status.get('id', agreement.status):
agreement.status = AgreementStatus.objects.get(id=status.get('id', None))
else:
agreement.status = agreement.status_id
else:
agreement.status = None

agreement.save()

return agreement



26 changes: 26 additions & 0 deletions koalixcrm/crm/rest/agreement_status_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework import serializers
from koalixcrm.crm.reporting.agreement_status import AgreementStatus


class OptionAgreementStatusJSONSerializer(serializers.HyperlinkedModelSerializer):
title = serializers.CharField(source='title', read_only=True)
description = serializers.CharField(source='description', read_only=True)
isAgreed = serializers.BooleanField(source='is_agreed', read_only=True)

class Meta:
model = AgreementStatus
fields = ('title',
'description',
'is_agreed')


class AgreementStatusJSONSerializer(serializers.HyperlinkedModelSerializer):
title = serializers.CharField(source='title')
description = serializers.CharField(source='description')
isAgreed = serializers.BooleanField(source='is_agreed')

class Meta:
model = AgreementStatus
fields = ('title',
'description',
'is_agreed')
22 changes: 22 additions & 0 deletions koalixcrm/crm/rest/agreement_type_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from rest_framework import serializers
from koalixcrm.crm.reporting.agreement_type import AgreementType


class OptionAgreementTypeJSONSerializer(serializers.HyperlinkedModelSerializer):
title = serializers.CharField(source='title', read_only=True)
description = serializers.CharField(source='description', read_only=True)

class Meta:
model = AgreementType
fields = ('title',
'description')


class AgreementTypeJSONSerializer(serializers.HyperlinkedModelSerializer):
title = serializers.CharField(source='title')
description = serializers.CharField(source='description')

class Meta:
model = AgreementType
fields = ('title',
'description')
Loading

0 comments on commit a4fccb8

Please sign in to comment.