What is the best way to duplicate a sales document from an uncertified series for a VBA-certified sales document?

0

I have an ECL with a non-emissive series and I intend that at the time of writing it, another CECL sales document with an emissive series is created. The documents are exactly the same.

The code below gives the following error:

  

The [2017] series of the [CECL] document has documents certified by a different application than the current one. To save the document you will need to create a new series.

Note: There is no CECL document yet. Note 2: I did not want to pass field by field and line the line from the original document to the destination. I think that's not necessary.

Dim newDoc As New GcpBEDocumentoVenda
Set newDoc = Me.DocumentoVenda
newDoc.Tipodoc = "CECL"
newDoc.EmModoEdicao = False
BSO.Comercial.Vendas.PreencheDadosRelacionados newDoc, PreencheRelacaoVendas.vdDadosTipoDoc
BSO.Comercial.Vendas.Actualiza newDoc
    
asked by anonymous 30.05.2018 / 17:19

2 answers

1

Although you do not know the context in which this code is inserted, not all the properties of the documents, at first glance you may notice that you need to set an important property in the header and lines: the ID .

The code below works, but does not take into account, for example, articles with dimensions (due to changing the ID, the child articles do not "know" the parent line ID), where some extra validation would be necessary: / p>

Dim objDocVenda As GcpBEDocumentoVenda
Dim objLinha    As GcpBELinhaDocumentoVenda

Set objDocVenda = Me.DocumentoVenda

With objDocVenda
    .TipoDoc = "CECL"
    .EmModoEdicao = False
    .Id = PlataformaPRIMAVERA.FuncoesGlobais.CriaGuid(True)
End With

For Each objLinha In objDocVenda.Linhas
    objLinha.IDLinha = PlataformaPRIMAVERA.FuncoesGlobais.CriaGuid(True)
Next

BSO.Comercial.Vendas.PreencheDadosRelacionados objDocVenda, PreencheRelacaoVendas.vdDadosTipoDoc
BSO.Comercial.Vendas.Actualiza objDocVenda

The code assumes that the same series exists in the CECL document, otherwise we would have to define it before writing the new document.

If you want to send the document via engines, just call the EmiteDocumento method:

Set objDocVenda = BSO.Comercial.Vendas.EmiteDocumento(Me.DocumentoVenda, "2018E")
    
30.05.2018 / 17:56
1

I think what is needed and clone the object to another in order to be able to manipulate the properties later on the copied object without changing the original object.

Sample code

Private Sub EditorVendas_DepoisDeEditar()
Dim objCopia As GcpBEDocumentoVenda

Set objCopia = New GcpBEDocumentoVenda

' Clona o objeto de origem
Set objCopia = PSO.FuncoesGlobais.ClonaObjecto(Me.DocumentoVenda)

ObjCopia.Tipodoc = "CECL"

BSO.Comercial.Vendas.Atualiza objCopia

End Sub
    
30.05.2018 / 22:46