Fixed mapping

This commit is contained in:
dankito 2024-12-13 05:54:25 +01:00
parent a69b4ed4d3
commit 3f6b975c44
1 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import net.codinux.invoicing.calculator.AmountsCalculator
import net.codinux.invoicing.model.* import net.codinux.invoicing.model.*
import net.codinux.invoicing.model.codes.Country import net.codinux.invoicing.model.codes.Country
import net.codinux.invoicing.model.codes.Currency import net.codinux.invoicing.model.codes.Currency
import net.codinux.invoicing.model.codes.UnitOfMeasure
import org.mustangproject.* import org.mustangproject.*
import org.mustangproject.BankDetails import org.mustangproject.BankDetails
import org.mustangproject.Invoice import org.mustangproject.Invoice
@ -23,6 +24,8 @@ open class MustangMapper(
val CountriesByIsoCode = Country.entries.associateBy { it.alpha2Code } val CountriesByIsoCode = Country.entries.associateBy { it.alpha2Code }
val CurrenciesByIsoCode = Currency.entries.associateBy { it.alpha3Code } 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( open fun mapLineItem(item: InvoiceItem): IZUGFeRDExportableItem = Item(
// description has to be an empty string if not set // 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, ...? this.sellerAssignedID = item.articleNumber // TODO: what is the articleNumber? sellerAssignedId, globalId, ...?
}, },
item.unitPrice, item.quantity item.unitPrice, item.quantity
@ -127,7 +130,8 @@ open class MustangMapper(
) )
open fun mapLineItem(item: IZUGFeRDExportableItem) = InvoiceItem( 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? { protected open fun mapAmountAdjustments(invoice: Invoice): AmountAdjustments? {