Skip to content

Commit

Permalink
Add Activation Option and policy status update
Browse files Browse the repository at this point in the history
  • Loading branch information
edarchis committed Feb 8, 2021
1 parent 6c06715 commit 7180534
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
9 changes: 9 additions & 0 deletions policy/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"policy_renewal_interval": 14, # Notify renewal nb of days before expiry date
"policy_location_via": "family", # ... or product
"default_eligibility_disabled": False,
"activation_option": 1,
}


Expand All @@ -36,6 +37,10 @@ class PolicyConfig(AppConfig):
policy_renewal_interval = 14
policy_location_via = 'family'
default_eligibility_disabled = False
ACTIVATION_OPTION_CONTRIBUTION = 1
ACTIVATION_OPTION_PAYMENT = 2
ACTIVATION_OPTION_READY = 3
activation_option = ACTIVATION_OPTION_CONTRIBUTION

def _configure_permissions(self, cfg):
PolicyConfig.gql_query_policies_perms = cfg["gql_query_policies_perms"]
Expand All @@ -58,10 +63,14 @@ def _configure_renewal(self, cfg):
def _configure_location(self, cfg):
PolicyConfig.policy_location_via = cfg["policy_location_via"]

def _configure_activation(self, cfg):
PolicyConfig.activation_option = cfg["activation_option"]

def ready(self):
from core.models import ModuleConfiguration
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self._configure_permissions(cfg)
self._configure_renewal(cfg)
self._configure_location(cfg)
self._configure_eligibility(cfg)
self._configure_activation(cfg)
2 changes: 1 addition & 1 deletion policy/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update_or_create_policy(data, user):
else:
policy = Policy.objects.create(**data)
policy.save()
update_insuree_policies(policy, user)
update_insuree_policies(policy, user.id_for_audit)


class CreateRenewOrUpdatePolicyMutation(OpenIMISMutation):
Expand Down
4 changes: 2 additions & 2 deletions policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ 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):
return sum([p.amount for p in self.premiums.filter(is_photo_fee=True).all()])
def sum_premiums(self, photo=False):
return sum([p.amount for p in self.premiums.filter(is_photo_fee=photo).all()])

def claim_ded_rems(self):
return self.claim_ded_rems
Expand Down
17 changes: 15 additions & 2 deletions policy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def policy_renewal_sms(family_message_template, range_from=None, range_to=None,
return sms_queue


def update_insuree_policies(policy, user):
def update_insuree_policies(policy, audit_user_id):
for member in policy.family.members.filter(validity_to__isnull=True):
existing_ip = InsureePolicy.objects.filter(validity_to__isnull=True, insuree=member, policy=policy).first()
if existing_ip:
Expand All @@ -883,11 +883,24 @@ def update_insuree_policies(policy, user):
effective_date=policy.effective_date,
expiry_date=policy.expiry_date,
offline=policy.offline,
audit_user_id=user.id_for_audit
audit_user_id=audit_user_id
)
)
if ip_created:
logger.debug("Created InsureePolicy(%s) %s - %s", ip.id, member.chf_id, policy.uuid)
else:
logger.debug("Updated InsureePolicy(%s) %s - %s", ip.id, member.chf_id, policy.uuid)


def policy_status_premium_paid(policy, effective_date):
if PolicyConfig.activation_option == PolicyConfig.ACTIVATION_OPTION_CONTRIBUTION:
policy.effective_date = effective_date
policy.status = Policy.STATUS_ACTIVE
else:
policy.status = Policy.STATUS_READY


def policy_status_payment_matched(policy):
if PolicyConfig.activation_option == PolicyConfig.ACTIVATION_OPTION_PAYMENT \
and policy.status == Policy.STATUS_IDLE:
policy.status = Policy.STATUS_ACTIVE
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='openimis-be-policy',
version='1.2.1rc3',
version='1.2.1rc5',
packages=find_packages(),
include_package_data=True,
license='GNU AGPL v3',
Expand Down

0 comments on commit 7180534

Please sign in to comment.