ChemPal Documentation - v1.6.0
    Preparing search index...

    Function isParentPurchasableUnit

    • Reports whether a variant represents the same purchasable unit as its parent product — i.e. the supplier lists the parent among its own variants. Matches on price-history identity first (variantSeriesKey folds in the genuine vs. inherited id, then title/quantity/sku); some suppliers give the parent its own id/sku that differs from the matching variant's, so it also matches when the two are the same purchasable unit (see samePurchasableUnit).

      Parameters

      • product: Product

        The parent product.

      • variant: Variant

        The variant to test against the parent.

      Returns boolean

      true when the variant is the parent's own purchasable unit.

      isParentPurchasableUnit(
      { title: "NaBH4", quantity: 50, uom: "g" } as Product,
      { quantity: 50, uom: "g" },
      ); // => true
      export function isParentPurchasableUnit(product: Product, variant: Variant): boolean {
      const parentKey = variantSeriesKey(product, product);
      return (
      (parentKey !== undefined && variantSeriesKey(product, variant) === parentKey) ||
      samePurchasableUnit(product, variant)
      );
      }