diff --git a/backend/internal/core/services/reporting/io_row.go b/backend/internal/core/services/reporting/io_row.go index 831375701..7e239e43a 100644 --- a/backend/internal/core/services/reporting/io_row.go +++ b/backend/internal/core/services/reporting/io_row.go @@ -14,12 +14,13 @@ type ExportItemFields struct { } type ExportCSVRow struct { - ImportRef string `csv:"HB.import_ref"` - Location LocationString `csv:"HB.location"` - TagStr TagString `csv:"HB.tags|HB.labels"` - AssetID repo.AssetID `csv:"HB.asset_id"` - Archived bool `csv:"HB.archived"` - URL string `csv:"HB.url"` + ImportRef string `csv:"HB.import_ref"` + ParentImportRef string `csv:"HB.parent_import_ref"` + Location LocationString `csv:"HB.location"` + TagStr TagString `csv:"HB.tags|HB.labels"` + AssetID repo.AssetID `csv:"HB.asset_id"` + Archived bool `csv:"HB.archived"` + URL string `csv:"HB.url"` Name string `csv:"HB.name"` Quantity float64 `csv:"HB.quantity"` diff --git a/backend/internal/core/services/reporting/io_sheet.go b/backend/internal/core/services/reporting/io_sheet.go index b53654669..ebc25a7d2 100644 --- a/backend/internal/core/services/reporting/io_sheet.go +++ b/backend/internal/core/services/reporting/io_sheet.go @@ -235,19 +235,30 @@ func (s *IOSheet) ReadItems(ctx context.Context, entities []repo.EntityOut, gid } }) + // Resolve parent import ref for CSV output + var parentImportRef string + if item.Parent != nil { + // Find the parent entity to get its import_ref + parentEntity, err := repos.Entities.GetByID(ctx, gid, item.Parent.ID) + if err == nil && parentEntity.ImportRef != "" { + parentImportRef = parentEntity.ImportRef + } + } + s.Rows[i] = ExportCSVRow{ // fill struct Location: locString, TagStr: tagString, - ImportRef: item.ImportRef, - AssetID: item.AssetID, - Name: item.Name, - Quantity: item.Quantity, - Description: item.Description, - Insured: item.Insured, - Archived: item.Archived, - URL: url, + ImportRef: item.ImportRef, + ParentImportRef: parentImportRef, + AssetID: item.AssetID, + Name: item.Name, + Quantity: item.Quantity, + Description: item.Description, + Insured: item.Insured, + Archived: item.Archived, + URL: url, PurchasePrice: item.PurchasePrice, PurchaseFrom: item.PurchaseFrom,