fix bug in Runningnumber versioning, improve handling of optional fields with functions
This commit is contained in:
parent
e168c65ca9
commit
dc657c32a5
@ -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
|
||||
|
||||
|
||||
@ -536,7 +536,7 @@ Namespace Winline
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
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
|
||||
Logger.Debug("EAN [{0}] was not found in Mandator: [{1}]", pEAN, pMandator.Id)
|
||||
Return Nothing
|
||||
@ -941,10 +941,10 @@ Namespace Winline
|
||||
Logger.Debug("Running number [{0}] does not exist yet. Returning.", pRunningNumber)
|
||||
Return pRunningNumber
|
||||
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 oFinalLength As Integer = oVersionResult.Item1.Count + oVersionResult.Item2.ToString.Count + 1
|
||||
Dim oNewVersion = oVersionResult.Item2 + 1
|
||||
Dim oFinalLength As Integer = oVersionResult.Item1.Count + oNewVersion.ToString.Count + 1
|
||||
|
||||
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)
|
||||
@ -952,7 +952,7 @@ Namespace Winline
|
||||
Return pRunningNumber
|
||||
End If
|
||||
|
||||
Return Await GetVersionedRunningNumberAsync(pDocument, pMandator, pAccountNumber, $"{oVersionResult.Item1}~{oVersionResult.Item2}")
|
||||
Return Await GetVersionedRunningNumberAsync(pDocument, pMandator, pAccountNumber, $"{oVersionResult.Item1}~{oNewVersion}")
|
||||
End If
|
||||
|
||||
Catch ex As MultiToolException
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user