From 3f6b975c44705737dbe7326f9ea1668f2a8ea2eb Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 13 Dec 2024 05:54:25 +0100 Subject: [PATCH] Fixed mapping --- .../kotlin/net/codinux/invoicing/mapper/MustangMapper.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt index a666714..beb1d40 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt @@ -4,6 +4,7 @@ import net.codinux.invoicing.calculator.AmountsCalculator import net.codinux.invoicing.model.* import net.codinux.invoicing.model.codes.Country import net.codinux.invoicing.model.codes.Currency +import net.codinux.invoicing.model.codes.UnitOfMeasure import org.mustangproject.* import org.mustangproject.BankDetails import org.mustangproject.Invoice @@ -23,6 +24,8 @@ open class MustangMapper( val CountriesByIsoCode = Country.entries.associateBy { it.alpha2Code } val CurrenciesByIsoCode = Currency.entries.associateBy { it.alpha3Code } + + val UnitsByCode = UnitOfMeasure.entries.associateBy { it.code } } @@ -75,7 +78,7 @@ open class MustangMapper( open fun mapLineItem(item: InvoiceItem): IZUGFeRDExportableItem = Item( // description has to be an empty string if not set - Product(item.name, item.description ?: "", item.unit, item.vatRate).apply { + Product(item.name, item.description ?: "", item.unit.code, item.vatRate).apply { this.sellerAssignedID = item.articleNumber // TODO: what is the articleNumber? sellerAssignedId, globalId, ...? }, item.unitPrice, item.quantity @@ -127,7 +130,8 @@ open class MustangMapper( ) open fun mapLineItem(item: IZUGFeRDExportableItem) = InvoiceItem( - item.product.name, item.quantity, item.product.unit, item.price, item.product.vatPercent, item.product.sellerAssignedID, item.product.description.takeUnless { it.isBlank() } + // TODO: what to use as fallback if unit cannot be determined? + item.product.name, item.quantity, item.product.unit?.let { UnitsByCode[it] } ?: UnitOfMeasure.ASM, item.price, item.product.vatPercent, item.product.sellerAssignedID, item.product.description.takeUnless { it.isBlank() } ) protected open fun mapAmountAdjustments(invoice: Invoice): AmountAdjustments? {