Rule Evaluation Walkthrough

Let use the use some sample taxation rules to understand how rule evaluation would happen in different scenarios.

Let’s say that the rule input priorities are as follows:

  1. Source State

  2. Interstate sale

  3. Item type

  4. Material

  5. MRP range

Understanding the rules

First let's understand the above rule-set.

  1. There are no rules defined for any state other than Karnataka.

  2. There is no default rule for other states.

  3. There is a default rule for all other input other than source state. This implies that anytime we pass in a source state Karnataka and any specific value for any of the other inputs, we are sure to get at least rule#1.

Evaluating for different inputs

Case 1

Source state = NULL, interstate sale = NULL, item type = NULL, material = NULL, mrp = NULL

 

This example is looking for a catchall, global default rule.i.e. Even if nothing else matched, what rule would surely match.

Get all applicable Rules

All rules will be returned, since we are not applying any filter on the rule set.

Get best fitting rule

No rule will be returned. 

We go over rule inputs in decreasing order of priority. 

  1. Nothing matches in the source state column since only specific rules for Karanataka state are defined but we are looking for an “Any” rule.

  2. We stop right there and return nothing.

Case 2

Source state = Karnataka, interstate sale = YES, item type = NULL, material = NULL, mrp = NULL

Get all applicable Rules

All rules will be returned, since we are not applying any filter on the rule-set except for state, and all rules are for Karnataka state.

Get best fitting rule

Rule#1 will be returned.

We go over rule inputs in decreasing order of priority. 

  1. All rules match for the source state column.

  2. Next, only rule#1 matches for interstate sale. There are no “Any” rules defined for interstate sale.

  3. Since we have only one candidate, we return that.

Case 3

Source state = Karnataka, interstate sale = NO, item type = NULL, material = Cotton, mrp = NULL

Get all applicable Rules

Rule#2, 3, 5 will be returned after applying filtering for Karnataka and Cotton in order of priority. 

Rule#1 is for interstate sale, so it is not returned for a “No” query. Rule#4 is specifically about material “khadi” so it will not be selected for a “Cotton” query.

Get best fitting rule

No rule is returned.

We start going over rule inputs in decreasing order of priority. 

  1. All rules match for the source state column.

  2. All rules match for the interstate sale column.

  3. All remaining rules are for specific item type, no “Any”. So all of them are rejected.

Case 4

Source state = Karnataka, interstate sale = NO, item type = Jeans, material = Cotton, mrp = 100

Get all applicable Rules

Rule#2, 3 will be returned after applying filtering for Karnataka, non-interstate sale, and Jeans in order of priority.

Rule#1 is for interstate sale, so it is not returned for a specific “No” query. Rule#4,5 are for item type “Kurta”, so they are not selected for the specific “Jeans” query.

Get best fitting rule

Rule#3 is returned.

We start going over rule inputs in decreasing order of priority. 

  1. All rules match for the source state column.

  2. All rules match for the interstate sale column.

  3. All rules match for the item type column.

  4. Mrp = 100 falls in the range specified by Rule#3 which is more specific than the “Any” match of Rule#2. Hence we return rule#3.

Case 5

Source state = Karnataka, interstate sale = NO, item type = Jeans, material = Cotton, mrp = 1000

Get all applicable Rules

Rule#2, 3 will be returned after applying filtering for Karnataka, non-interstate sale, and Jeans in order of priority. 

Rule#1 is for interstate sale, so it is not returned for a specific “No” query. Rule#4,5 are for item type “Kurta”, so they are not selected for the specific “Jeans” query.

Get best fitting rule

Rule#2 is returned.

We start going over rule inputs in decreasing order of priority. 

  1. All rules match for the source state column.

  2. All rules match for the interstate sale column.

  3. All rules match for the item type column.

  4. Mrp = 1000 falls outside the range specified by Rule#3, but it matches the “Any” definition of Rule#2.Hence we return rule#2.

Let me bring this to your inbox! Subscribe to new posts.