Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-794: allow to fetch policy holder with mutation id #64

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions policyholder/gql/gql_mutations/create_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from core.models import InteractiveUser
from policyholder.apps import PolicyholderConfig
from policyholder.services import PolicyHolder as PolicyHolderServices
from policyholder.models import PolicyHolder, PolicyHolderInsuree, PolicyHolderContributionPlan, PolicyHolderUser
from policyholder.models import PolicyHolder, PolicyHolderInsuree, PolicyHolderContributionPlan, PolicyHolderUser, \
PolicyHolderMutation
from policyholder.gql.gql_mutations import PolicyHolderInputType, PolicyHolderInsureeInputType, \
PolicyHolderContributionPlanInputType, PolicyHolderUserInputType
from policyholder.validation import PolicyHolderValidation
Expand All @@ -19,6 +20,17 @@ class CreatePolicyHolderMutation(BaseHistoryModelCreateMutationMixin, BaseMutati
class Input(PolicyHolderInputType):
pass

@classmethod
def _mutate(cls, user, **data):
client_mutation_id = data.pop('client_mutation_id', None)
if "client_mutation_label" in data:
data.pop('client_mutation_label')
policy_holder = cls.create_object(user=user, object_data=data)
if client_mutation_id:
PolicyHolderMutation.object_mutated(
user, client_mutation_id=client_mutation_id, policy_holder=policy_holder
)

@classmethod
def _validate_mutation(cls, user, **data):
if PolicyHolderServices.check_unique_code_policy_holder(code=data['code']):
Expand Down Expand Up @@ -83,4 +95,3 @@ class Input(PolicyHolderUserInputType):
def _validate_mutation(cls, user, **data):
super()._validate_mutation(user, **data)
PermissionValidation.validate_perms(user, PolicyholderConfig.gql_mutation_create_policyholderuser_perms)

2 changes: 1 addition & 1 deletion policyholder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Meta:
db_table = 'tblPolicyHolderUser'


class PolicyHolderMutation(core_models.UUIDModel):
class PolicyHolderMutation(core_models.UUIDModel, core_models.ObjectMutation):
policy_holder = models.ForeignKey(PolicyHolder, models.DO_NOTHING,
related_name='mutations')
mutation = models.ForeignKey(
Expand Down
5 changes: 5 additions & 0 deletions policyholder/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Query(graphene.ObjectType):
dateValidFrom__Gte=graphene.DateTime(),
dateValidTo__Lte=graphene.DateTime(),
applyDefaultValidityFilter=graphene.Boolean(),
clientMutationId=graphene.String()
)

policy_holder_insuree = OrderedDjangoFilterConnectionField(
Expand Down Expand Up @@ -111,6 +112,10 @@ def resolve_policy_holder(self, info, **kwargs):

filters += append_validity_filter(**kwargs)

client_mutation_id = kwargs.pop("clientMutationId", None)
if client_mutation_id:
filters.append(Q(mutations__mutation__client_mutation_id=client_mutation_id))

parent_location = kwargs.get('parent_location')
if parent_location:
filters += [get_ancestor_location_filter(parent_location, location_field='locations')]
Expand Down
Loading