fix bug in Runningnumber versioning, improve handling of optional fields with functions

This commit is contained in:
Jonathan Jenne 2022-05-13 15:03:25 +02:00
parent e168c65ca9
commit dc657c32a5
2 changed files with 35 additions and 21 deletions

View File

@ -434,18 +434,29 @@ Namespace Documents
Dim oFunctionParams = oColumn.Config.FunctionParams Dim oFunctionParams = oColumn.Config.FunctionParams
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams) Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
If oFunctionName = FUNCTION_GLN Then ' The code below needs a defined function
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing, oParamsDict) If oFunctionName = String.Empty Then
Continue For
End If End If
If oFunctionName = FUNCTION_EAN Then ' The main identifier will be checked for String.empty and not required.
SetArticleByEAN(oRow, pMandator, oField.Key) ' 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 End If
If oFunctionName = FUNCTION_RUNNINGNUMBER Then Select Case oFunctionName
Await SetVersionedRunningNumber(pDocument, oRow, pMandator, oField.Key, oParamsDict) Case FUNCTION_GLN
End If 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
Next Next
@ -615,6 +626,11 @@ Namespace Documents
Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String) Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String)
Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField) 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) Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
If oArticleNumber IsNot Nothing Then If oArticleNumber IsNot Nothing Then
@ -655,12 +671,9 @@ Namespace Documents
'}) '})
End If End If
Else Else
' If no account was found and the field is required, ' If no account was found, mark it as error.
' mark it as error. Otherwise, do nothing. oNumberItem.AddFieldError(FieldErrorType.AccountNotFound, $"GLN in Attribut '{pNumberField}' konnte nicht aufgelöst werden.")
If oNumberItem.IsRequired Then
'oNumberItem.Error = FieldErrorType.AccountNotFound
oNumberItem.AddFieldError(FieldErrorType.AccountNotFound, $"GLN in Attribut '{pNumberField}' konnte nicht aufgelöst werden.")
End If
End If End If
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -668,7 +681,7 @@ Namespace Documents
End Try End Try
End Sub 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 Try
Const PARAMETER_ACCOUNT = "Account" Const PARAMETER_ACCOUNT = "Account"
Dim oAccountField As String = pParams.GetOrDefault(PARAMETER_ACCOUNT, Nothing) 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) Logger.Warn("Parameter '{0}' not found for Function RUNNINGNUMBER", PARAMETER_ACCOUNT)
End If End If
Dim oRunningNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pRunningNumberField) Dim oRunningNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pNumberField)
Dim oRunningNumber = oRunningNumberItem.Final 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 oAccountNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(oAccountField)
Dim oAccountNumber = oAccountNumberItem.Final Dim oAccountNumber = oAccountNumberItem.Final

View File

@ -536,7 +536,7 @@ Namespace Winline
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}" AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
Dim oTable As DataTable = Database.GetDatatable(oSQL) Dim oTable As DataTable = Database.GetDatatable(oSQL)
' EAN not found in this Mandator, continue to next one ' EAN not found in this Mandator
If oTable.Rows.Count = 0 Then If oTable.Rows.Count = 0 Then
Logger.Debug("EAN [{0}] was not found in Mandator: [{1}]", pEAN, pMandator.Id) Logger.Debug("EAN [{0}] was not found in Mandator: [{1}]", pEAN, pMandator.Id)
Return Nothing Return Nothing
@ -941,10 +941,10 @@ Namespace Winline
Logger.Debug("Running number [{0}] does not exist yet. Returning.", pRunningNumber) Logger.Debug("Running number [{0}] does not exist yet. Returning.", pRunningNumber)
Return pRunningNumber Return pRunningNumber
Else Else
Logger.Debug("Running number [{0}] already exists. Checking again.") Logger.Debug("Running number [{0}] already exists. Checking again.", pRunningNumber)
Dim oVersionResult = FileEx.GetVersionedString(pRunningNumber, "~"c) Dim oVersionResult = FileEx.GetVersionedString(pRunningNumber, "~"c)
Dim oNewVersion = oVersionResult.Item2 + 1
Dim oFinalLength As Integer = oVersionResult.Item1.Count + oVersionResult.Item2.ToString.Count + 1 Dim oFinalLength As Integer = oVersionResult.Item1.Count + oNewVersion.ToString.Count + 1
If oFinalLength > RunningNumberMaximumLength Then If oFinalLength > RunningNumberMaximumLength Then
Logger.Warn("Running number is too long ({0} chars total) and cannot be versioned. Versioning needs at least 2 characters.", oFinalLength) Logger.Warn("Running number is too long ({0} chars total) and cannot be versioned. Versioning needs at least 2 characters.", oFinalLength)
@ -952,7 +952,7 @@ Namespace Winline
Return pRunningNumber Return pRunningNumber
End If End If
Return Await GetVersionedRunningNumberAsync(pDocument, pMandator, pAccountNumber, $"{oVersionResult.Item1}~{oVersionResult.Item2}") Return Await GetVersionedRunningNumberAsync(pDocument, pMandator, pAccountNumber, $"{oVersionResult.Item1}~{oNewVersion}")
End If End If
Catch ex As MultiToolException Catch ex As MultiToolException