{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/quotebill-com/json-schema/quotebill-com-calculation-schema.json",
  "title": "Calculation",
  "x-generated": "2026-11-22",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/quotebill-com-openapi.yml#/components/schemas/Calculation",
  "type": "object",
  "properties": {
    "kind": {
      "type": "string",
      "enum": [
        "quotation",
        "invoice",
        "proforma",
        "receipt",
        "creditNote",
        "purchaseOrder",
        "deliveryNote",
        "workOrder",
        "commercialInvoice"
      ]
    },
    "country": {
      "type": "string"
    },
    "region": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "currency_decimals": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4
    },
    "lines": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "quantity": {
            "type": "number"
          },
          "unit_price": {
            "type": "number"
          },
          "discount": {
            "anyOf": [
              {
                "$ref": "#/$defs/Discount"
              },
              {
                "type": "null"
              }
            ]
          },
          "gross": {
            "type": "number",
            "description": "quantity x unit_price, rounded to the currency."
          },
          "discount_amount": {
            "type": "number",
            "description": "gross less amount."
          },
          "amount": {
            "type": "number",
            "description": "The line as the document prints it: after its discount, rounded to the currency."
          }
        },
        "required": [
          "quantity",
          "unit_price",
          "discount",
          "gross",
          "discount_amount",
          "amount"
        ],
        "additionalProperties": false
      }
    },
    "subtotal_before_discounts": {
      "type": "number"
    },
    "discount_total": {
      "type": "number"
    },
    "totals": {
      "$ref": "#/$defs/Totals"
    },
    "tax": {
      "type": "object",
      "properties": {
        "components": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "rate": {
                "type": "number"
              },
              "amount": {
                "type": "number"
              }
            },
            "required": [
              "name",
              "rate",
              "amount"
            ],
            "additionalProperties": false
          },
          "description": "Each tax, rounded on its own: two for a Canadian province with GST and PST."
        },
        "rate_from": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "request",
                "kind",
                "template",
                "account",
                "published"
              ]
            },
            {
              "type": "null"
            }
          ],
          "description": "Where the rate came from: the request's tax_rate, the kind's own (0 for a commercial invoice), the template's own (0 for a template made for someone not registered for VAT or GST), the account's default, or the published rate of the country or region. null when there is none."
        },
        "status": {
          "type": "string",
          "description": "The catalogue's note on the rate, such as standard-rate-estimate or jurisdiction-required."
        },
        "review_reasons": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "anyOf": [
                    {
                      "type": "string",
                      "format": "uri"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "checked_on": {
                  "anyOf": [
                    {
                      "type": "string",
                      "format": "date",
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "title",
                "url",
                "checked_on"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ],
          "description": "Where the rate was read, and when."
        },
        "effective_from": {
          "anyOf": [
            {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "components",
        "rate_from",
        "status",
        "review_reasons",
        "source",
        "effective_from"
      ],
      "additionalProperties": false
    },
    "defaults": {
      "type": "object",
      "properties": {
        "country": {
          "type": "string",
          "enum": [
            "request",
            "template",
            "account",
            "fallback"
          ]
        },
        "currency": {
          "type": "string",
          "enum": [
            "request",
            "account",
            "country"
          ]
        }
      },
      "required": [
        "country",
        "currency"
      ],
      "additionalProperties": false,
      "description": "Which fields the request left to the template (its country), to the account's settings (as for a document), or to the fallbacks: US, and the country's currency."
    },
    "rounding": {
      "type": "string",
      "description": "How the figures are rounded, in the catalogue's words."
    }
  },
  "required": [
    "kind",
    "country",
    "region",
    "currency",
    "currency_decimals",
    "lines",
    "subtotal_before_discounts",
    "discount_total",
    "totals",
    "tax",
    "defaults",
    "rounding"
  ],
  "additionalProperties": false,
  "$defs": {
    "Discount": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "percent",
            "amount"
          ]
        },
        "value": {
          "type": "number",
          "minimum": 0,
          "maximum": 100000000000,
          "description": "percent: 0 to 100. amount: in the document's currency, at most quantity x unit_price."
        }
      },
      "required": [
        "type",
        "value"
      ],
      "additionalProperties": false,
      "description": "A line's discount (V 1.38 on requests; read back since V 1.28)."
    },
    "Totals": {
      "type": "object",
      "properties": {
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "subtotal": {
          "type": "number",
          "description": "The lines, each rounded to the currency, added up."
        },
        "tax_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "tax_rate": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "description": "A percentage: 19 is 19%."
        },
        "tax_amount": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "total": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "tax_status": {
          "type": "string",
          "enum": [
            "calculated",
            "rate_needed"
          ],
          "description": "rate_needed: the country has no single national rate (the United States, Canada without a region). No tax and no total until tax_rate is sent."
        },
        "total_hours": {
          "type": "number",
          "description": "Only on an hours template: the quantities added up."
        }
      },
      "required": [
        "currency",
        "subtotal",
        "tax_name",
        "tax_rate",
        "tax_amount",
        "total",
        "tax_status"
      ],
      "additionalProperties": false,
      "description": "What the editor shows under the lines."
    }
  }
}