Fix BOM: apply global discount_pct from metadata to all line items

oci_bom_gen.py from_spec now reads metadata.discount_pct as fallback
when individual line items don't specify a discount. This means
discount_pct: 0.45 in the spec metadata applies 45% to every SKU.

Previously, global discount was silently ignored — only per-item
discount fields were read (defaulting to 0.0).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-13 09:21:07 -03:00
parent cd718f8628
commit 8726f14512
2 changed files with 5 additions and 1 deletions

View File

@@ -683,13 +683,17 @@ class OCIBomGenerator:
gen.load_catalog(catalog_path)
# Global discount from metadata — used as fallback for line items without explicit discount
bom_meta = bom.get("metadata", {})
global_discount = bom_meta.get("discount_pct", bom.get("discount_pct", 0.0))
for item in bom.get("line_items", []):
gen.add_line_item(
sku=str(item["sku"]),
qty=item.get("qty", 0),
hours_units=item.get("hours_units"),
months=item.get("months", 12),
discount=item.get("discount", 0.0),
discount=item.get("discount", global_discount),
custom_label=item.get("custom_label", ""),
custom_note=item.get("custom_note", ""),
)