Total Cost of Materials Scenario

A calculated attribute can be used to find the total cost of a Bill of Materials (BOM), which is an 'assembled' product, that is itself a collection of individual products or 'part products.'

The most popular approach is to link the source product (i.e., the assembled product) to the various part products that go to make up that assembly (target product), using a specific reference type, for example, 'BOM.' Then, the cost of each of the part products is usually a standard product attribute, for example, 'Cost Price.' Finally, the quantity required for each of the part products in the assembly is a description attribute (metadata) on the link between the source product (the assembly) and each target product (the part products).

Assumptions

  1. The reference type with ID = BOM exists and the assembled product is linked to the individual part products using this reference type.
  2. A description attribute (metadata) with ID = Qty exists on the BOM reference type and the values are populated for how many of those part products are required in the assembled product.

  1. An attribute with ID = CostPrice exists on the part products and the values are entered for the cost of each part product.

Solution

Approach

In the calculation, three (3) lists are generated.

  • The CostPriceVal list will hold the CostPrice of each of the part products referenced by the assembled products. By definition, these two lists will have the same number of entries and have values that are in the same order. That is, entry #1 in List #1 will have the corresponding cost in entry #1 of List #2.
  • The QtyVal list will hold the Qty attribute values for each of the references from the assembled part to the part products.
  • The TotalCost list will hold the list of total cost for each reference by multiplying entry #1 in List #1 with the value in entry #1 of List #2, and so on. The last part of the calculation will then summarize the entries of this third list, and thus calculate the total cost for the assembled product.

Value Template

{CostPriceVal := iterate(iterate(references("product", "BOM"), 'referencetarget()'), 'value("CostPrice")'),
QtyVal := iterate(references ("product",""),'value("Qty")'),
TotalCost := iterate(CostPriceVal, 'item*listitem(QtyVal,index)'),
total := '0',
dummy := iterate(TotalCost,'total:=item + total')
}
concatenate('Sum of BOM = ',total)

Notes

The summation of the entries in TotalCost is a little unusual in that the variable 'dummy' is not required at all, but the variable 'total' is what is needed. Although the contents of the variable 'dummy' are never used, in calculating that value, it is used to calculate the variable 'total' which is the required piece.

Results

The value template multiplies the CostPrice value with the Qty value for each item in the kit as follows:

  • Hex Nuts: .05 x 15 = .75
  • Machine Bolts: .10 x 18 = 1.80
  • Split Washers: .01 x 20 = .20

Then sums the total for each part of the kit: .75 + 1.80 + .20 = 2.75