Calculation rules

Version

Version

date

comment

changes

Version

date

comment

changes

1

06-2021

formal sector

 

2

08-2021

Payment layer

add Type and sub-type

add bill and invoice service and signals

Example:

https://github.com/openimis/openimis-be-calculation_rule_fs_income_percentage_py

Module files:

  • config.py : define constant that might be used for the definition of description and impacted_class_parameter

  • app.py: load config

  • calculation_rule.py: host the code of the class that implements AbsCalculationRule

Static value:

version

The version is used to keep track of the changes in the version of the calculation rule,

status

integer inactive, future, active, archived

UUID

UUID to follow the version of the calculation

calculation_rule_name

short name of the calculation rule

description

description text of the calculation

impacted_class_parameter

<list>JSONObject objects {class:"className"(to be compare with property name of the FE details object which is pulled from BE), 'parameters':['type':"int",'name':"example",'label':{'en':'DiplayName'},'rights':{'read':"readAuthority", ‘write':"writeAuthority"},relevance:"frontendjsdisplaylogic",condition:"frontendjsvalidationlogic",'optionSet’:[]]} // list of the parameters required on other object,

date_valid_from

default value can be datetime.datetime(2000, 1, 1)

date_valid_to

date or None

type

extendable list

  • account_receivable (default if type is not set)

  • account_payable

  • tax

sub_type

specify in more details the type

  • account_receivable :

    • contribution

    • reinsurance_payment

    • funding

  • account_payable:

    • third_party_payment (toward HF)

    • reimbursement(toward Insuree)

    • commissions (toward User)

    • fees (toward other)

    • reinsurance_contribution

  • tax

    • local_tax

    • state_tax

    • country_tax

From-to

used to define the available convereters

[{“name”:”FunctionName”,”from”:{“class”:”BusinessObject1”,”right”:”rightObject1”},”to”:{“class”:”BusinessObject2”,”right”:”rightObject2”}, parameters':['type':"int",'name':"example",'label':{'en':'DiplayName'},'rights':{'read':"readAuthority", ‘write':"writeAuthority"},relevance:"frontendjsdisplaylogic",condition:"frontendjsvalidationlogic",'optionSet’:[]]}, …]

convert(from,to,**argv)

will check the from-to, and the rights then will call the Function Name with agrv as parameters

→ might be able to define it on abstract level

Models

  • None (using no database approach for CalculationRule) - Calculation Rule is saved by defining class extending the ABSCalculationClass from core module.

Listened Django Signals

  • signal_get_rule_name

  • signal_get_rule_details

  • signal_get_param

  • signal_get_linked_class

  • signal_calculate_event

  •  

GraphQl Queries

None

Services

None

Configuration options (can be changed via core.ModuleConfiguration)

loading implemented rules from "calculation_rule.py" into global variable "CALCULATION_RULE"

Standard Methods

 

ready()

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

all rules, if active will have to register to the signal sent by “getRuleDetails”

 

active_for_object(cls, instance, context, type = ‘account_receivable', sub_type = 'contribution’)

this method will contains the checks if the calculation need to be executed for the object on that context. the default context will be:

  • create

  • update

  • delete

  • submit

  • amend

  • replace

  • check

  • validate

This function is required because the same class can have different calculation based on the object members values (like product ….)

check_calculation(cls, instance):

this function will check if it can be used for the instance, ie. if there is a link between the instance and a calculation

1- get instance class

2- if class known then return check that the linked calculation if the current one

calculate(cls, instance, *args)

Function that will do the calculation based on the parameters

get_linked_class(cls, sender, class_name, **kwargs):

that function will return the possible instance that can have a link to the calculation

convert(from, to, **agrs)

Convert on or several object toward another type, especially to invoice or bill

other methods

Calculation are likely to have other method that could be listening to signals