Skip to content

Latest commit

 

History

History
93 lines (83 loc) · 2.44 KB

invariants.md

File metadata and controls

93 lines (83 loc) · 2.44 KB

Invariants

List of functions in this API grouped by invariants object: export const invariants = { ... }. To understand the invariants the Order model should be understood first:

  • CI - stands for not canceled and not invoiced part of the order (CI >= 0)
  • IR - stands for invoiced and not refunded part of the order (IR >= 0)

Use these functions to check the invariants for sales calculations. If you use sales (order) functions without checking invariants, the correct result not guaranteed.

Negative values correspond to the "missing" amount/quantity in the Order model state.

invariants.total

total: <T extends Order<Total>>({
  total,
  invoiced,
  canceled,
  refunded
}: T) => {
  ci: number;
  ir: number;
}

Based on the order information in the documents (invoiced, refunded, canceled) gives you CI and IR for total fields. Must not be negative!

invariants.shipping

shipping: <T extends Order<Shipping>>({
  shipping,
  invoiced,
  refunded,
  canceled
}: T) => {
  total: {
    ci: number;
    ir: number;
  };
  qty: number;
}

Same as invariants.total, but gives you 2 fields:

  • total - is the same CI and IR values, but for the shipping costs - must not be negative
  • qty - if you want to control, that shipping costs are invoiced (refunded, canceled) only once, then this value must not be negative

invariants.items.qty

qty: <
  V extends ItemQty,
  U extends Items<V>,
  T extends Order<U>
>(order: T) => {
    ci: V[];
    ir: V[];
}

Gives you CI and IR values for each item quantity (qty). Aggregated per item id. Quantity for each item id must not be negative!

invariants.items.total

total: <
  V extends ItemTotal,
  U extends Items<V>,
  T extends Order<U>
>(order: T) => {
  ci: V[];
  ir: V[];
}

Gives you CI and IR values for each item total. Aggregated per item id. The total for each item id must not be negative!

If you need CI, IR, CR values (not invariants), use order.sales from the order API

Read more