Skip to content

Commit

Permalink
Finish feature/OFS-219
Browse files Browse the repository at this point in the history
OFS-219: changes related to the calculation module
  • Loading branch information
dragos-dobre committed Feb 18, 2021
2 parents 58edb0f + 583db3d commit 6fc283e
Showing 1 changed file with 61 additions and 41 deletions.
102 changes: 61 additions & 41 deletions core/abs_calculation_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,116 @@

class AbsCalculationRule(object, metaclass=abc.ABCMeta):

def __init__(self, status):
self.status = status
@classmethod
def get_version(cls):
return type(cls)._version

def get_version(self):
return type(self)._version

def set_version(self, val):
type(self)._version = val
@classmethod
def set_version(cls, val):
type(cls)._version = val

version = property(get_version, set_version)

def get_uuid(self):
return type(self)._uuid
@classmethod
def get_uuid(cls):
return type(cls)._uuid

def set_uuid(self, val):
type(self)._uuid = val
@classmethod
def set_uuid(cls, val):
type(cls)._uuid = val

uuid = property(get_uuid, set_uuid)

def get_calculation_rule_name(self):
return type(self)._calculation_rule_name
@classmethod
def get_calculation_rule_name(cls):
return type(cls)._calculation_rule_name

def set_calculation_rule_name(self, val):
type(self)._calculation_rule_name = val
@classmethod
def set_calculation_rule_name(cls, val):
type(cls)._calculation_rule_name = val

calculation_rule_name = property(get_calculation_rule_name, set_calculation_rule_name)

def get_description(self):
return type(self)._description
@classmethod
def get_description(cls):
return type(cls)._description

def set_description(self, val):
type(self)._description = val
@classmethod
def set_description(cls, val):
type(cls)._description = val

description = property(get_description, set_description)

def get_impacted_class_parameter(self):
return type(self)._impacted_class_parameter
@classmethod
def get_impacted_class_parameter(cls):
return type(cls)._impacted_class_parameter

def set_impacted_class_parameter(self, val):
type(self)._impacted_class_parameter = val
@classmethod
def set_impacted_class_parameter(cls, val):
type(cls)._impacted_class_parameter = val

impacted_class_parameter = property(get_impacted_class_parameter, set_impacted_class_parameter)

@classmethod
@abc.abstractmethod
def ready(self):
def ready(cls):
return

@classmethod
@abc.abstractmethod
def check_calculation(self, instance):
def check_calculation(cls, instance):
return

@classmethod
@abc.abstractmethod
def active_for_object(self, object_class, context):
def active_for_object(cls, instance, context):
return

@classmethod
@abc.abstractmethod
def calculate_event(self, sender, instance, user, **kwargs):
def calculate(cls, instance, *args):
return

@classmethod
@abc.abstractmethod
def calculate(self, instance, *args):
def get_linked_class(cls, sender, class_name, **kwargs):
return

@abc.abstractmethod
def get_linked_class(self, list_class_names):
return
@classmethod
def get_rule_name(cls, sender, class_name, **kwargs):
for object_class in cls.impacted_class_parameter:
if object_class["class"] == class_name:
return cls

def get_rule_details(self, class_name):
for object_class in self.impacted_class_parameter:
@classmethod
def get_rule_details(cls, sender, class_name, **kwargs):
for object_class in cls.impacted_class_parameter:
if object_class["class"] == class_name:
return object_class

def get_parameters(self, class_name, instance):
@classmethod
def get_parameters(cls, sender, class_name, instance, **kwargs):
"""
class_name is the class name of the object where the calculation param need to be added
instance is where the link with a calculation need to be found,
like the CPB in case of PH insuree or Contract Details
return a list only with rule details that matches step 1 and 2
"""
rule_details = self.get_rule_details(class_name=class_name)
rule_details = cls.get_rule_details(sender=sender, class_name=class_name)
if rule_details:
if self.check_calculation(instance=instance):
if cls.check_calculation(instance=instance):
return rule_details["parameters"] if "parameters" in rule_details else []

def run_calculation_rules(self, instance, context):
@classmethod
def run_calculation_rules(cls, sender, instance, user, context, **kwargs):
"""
this function will send a signal and the rules will
reply if they have object matching the classname in their list of object
"""
self.ready()
rule_details = self.get_rule_details(class_name=instance.__class__)
if self.active_for_object(object_class=rule_details, context=context):
self.calculate(instance=instance)
list_class = cls.get_linked_class(sender=sender, class_name=instance.__class__.__name__)
if len(list_class) > 0:
rule_details = cls.get_rule_details(class_name=list_class[0], sender=sender)
if rule_details:
if cls.active_for_object(instance=instance, context=context):
result = cls.calculate(instance=instance)
return result

0 comments on commit 6fc283e

Please sign in to comment.