-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from scaphilo/FeatrueIssue287
Featrue issue287
- Loading branch information
Showing
35 changed files
with
1,598 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,4 +281,4 @@ class Meta: | |
'project', | ||
'title', | ||
'begin', | ||
'end') | ||
'end') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ class ResourceManagerAdminView(admin.ModelAdmin): | |
(_('Basics'), { | ||
'fields': ('user',) | ||
}), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.