Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Cant post partial invoice by code with x++ (PO was partial too)

Posted on by 12

I hope to get a correct answer thats why i will be as detailed as possible because this is a problem we are dealing with for a while now.

Example:

We have a sales order with 1 position which has 1 Line with quantity 30.

We have a purchase order with that 1 position and 30 quantity.

We created 2 Product Receipt one with 14 and one with 16 quantity.

And now we want to invoice 12 and 16. (We invoice Per PackingSlip)

If i do it manually it is possible in the saleseditlines form but i have to do it in x++ because we are creating an automation project so customers can invoice it themselves.

My code Creates the sales parm lines and edits the deliver now field salesupdate is on delivernow on salesformletter and salesparmupdate

i create the salesformletter and let it run when it runs it gets me an error in this specific example.

the error is: "Insufficient inventory transactions with status picked"

but as i already said with the manual way it does not throw any error

my Salesparmline creation looks like this: (i did not copy the while loop)

            salesParmLine = null;
            salesParmLine.initFromSalesLine(salesLine);
            salesParmLine.DeliverNow = postableQty;

            salesParmLine.ParmId = salesParmTable.ParmId;
            salesParmLine.TableRefId = salesParmTable.TableRefId;

            if(pckngSlpForInSalesInvoice.exists(inSalesInvoiceLine.RecId))
            {
                custPackingSlipTrans = pckngSlpForInSalesInvoice.lookup(inSalesInvoiceLine.RecId);
                salesParmLine.PBS_PackingSlipTransRecId = custPackingSlipTrans.RecId; //here we get the packing slip for the salesline and use it to invoice per packing slip
            }

            salesParmLine.setQty(DocumentStatus::Invoice, false, true);
            salesParmLine.setInventDeliverNow();
            salesParmLine.setLineAmount();

            salesParmLine.insert();

SalesParmTable:

        salesParmTable.clear();

        salesParmTable.initFromSalesTable(salesTable);
        if(_isFirstInvoice)
        {
            salesParmTable.Transdate = _inSalesInvoiceHeader.InvoiceDate;
        }
        else
        {
            salesParmTable.Transdate = systemDateGet();
        }
        salesParmTable.DocumentDate = _inSalesInvoiceHeader.InvoiceDate;
        //<-- PBS/DAUER/T10000177434/27.01.2022
        salesParmTable.Ordering = DocumentStatus::Invoice;
        salesParmTable.ParmJobStatus = ParmJobStatus::Waiting;
        salesParmTable.SalesId = salesTable.SalesId;
        salesParmTable.SalesName = salesTable.SalesName;
        salesParmTable.DeliveryName = salesTable.DeliveryName;
        salesParmTable.DeliveryPostalAddress = salesTable.DeliveryPostalAddress;
        salesParmTable.CustAccount = salesTable.CustAccount;
        salesParmTable.CurrencyCode = _inSalesInvoiceHeader.CurrencyCode;
        salesParmTable.InvoiceAccount = salesTable.InvoiceAccount;
        salesParmTable.ParmId = salesParmUpdate.ParmId;
        salesParmTable.BatchAdministration = NoYes::Yes;
        salesParmTable.DlvMode = salesTable.DlvMode;
        salesParmTable.DlvTerm = salesTable.DlvTerm;
        salesParmTable.InventSiteId = salesTable.InventSiteId;


        if(_inSalesInvoiceHeader.InvoiceOrSelfBilling == PBS_InvoiceSelfBilling::Self_Billing)
        {
            salesParmTable.Num_W = _inSalesInvoiceHeader.getSelfBillingAXInvoiceIdWithCounter();
        }
        else
        {
            salesParmTable.Num_W = _inSalesInvoiceHeader.AXInvoiceId;         // FF/WSCH/T10000138245/28.06.2021
        }
        salesParmTable.insert();

salesform letter:

    salesFormLetter.transDate(_inSalesInvoiceHeader.InvoiceDate);
    salesFormLetter.proforma(false);
    salesFormLetter.specQty(SalesUpdate::All);
    salesFormLetter.salesTable(salesTable);
    salesFormLetter.initParmSalesTable(salesFormLetter.salesTable());
    salesFormLetter.printCODLabel(NoYes::No);
    salesFormLetter.printShippingLabel(NoYes::No);
    salesFormLetter.parmId(salesParmTable.ParmId);
    salesFormLetter.salesParmUpdate(salesFormletterParmData.parmParmUpdate());
    salesFormLetter.printFormLetter(false);
    salesFormLetter.usePrintManagement(true); // do not pring
    salesFormLetter.sumBy(AccountOrder::Account);
    //salesFormLetter.chooseLines(false, false);

    salesFormLetter.initParameters(salesParmUpdate.data(),
                                    Printout::Current,
                                    NoYes::No,
                                    NoYes::No,
                                    NoYes::No,
                                    NoYes::No,
                                    true,
                                    NoYes::No,
                                    NoYes::No,
                                    PlFiscalDocType::Invoice,
                                    NoYes::No);

    salesFormLetter.reArrangeNow(true);
    salesFormLetter.editLinesChanged(true);
    salesFormLetter.enableUpdateNowField(true);


    salesFormLetter.run();

i hope you can help me and show me what is missing so i can invoice partially on partial PO's

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans