Version

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:

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

sub_type

specify in more details the type

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

Listened Django Signals

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:

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