Skip to content

Commit

Permalink
Merge pull request #88 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING develop into release/23.10
  • Loading branch information
delcroip authored Dec 15, 2023
2 parents 30e3ded + 46a318b commit a0a1520
Show file tree
Hide file tree
Showing 9 changed files with 4,408 additions and 42 deletions.
2 changes: 1 addition & 1 deletion policy/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class PolicyGQLType(DjangoObjectType):
sum_premiums = graphene.Float(source="sum_premiums")

def resolve_family(self, info):
if not info.context.user.has_perms(PolicyConfig.gql_query_policies_perms):
raise PermissionDenied(_("unauthorized"))
Expand Down
24 changes: 14 additions & 10 deletions policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from core import fields
from core import models as core_models
from core.utils import filter_validity
from core.models import Officer

from django.conf import settings
from django.db import models
from graphql import ResolveInfo
Expand Down Expand Up @@ -32,15 +34,17 @@ class Policy(core_models.VersionedModel):
audit_user_id = models.IntegerField(db_column='AuditUserID')
# row_id = models.BinaryField(db_column='RowID', blank=True, null=True)

def sum_premiums(self, photo=False):
return sum(
[
p.amount
for p in self.premiums.filter(
is_photo_fee=photo, validity_to__isnull=True
).all()
]
)
@staticmethod
def get_query_sum_premium(photo=False):
return models.Sum(
'premiums__amount',
filter=models.Q(*filter_validity(prefix='premiums__'),premiums__is_photo_fee=photo)
)

def sum_premiums(self, photo = False):
return Policy.objects.filter(id=self.id).aggregate(
sum_premiums=Policy.get_query_sum_premium(photo)
)['sum_premiums'] or 0

def claim_ded_rems(self):
return self.claim_ded_rems
Expand All @@ -50,7 +54,6 @@ def is_new(self):

def can_add_insuree(self):
return self.family.members.filter(validity_to__isnull=True).count() < self.product.max_members

class Meta:
managed = True
db_table = 'tblPolicy'
Expand Down Expand Up @@ -79,6 +82,7 @@ def get_queryset(cls, queryset, user):
# return queryset.filter(
# health_facility__location_id__in=[l.location.id for l in dist]
# )

return queryset


Expand Down
11 changes: 11 additions & 0 deletions policy/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from policy.reports import policy_renewals
from policy.reports.policy_renewals import policy_renewals_query
from policy.reports import primary_operational_indicators
from policy.reports.primary_operational_indicators import policies_primary_indicators_query

report_definitions = [
{
Expand All @@ -11,4 +13,13 @@
"python_query": policy_renewals_query,
"permission": ["131217"],
},
{
"name": "policy_primary_operational_indicators",
"engine": 0,
"default_report": primary_operational_indicators.template,
"description": "Policy primary operational indicators",
"module": "policy",
"python_query": policies_primary_indicators_query,
"permission": ["131201"],
},
]
Loading

0 comments on commit a0a1520

Please sign in to comment.