fix bug in Runningnumber versioning, improve handling of optional fields with functions
This commit is contained in:
@@ -434,18 +434,29 @@ Namespace Documents
|
||||
Dim oFunctionParams = oColumn.Config.FunctionParams
|
||||
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
|
||||
|
||||
If oFunctionName = FUNCTION_GLN Then
|
||||
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing, oParamsDict)
|
||||
' The code below needs a defined function
|
||||
If oFunctionName = String.Empty Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If oFunctionName = FUNCTION_EAN Then
|
||||
SetArticleByEAN(oRow, pMandator, oField.Key)
|
||||
' The main identifier will be checked for String.empty and not required.
|
||||
' This makes sure that optional fields do not generate errors.
|
||||
Dim oIdentifier As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key)
|
||||
If oIdentifier.Original = String.Empty And oIdentifier.IsRequired = False Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If oFunctionName = FUNCTION_RUNNINGNUMBER Then
|
||||
Await SetVersionedRunningNumber(pDocument, oRow, pMandator, oField.Key, oParamsDict)
|
||||
End If
|
||||
Select Case oFunctionName
|
||||
Case FUNCTION_GLN
|
||||
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing, oParamsDict)
|
||||
|
||||
Case FUNCTION_EAN
|
||||
SetArticleByEAN(oRow, pMandator, oField.Key)
|
||||
|
||||
Case FUNCTION_RUNNINGNUMBER
|
||||
Await SetVersionedRunningNumber(pDocument, oRow, pMandator, oField.Key, oParamsDict)
|
||||
|
||||
End Select
|
||||
Next
|
||||
Next
|
||||
|
||||
@@ -615,6 +626,11 @@ Namespace Documents
|
||||
|
||||
Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String)
|
||||
Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField)
|
||||
|
||||
If oNumberItem Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
|
||||
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
@@ -655,12 +671,9 @@ Namespace Documents
|
||||
'})
|
||||
End If
|
||||
Else
|
||||
' If no account was found and the field is required,
|
||||
' mark it as error. Otherwise, do nothing.
|
||||
If oNumberItem.IsRequired Then
|
||||
'oNumberItem.Error = FieldErrorType.AccountNotFound
|
||||
oNumberItem.AddFieldError(FieldErrorType.AccountNotFound, $"GLN in Attribut '{pNumberField}' konnte nicht aufgelöst werden.")
|
||||
End If
|
||||
' If no account was found, mark it as error.
|
||||
oNumberItem.AddFieldError(FieldErrorType.AccountNotFound, $"GLN in Attribut '{pNumberField}' konnte nicht aufgelöst werden.")
|
||||
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
@@ -668,7 +681,7 @@ Namespace Documents
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Async Function SetVersionedRunningNumber(pDocument As Document, pRow As DocumentRow, pMandator As Mandator, pRunningNumberField As String, pParams As Dictionary(Of String, String)) As Task
|
||||
Public Async Function SetVersionedRunningNumber(pDocument As Document, pRow As DocumentRow, pMandator As Mandator, pNumberField As String, pParams As Dictionary(Of String, String)) As Task
|
||||
Try
|
||||
Const PARAMETER_ACCOUNT = "Account"
|
||||
Dim oAccountField As String = pParams.GetOrDefault(PARAMETER_ACCOUNT, Nothing)
|
||||
@@ -676,9 +689,10 @@ Namespace Documents
|
||||
Logger.Warn("Parameter '{0}' not found for Function RUNNINGNUMBER", PARAMETER_ACCOUNT)
|
||||
End If
|
||||
|
||||
Dim oRunningNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pRunningNumberField)
|
||||
Dim oRunningNumber = oRunningNumberItem.Final
|
||||
Dim oRunningNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pNumberField)
|
||||
Dim oRunningNumber = oRunningNumberItem.Original
|
||||
|
||||
' We use the Final value to work with the actual account number, not the GLN
|
||||
Dim oAccountNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(oAccountField)
|
||||
Dim oAccountNumber = oAccountNumberItem.Final
|
||||
|
||||
|
||||
Reference in New Issue
Block a user