Add PreferExternalValue to control which value will be the final value

This commit is contained in:
Jonathan Jenne
2022-05-03 15:32:35 +02:00
parent 5fe4079028
commit 5accfbe002
6 changed files with 84 additions and 46 deletions

View File

@@ -242,29 +242,20 @@ Namespace Documents
' oValue = oDate.ToString("d")
'End If
oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
.Original = oValue,
.Final = oValue,
.DataType = oColumn.DataType,
.IsRequired = oRequired,
.IsVirtual = oColumn.Config.IsVirtual,
.SortKey = oColumnSortKey
})
Dim oFieldValue = GetFieldValueFromColumn(oColumn, oColumnSortKey)
oFieldValue.SetOriginalValue(oValue)
oFields.Add(oSubElement.Name.ToString, oFieldValue)
Else
Logger.Debug("Creating new field from Configuration: [{0}]", oColumn.Name)
Dim oValue = New DocumentRow.FieldValue With {
.SortKey = oColumnSortKey,
.IsVirtual = oColumn.Config.IsVirtual
}
Dim oFieldValue = GetFieldValueFromColumn(oColumn, oColumnSortKey)
'oValue.Error = FieldErrorType.None
If oColumn.Config?.IsRequired Then
'oValue.Error = FieldErrorType.MissingValue
oValue.AddFieldError(FieldErrorType.MissingValue, $"Attribut {oSubElement.Name} wird benötigt, ist aber nicht gefüllt.")
oFieldValue.AddFieldError(FieldErrorType.MissingValue, $"Attribut {oSubElement.Name} wird benötigt, ist aber nicht gefüllt.")
End If
oFields.Add(oColumn.Name, oValue)
oFields.Add(oColumn.Name, oFieldValue)
End If
oColumnSortKey += 1
@@ -291,6 +282,16 @@ Namespace Documents
Return pDocument
End Function
Public Function GetFieldValueFromColumn(pColumn As Template.Column, pSortKey As Integer) As DocumentRow.FieldValue
Return New DocumentRow.FieldValue With {
.DataType = pColumn.DataType,
.IsRequired = pColumn.IsRequired,
.IsVirtual = pColumn.Config.IsVirtual,
.PreferExternalValue = pColumn.Config.PreferExternalValue,
.SortKey = pSortKey
}
End Function
Private Async Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator, pTemplate As Template) As Task(Of Document)
Dim oMandators As List(Of Mandator) = pMandators.
@@ -361,8 +362,7 @@ Namespace Documents
Dim oValue = Database.GetScalarValue(oSQL)
If oValue IsNot Nothing Then
oField.Value.External = oValue
oField.Value.Final = oValue
oField.Value.SetExternalValue(oValue)
End If
Next
Next
@@ -494,7 +494,7 @@ Namespace Documents
Dim oValue As String = Utils.NotNull(oRawValue, String.Empty)
If oValue <> String.Empty Then
oField.Value.Final = oValue
oField.Value.SetExternalValue(oValue)
End If
Else
@@ -541,7 +541,7 @@ Namespace Documents
pDocument.Rows.
SelectMany(Function(row) row.Fields).
Where(Function(field) field.Key = oMapping.DestinationItem).
SetValue(Sub(field) field.Value.Final = oMapping.DestinationValue)
SetValue(Sub(field) field.Value.SetExternalValue(oMapping.DestinationValue))
Else
' don't do anything
@@ -602,8 +602,7 @@ Namespace Documents
Dim oArticlePrice As Double = Await Winline.TryGetArticlePriceAsync(oArticleNumber, oAccountNumber, oQuantity, oDocumentDate, pMandator, pTemplate, oWaitingDays)
If oArticlePrice > 0 Then
oPriceItem.External = oArticlePrice
oPriceItem.Final = oArticlePrice
oPriceItem.SetExternalValue(oArticlePrice)
Logger.Info("Price for Item [{0}] set to [{1}]", pPriceField, oArticlePrice)
Else
Logger.Warn("Price for Item [{0}] could not be found!", pPriceField)
@@ -613,9 +612,9 @@ Namespace Documents
Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String)
Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField)
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
If oArticleNumber IsNot Nothing Then
oNumberItem.External = oArticleNumber
oNumberItem.Final = oArticleNumber
oNumberItem.SetExternalValue(oArticleNumber)
Else
'oNumberItem.Error = FieldErrorType.ArticleNotFound
oNumberItem.AddFieldError(FieldErrorType.ArticleNotFound, $"EAN in Attribut '{pArticleField}' konnte nicht aufgelöst werden.")
@@ -639,12 +638,10 @@ Namespace Documents
' If an account was found, set it for External and Final value
If oAccount IsNot Nothing Then
oNumberItem.External = oAccount.Id
oNumberItem.Final = oAccount.Id
oNumberItem.SetExternalValue(oAccount.Id)
If oContainsAccountName Then
oNameItem.External = oAccount.Name
oNameItem.Final = oAccount.Name
oNameItem.SetExternalValue(oAccount.Name)
Else
' TODO: What to to if name field is missing or not set?
'oRow.Fields.Add(pNameField, New DocumentRow.FieldValue() With {
@@ -683,8 +680,7 @@ Namespace Documents
Dim oVersionedNumber = Await Winline.GetVersionedRunningNumberAsync(pDocument, pMandator, oAccountNumber, oRunningNumber)
If oVersionedNumber <> oRunningNumber Then
oRunningNumberItem.External = oVersionedNumber
oRunningNumberItem.Final = oVersionedNumber
oRunningNumberItem.SetExternalValue(oVersionedNumber)
End If
Catch ex As Exception