Skip to content

Commit

Permalink
Merge pull request #19 from openimis/develop
Browse files Browse the repository at this point in the history
Release v1.3.1
  • Loading branch information
delcroip authored Dec 9, 2021
2 parents 2b3180f + cad11a6 commit 24c8f21
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
14 changes: 11 additions & 3 deletions calculation/calculation_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .apps import AbsCalculationRule
from .config import CLASS_RULE_PARAM_VALIDATION, CLASS_RULE_PARAM_VALIDATION2, \
DESCRIPTION_CONTRIBUTION_VALUATION
DESCRIPTION_CONTRIBUTION_VALUATION, FROM_TO
from contribution_plan.models import ContributionPlanBundleDetails
from core.signals import Signal
from core import datetime
Expand All @@ -19,12 +19,16 @@ class ContributionValuationRule(AbsCalculationRule):
date_valid_from = datetime.datetime(2000, 1, 1)
date_valid_to = None
status = "active"
from_to = FROM_TO
type = ""
sub_type = ""

signal_get_rule_name = Signal(providing_args=[])
signal_get_rule_details = Signal(providing_args=[])
signal_get_param = Signal(providing_args=[])
signal_get_linked_class = Signal(providing_args=[])
signal_calculate_event = Signal(providing_args=[])
signal_convert_from_to = Signal(providing_args=[])

@classmethod
def ready(cls):
Expand All @@ -41,7 +45,7 @@ def ready(cls):
cls.signal_calculate_event.connect(cls.run_calculation_rules, dispatch_uid="on_calculate_event_signal")

@classmethod
def active_for_object(cls, instance, context):
def active_for_object(cls, instance, context, type='account_receivable', sub_type='contribution'):
return instance.__class__.__name__ == "ContractContributionPlanDetails" \
and context in ["create", "update"] \
and cls.check_calculation(instance)
Expand Down Expand Up @@ -149,12 +153,16 @@ class ContributionValuationRule_2(AbsCalculationRule):
date_valid_from = datetime.datetime(2000, 1, 1)
date_valid_to = None
status = "active"
from_to = FROM_TO
type = ""
sub_type = ""

signal_get_rule_name = Signal(providing_args=[])
signal_get_rule_details = Signal(providing_args=[])
signal_get_param = Signal(providing_args=[])
signal_get_linked_class = Signal(providing_args=[])
signal_calculate_event = Signal(providing_args=[])
signal_convert_from_to = Signal(providing_args=[])

@classmethod
def ready(cls):
Expand All @@ -171,7 +179,7 @@ def ready(cls):
cls.signal_calculate_event.connect(cls.run_calculation_rules, dispatch_uid="on_calculate_event_signal")

@classmethod
def active_for_object(cls, instance, context):
def active_for_object(cls, instance, context, type='account_receivable', sub_type='contribution'):
return instance.__class__.__name__ == "ContractContributionPlanDetails" \
and context in ["create", "update"] \
and cls.check_calculation(instance)
Expand Down
2 changes: 2 additions & 0 deletions calculation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,5 @@
F"and PHinsuree and the percentage in the Contribution plan" \
F" so when a contract valuation is requested then the calculation will" \
F" determine the value based on the contract details income and CP percentage"

FROM_TO = []
34 changes: 34 additions & 0 deletions calculation/migrations/0003_add_calculation_roles_for_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import logging

from django.db import migrations

logger = logging.getLogger(__name__)


MIGRATION_SQL = """
/* Calculation */
DECLARE @SystemRole INT
SELECT @SystemRole = role.RoleID from tblRole role where IsSystem=256;
/* Calculation search*/
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 153001)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 153001, CURRENT_TIMESTAMP)
END
/* Calculation update*/
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 153003)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 153003, CURRENT_TIMESTAMP)
END
"""


class Migration(migrations.Migration):
dependencies = [
('calculation', '0002_auto_20210118_1426')
]

operations = [
migrations.RunSQL(MIGRATION_SQL)
]
9 changes: 9 additions & 0 deletions calculation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class CalculationRulesGQLType(graphene.ObjectType):
class_param = graphene.JSONString()
date_valid_from = graphene.Date()
date_valid_to = graphene.Date()
from_to = graphene.JSONString()
type = graphene.String()
sub_type = graphene.String()


class CalculationRulesListGQLType(graphene.ObjectType):
Expand Down Expand Up @@ -100,6 +103,9 @@ def resolve_calculation_rules_by_class_name(parent, info, **kwargs):
class_param=rule.impacted_class_parameter,
date_valid_from=rule.date_valid_from,
date_valid_to=rule.date_valid_to,
from_to=rule.from_to,
type=rule.type,
sub_type =rule.sub_type
)
)
return CalculationRulesListGQLType(list_cr)
Expand All @@ -119,6 +125,9 @@ def resolve_calculation_rules(parent, info, **kwargs):
class_param=cr.impacted_class_parameter,
date_valid_from=cr.date_valid_from,
date_valid_to=cr.date_valid_to,
from_to=cr.from_to,
type=cr.type,
sub_type=cr.sub_type
)
)
return CalculationRulesListGQLType(list_cr)
Expand Down

0 comments on commit 24c8f21

Please sign in to comment.