...
relevance and condition are Nice to have.
Methods
ready()
NEED TO BE DEFINED ON RULE LEVEL
This method makes sure the calculation is registered in the calculation table (if not the line should be added with "inactive status") and register the signals only if it is active
activeForObject(object, context)
NEED TO BE DEFINED ON RULE LEVEL
this method will contains the checks if the calculation need to be executed for the object on that context. the default context will be:
...
(TDC)calculateEvent(sender, instance, user, **kwargs)
NEED TO BE DEFINED ON RULE LEVEL
This method runs the calculation based on the object sending the signal, this means that the relationship with the other item required for the calculation could be found from the object sending the signal. (e.g., link to the product can be found in the policy as foreign key.)
This function should call first the activeForObject method, the context will depend on the calling event, if the fuction return true the calcuation needs to be run, in other case the even handling will stop
the calculate(*args) function
Signal need to be set up on the ready function to call it
...
checkCalculation(instance)
NEED TO BE DEFINED ON RULE LEVEL
this function will get the calculation relative the instance
1- get instance class
2- if class known then return check that the linked calculation is the current one
calculate(instance, *args)
Function that will do the calculation based on the parameters
getParamteres(ClassName, instance)
NEED TO BE DEFINED ON MODULE LEVEL
This function has two steps
1- define which calculation has param for the class name
Return the data contained on the JSON so the frontend can ask the parameters for a new object of the ClassName.
for active_calculation_rule
for active_calculation_rule.objects
OR
CalculationRulesDetailsModel.objects.filter(calulation_rule__status='active').filter(calulation_rule__dateValidFrom__lte=now()).filter(Q(calulation_rule__dateValidTo__gte=now())|Q(calulation_rule__dateValidTo__isnull=True)).filter(class_name=ClassName)
return the CalculationRulesDetails json object
2- define if the calculation should be used
for each “eligible“ ruleDetails,
check if the calculation is really concerning the class for that context checkCalculation(instance)
return the ruleDetails that are valid to classname and related to instance
Authorities
Calculation (prefix 153)
...