Date Calculation Extension [LEGACY]

Prev Next

This extension is deprecated and has been replaced by Formula Fields. Learn more here.

What is the Date Calculation extension?

The Date Calculation function improves your automation without compromising data integrity. Suppose a date is missing but Rossum can deduce them from other available data. You can use this extension to compute the missing dates by running mathematical expressions in this case. These calculated values are connected to specific schema IDs to ensure that the data output is the same across all documents.

Common use case configurations for Date Calculation extension

Below you will find configuration examples you can copy and modify for easy setup.

Due date calculation based on extracted data

In this use case, invoice dates and payment terms are extracted from the document in corresponding fields. We also assume that the payment terms are numbers so you can use them in the calculation.

Please note that this is a simplified example. Real payment terms can appear in the document in different forms. You can use the Value Transformations extension to convert the extracted payment terms to a number before Rossum uses them in the due date calculation.

Example:

  • Extracted values:

    • Invoice date: 23/06/2023

    • Payment terms: 30

  • Resulting due date (calculated) value: 23/07/2023

{
  "calculations": [
    {
      "expression": "{date_issue} + timedelta(days={terms})",
      "target_field": "date_due_calculated"
    }
  ]
}

Due date calculation based on document metadata

In this scenario, in the due date calculation, we use the date Rossum receives the document. The payment terms are also known.

There are two calculations in this example. The first is the standard due date calculation for all vendors (Payment Terms NET 30). The other is specific to the “Milk Company” vendor mentioned in the condition (Payment Terms NET 14). Because both calculations use the same target field, the last performed calculation will propagate the value.

Example:

  • Document metadata:

    • created_at (date when Rossum received the document): 23/06/2023

  • Results:

    • For documents from all vendors except the “Milk Company“: 23/07/2023

    • For the documents from the “MIlk Company“ vendor: 07/07/2023

{
  "calculations": [
    {
      "expression": "{created_at} + timedelta(days=30)",
      "target_field": "date_due_calculated"
    },
{
"condition": "{sender_name} == 'Milk Company'",
"expression": "{created_at} + timedelta(days=14)",
"target_field": "date_due_calculated"
    }
  ]
}

How to set up Date Calculations extension

Setting up the extension itself takes a few simple steps.

Step 1: Prepare your queues and schemas

The first step is to identify the queue(s) with the documents that require this function. Then you need to identify the schema IDs of the fields that will contain the extracted values set to be transformed by the function.

If you use the Dedicated Engine, make sure that you create new schema fields that will store the results of the calculations (see the info panel below). And if you use the Generic Engine, you can also store the results of the calculations in the AI-predicted fields if needed.

Please remember that if you configure the function to modify the value of a specific AI-extracted field in the Dedicated Engine, the accuracy calculation will be lower than the actual accuracy. To avoid this, we do not recommend changing the AI and OCR extracted values manually or programmatically. Instead, store the modified value in new schema fields.

Step 2: Activate Date Calculations in the Rossum Store

To enable Date Calculations, go to the Rossum application and:

  • Click on the Extensions tab at the top of the app

  • Click on the Rossum store option to display all the available extensions

  • Select the “Date Calculations” extension tile

  • Click “Add

Step 3: Specify to which queue(s) you want to add this extension.

In the “Rossum Store Extension Settings,” scroll down to “Queues” and select the queue(s) in which you want to use the function. Please remember to save your changes once you’ve chosen the desired queues.

4: Set up the Calculations

You can set it up using the configuration field in the UI or using the settings attribute of the hook API object. The configuration is in JSON format.

It consists of a list of calculations that work with values from different fields in the schema.

Complete list of available parameters:

Attribute

Type

Required

Default value

Description

calculations

list

yes

-

List calculation definitions

condition

string

no

-

Python expression that contains Rossum schema IDs wrapped in the { }. The date calculation will only be performed if the condition matches (expression evaluates to True).

expression

string

yes

-

The mathematical expression that contains date type schema_ids in { } – to be evaluated.

The expression supports usage of the timedelta() * or today() object from the python datetime library.

target_field

string

yes

-

Schema ID of the field to which the calculation result will be stored. **

queues

list

no

-

Queues where the calculations should be applied (a subset of queues to which the extension is assigned). List of queue URLs.

If not specified, the calculation applies to all queues to which you assigned the function.

excluded_queues

list

no

-

Queues where the action should NOT be applied (a subset of queues to which the extension is assigned). List of queue URLs.

If not specified, the calculation applies to all queues to which you assigned the function.

allow_target_update

boolean

no

false

true – allows user update of the field filled out by the function.

false – doesn’t allow user update of the field. The value will always be changed back after edit.

Things to remember:

* All schema IDs used on the expression (except for params on the timedelta Object) must be of type date (Rossum schema field type). If a metadata field is used in the expression, the extension will parse only its date part and use it for the calculation.

If there is a schema_id in the schema overlapping with the metadata field name, the schema field value takes precedence, and it is not possible to use the metadata field.

It is possible to define the parameter of the timedelta object using the schema_id. The user can decide to use an integer value. If you use an incompatible value, the function will fail.

The expression supports the use of the today() method to get the current date.

** Schema ID of the field to which the function will write the calculation result. The target field can only be of type Date. The function will write the value in the same format defined in the schema.