Decimal prices and quantities

Step 1: Define decimal places

You can define the number of decimal places for product prices and quantities either in the Oneflow application or via the public API.

From the Oneflow application

You can define the number of decimal places for prices and quantities in a template and use it when creating contracts through the Public API. Additionally, you can modify the decimal places after the contract is created.

Set decimal places for the product prices

Open a template or contract within the Oneflow application, ensure it has at least one product table, and click on the menu button in the 'Price 1' column.

Navigate to the Decimal places section and select the desired number of decimal places for the product prices and click on Save.

📘

Note:

The default number of decimal places for product prices is 2.

📘

Note:

The defined price_precision applies to price_1 and price_2 base_amount.amount, discount_amount.amount and amount.amount (discounted amount) when performing CRUD operations through the Public API.

Set decimal places for the product quantities

Open a template or contract within the Oneflow application, ensure it has at least one product table, and click on the menu button in the 'Quantity' column.

Navigate to the Decimal places section and select the desired number of decimal places for the product quantities and click on Save.

📘

Note:

The default number of decimal places for quantities is 0.

From the Public API

You can set decimal places for product prices and quantities through Public API within the product group configuration details of the following endpoints:

  1. Create a contract
  2. Update a list of product groups
  3. Update a product group by ID

Use the price_precision key to define the number of decimal places for prices and the quantity_precision key to define the number of decimal places for quantities.

Example:

{
     "product_groups": [
          {
               "configuration": {
                    price_precision: 2,
                    quantity_precision: 0
          }
     ]
}

📘

Note:

Each product group can have its own price precision and quantity precision.

🚧

Note:

When creating contracts, price_precision and quantity_precision are optional fields. If not specified, they will default to the values defined in the template.

Step 2: Set decimal values

You can set decimal prices and decimal quantities through the Public API within product details of the following endpoints:

  1. Create a contract
  2. Update a list of product groups
  3. Update a product group by ID
  4. Add a product to a product group
  5. Update a product in a product group
  6. Update a product by ID

Set decimal values for the product prices

You can set integer or decimal prices with up to four decimal places for the product's price_1 and price_2 base_amount.amount, discount_amount.amount and discount_percent values.

📘

Note:

The public API does not validate the number of decimal places in the input price base amount and discount amount against the defined price_precision. It allows price base amounts and discount amounts with decimal places either fewer or more (up to a maximum of 4) than the defined price_precision.

Example: Assume price_precision is set to 2. You can provide values such as 1, 1.2, or 1.2345 as the price base amount and discount amount.

📘

Note:

If you set a price base amount or price discount amount with fewer decimal places than defined in price_precision, the public API will append trailing zeros when returning the values.

Example: Assume price_precision is set to 3. If you input 1.2 as the price_1.base_amount.amount, the public API will return 1.200 in the response.

📘

Note:

If you set a price base amount or price discount amount with more decimal places (up to a maximum of 4) than defined in price_precision, the public API will not round values according to the price_precision.

Example: Assume price_precision is set to 1. If you input 1.2345 as the price_1.base_amount.amount, the public API will return 1.2345 in the response.

🚧

Note:

The price_1 and price_2 discount_percent value does not depend on the defined price_precision. It supports up to 3 decimal places in the request body. The public API returns the discount_percent in 3 decimal places, adding tailing zeros if the discount_percent has fewer than three decimal places or is an integer.

🚧

Note:

When Oneflow calculates the total price and discounted amount, it ensures both accuracy and adherence to the number of decimal places defined by the price_precision of the respective product group.

Set decimal values for the product quantities

You can set integer or decimal quantities (with no maximum limit) for the product's quantity.amount for quantity-type product quantities.

📘

Note:

The public API does not validate the number of decimal places in the input quantity amount against the defined quatity_precision. It allows quantity amount with decimal places either fewer or more than the defined quantity_precision.

Example: Assume quantity_precision is set to 2. You can provide values such as 1, 1.2,1.2345 or 1.234567 as the quantity amount.

🚧

Note:

There is no maximum limit for the number of decimal places that can be set through the public API. Therefore, if your system uses quantities with more than 4 decimal places, you can send them to Oneflow as is, without rounding.

Example: If your system defines a quantity as 1.23456789, you can send it to Oneflow in the same format without any rounding.

📘

Note:

The public API does not round or append trailing zeros to quantity.amount in the responses, based on the defined quantity_precision.

Example: If quantity_precision is set to 3 and you input 1.23, the response will return 1.23 without adding trailing zeros (e.g., it won't return 1.230).

Similarly, if you input 1.234567, the response will retain the value as 1.234567 without rounding.

🚧

Note:

When Oneflow calculates the total price amount, it uses quantities rounded to the number of decimal places defined by the quantity_precision of the respective product group.

Step 3: Run the code

Example Update a product group by ID request with how to set precision and decimal values.

curl --request PUT \
     --url https://api.oneflow.com/v1/contracts/10015/product_groups/75861 \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'x-oneflow-api-token: 9841f1ee533681c3ea6a438560f2bb6c73b76675' \
     --header 'x-oneflow-user-email: [email protected]' \
     --data '
{
     "configuration": {
          "price_affixes": {
               "prefix": "Rs"
          },
          "hide_price_summation": false,
          "columns": [
               {
                    "enabled": true,
                    "key": "name",
                    "label": "Flowers"
               },
               {
                    "enabled": true,
                    "key": "count",
                    "label": "Value"
               }
          ],
          "counterpart_edit": false,
          "price_precision": 3,
          "quantity_precision: 2
     },
     "products": [
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.275"
                    },
                    "discount_amount": {
                         "amount": "2.725"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.25
               },
               "description": "fresh rose",
               "name": "Rose"
          },
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.75"
                    },
                    "discount_amount": {
                         "amount": "2.5"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.5
               },
               "description": "fresh lily",
               "name": "Lily"
          },
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.7525"
                    },
                    "discount_amount": {
                         "amount": "2.5375"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.567255
               },
               "description": "fresh tulip",
               "name": "Tulip"
          }
     ]
}
'
import requests

url = "https://api.oneflow.com/v1/contracts/10015/product_groups/75861"

payload = {
     "configuration": {
          "price_affixes": {
               "prefix": "Rs"
          },
          "hide_price_summation": false,
          "columns": [
               {
                    "enabled": true,
                    "key": "name",
                    "label": "Flowers"
               },
               {
                    "enabled": true,
                    "key": "count",
                    "label": "Value"
               }
          ],
          "counterpart_edit": false,
          "price_precision": 3,
          "quantity_precision: 2
     },
     "products": [
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.275"
                    },
                    "discount_amount": {
                         "amount": "2.725"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.25
               },
               "description": "fresh rose",
               "name": "Rose"
          },
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.75"
                    },
                    "discount_amount": {
                         "amount": "2.5"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.5
               },
               "description": "fresh lily",
               "name": "Lily"
          },
          {
               "counterparty_lock": false,
               "price_1": {
                    "base_amount": {
                         "amount": "100.7525"
                    },
                    "discount_amount": {
                         "amount": "2.5375"
                    }
               },
               "quantity": {
                    "type": "quantity",
                    "amount": 1.567255
               },
               "description": "fresh tulip",
               "name": "Tulip"
          }
     ]
}

headers = {
    "accept": "application/json",
    "x-oneflow-api-token": "9841f1ee533681c3ea6a438560f2bb6c73b76675",
    "x-oneflow-user-email": "[email protected]",
    "content-type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.text)

Expected response

{
  "_private_ownerside": {
    "created_time": "2021-01-29T08:55:46+00:00",
    "updated_time": "2021-01-29T08:55:46+00:00"
  },
  "configuration": {
    "columns": [
      {
        "enabled": true,
        "key": "name",
        "label": "Flowers"
      },
      {
        "enabled": true,
        "key": "description",
        "label": "Description"
        },
        {
          "enabled": true,
          "key": "price_1",
          "label": "Price 1"
        },
        {
          "enabled": true,
          "key": "price_2",
          "label": "Price 2"
        },
        {
          "enabled": true,
          "key": "count",
          "label": "Value"
        }
    ],
    "counterpart_edit": false,
    "hide_price_summation": false,
    "name": {
      "enabled": false,
      "label": "Untitled"
    },
    "price_affixes": {
      "prefix": "Rs"
    },
    "price_precision": 3,
    "quantity_precision": 2
  },
  "enabled_columns": [
    {
      "enabled": true,
      "key": "name"
    },
    {
      "enabled": true,
      "key": "description"
    },
    {
      "enabled": true,
      "key": "price_1"
    },
    {
      "enabled": true,
      "key": "price_2"
    },
    {
      "enabled": true,
      "key": "count"
    }
  ],
  "id": 75861,
  "products": [
    {
      "_private_ownerside": {
        "created_time": "2021-01-29T08:55:46+00:00",
        "custom_id": "custom_id_set_by_user",
        "updated_time": "2021-01-29T08:55:46+00:00"
      },
      "counterparty_lock": false,
      "description": "fresh rose",
      "id": 135805,
      "name": "Rose",
      "price_1": {
        "amount": {
          "amount": "97.550"
        },
        "base_amount": {
          "amount": "100.275"
        },
        "discount_amount": {
          "amount": "2.725"
        },
        "discount_percent": "0.000"
      },
       "price_2": {
         "amount": {
           "amount": "0.000"
         },
         "base_amount": {
           "amount": "0.000"
         },
         "discount_amount": {
           "amount": "0.000"
         },
         "discount_percent": "0.000"
       },
      "quantity": {
        "amount":  1.25,
        "type": "quantity"
      }
    },
    {
      "_private_ownerside": {
        "created_time": "2021-01-29T08:55:46+00:00",
        "custom_id": "custom_id_set_by_user",
        "updated_time": "2021-01-29T08:55:46+00:00"
      },
      "counterparty_lock": false,
      "description": "fresh lily",
      "id": 135806,
      "name": "Lily",
      "price_1": {
        "amount": {
          "amount": "98.250"
        },
        "base_amount": {
          "amount": "100.750"
        },
        "discount_amount": {
          "amount": "2.500"
        },
        "discount_percent": "0.000"
      },
       "price_2": {
         "amount": {
           "amount": "0.000"
         },
         "base_amount": {
           "amount": "0.000"
         },
         "discount_amount": {
           "amount": "0.000"
         },
         "discount_percent": "0.000"
       },
      "quantity": {
        "amount":  1.5,
        "type": "quantity"
      }
    },
    {
      "_private_ownerside": {
        "created_time": "2021-01-29T08:55:46+00:00",
        "custom_id": "custom_id_set_by_user",
        "updated_time": "2021-01-29T08:55:46+00:00"
      },
      "counterparty_lock": false,
      "description": "fresh tulip",
      "id": 135807,
      "name": "Tulip",
      "price_1": {
        "amount": {
          "amount": "98.214"
        },
        "base_amount": {
          "amount": "100.7525"
        },
        "discount_amount": {
          "amount": "2.5375"
        },
        "discount_percent": "0.000"
      },
       "price_2": {
         "amount": {
           "amount": "0.000"
         },
         "base_amount": {
           "amount": "0.000"
         },
         "discount_amount": {
           "amount": "0.000"
         },
         "discount_percent": "0.000"
       },
      "quantity": {
        "amount":   1.567255,
        "type": "quantity"
      }
    }
  ]
}