I have slightly improved the code by inserting UOM conversion
for product in records:
    bom = product.bom_ids and product.bom_ids[0] or False
    if not bom:
        continue
    bom_lines = bom.bom_line_ids
    if not bom_lines:
        continue
    total_weight = 0.0
    for line in bom_lines:
        component = line.product_id
        component_uom=component.uom_id.relative_factor
        quantity = line.product_qty  # Quantity in units
        line_uom = line.product_uom_id.relative_factor
        component_weight = component.weight or 0.0  # Weight in kg
        weight_contribution = line_uom/component_uom * component_weight * quantity
        total_weight += weight_contribution
    product.write({'weight': total_weight})
4 years later and I am faced with the same question, maybe it is badly elaborated:
So let's go:
in a product with a BOM and a manufacturing route, can I not obtain the weight and, why not, also the volume automatically?
product C Weight = component A + component B weight
is it so hard to automatically calculate and provide this information in an integrated system?