User field behavior when using the AddTransformed method in sales. (V9.15 and C #)

0

When creating an Invoice with lines to be transformed from one or more orders, I know that the BSO.Commercial method Sales.AddedTransformedLine works correctly and makes the transformation due to the management of the quantities as well as other rules.

However, if you want to update the user fields in the Invoice lines to be created, the same ones, although apparently well filled, both before and after the Document update method, as I was able to confirm after querying the debugged object in the Visual Studio Watch, are never updated in the database. The pseudo-code used is the following:

GcpBEDocumentoVenda fatura = new GcpBEDocumentoVenda();

//atribuir dados do cabeçalho
fatura.set_Tipodoc("FA")
etc...

BSO.Comercial.Vendas.PreencheDadosRelacionados(fatura);

//percorrer encomendas de origem a transformar
foreach (encomenda...)
{
    //percorrer linhas de cada encomenda
    foreach (linha in encomenda...)
    {
        //CÓDIGO REAL:
        BSO.Comercial.Vendas.AdicionaLinhaTransformada
                        (
                        fatura
                        , encomenda.TipoDoc
                        , encomenda.NumDoc
                        , linha.NumLinhaNossaEncomenda
                        , strSerieEnc: encomenda.Serie
                        , QuantSatisf: linha.QtFaturar
                        );

        //obter última linha inserida
        GcpBELinhaDocumentoVenda linhaDocumentoVenda = fatura.get_Linhas()[fatura.get_Linhas().NumItens];

        //actualizar os CDUs
        linhaDocumentoVenda.get_CamposUtil().get_Item("CDU_Teste1").Valor = "Teste1";
        linhaDocumentoVenda.get_CamposUtil().get_Item("CDU_Teste2").Valor = "Teste2";
        etc...
    }
}

//gravar documento
string avisos = "";
BSO.Comercial.Vendas.Actualiza(fatura, avisos);

I hope it's noticeable. It works everything as expected except the user fields. Anything you're doing less well? Thank you in advance.

    
asked by anonymous 14.12.2018 / 18:27

1 answer

3

Good morning,

As John said, it is important that the name of the user fields is the same as the one in the database (case sensitive). You can get these names through this simple query in the database:

SELECT * FROM StdCamposVar WHERE Tabela = 'LinhasDoc'

You can also enable SQL Server Profile to try to understand what is being written to the database.

I've made a few minor changes to the supplied code in order to turn an order into an invoice in a demo company.

public void TransformEncToFA(string idEnc)
{
    GcpBEDocumentoVenda fatura = new GcpBEDocumentoVenda();

    GcpBEDocumentoVenda encomenda = new GcpBEDocumentoVenda();
    encomenda = Globals.MotorERP.Comercial.Vendas.EditaID(idEnc);

    //atribuir dados do cabeçalho
    fatura.set_TipoEntidade("C");
    fatura.set_Entidade("SOFRIO");
    fatura.set_Tipodoc("FA");
    fatura.set_Serie("C");

    Globals.MotorERP.Comercial.Vendas.PreencheDadosRelacionados(fatura);

    int numLinhaEnc = 0;

    //percorrer linhas de cada encomenda
    foreach (GcpBELinhaDocumentoVenda linhaenc in encomenda.get_Linhas())
    {
        numLinhaEnc += 1;

        //CÓDIGO REAL:
        Globals.MotorERP.Comercial.Vendas.AdicionaLinhaTransformada
            (
                fatura
                , encomenda.get_Tipodoc()
                , encomenda.get_NumDoc()
                , numLinhaEnc
                , strSerieEnc: encomenda.get_Serie()
                , QuantSatisf: linhaenc.get_Quantidade()
            );

        //obter última linha inserida
        GcpBELinhaDocumentoVenda linhaDocumentoVenda = fatura.get_Linhas()[fatura.get_Linhas().NumItens];

        //actualizar os CDUs
        linhaDocumentoVenda.get_CamposUtil().get_Item("CDU_LinVar1").Valor = "Teste1";
        linhaDocumentoVenda.get_CamposUtil().get_Item("CDU_LinVar2").Valor = "Teste2";
    }

    //gravar documento
    string avisos = "";
    Globals.MotorERP.Comercial.Vendas.Actualiza(fatura, avisos);
}

Try running the same code on one of these companies and make sure it works.

    
19.12.2018 / 14:03