Not delete sales order

gemini_shooter
gemini_shooter Member Posts: 149
Hello Guys,

I am trying to modify the code 80 to prevent sales order from getting deleted.

I have able to keep the sales line but I am unable to keep the sales header.

I commented this part of the code for sales header but I am not sure if it is the right piece of code. Can someone please help


DocDim.RESET;
DocDim.SETRANGE("Table ID",DATABASE::"Sales Header");
DocDim.SETRANGE("Document Type","Document Type");
DocDim.SETRANGE("Document No.","No.");
// DocDim.DELETEALL;
DocDim.SETRANGE("Table ID",DATABASE::"Sales Line");
// DocDim.DELETEALL;

ApprovalMgt.DeleteApprovalEntry(DATABASE::"Sales Header","Document Type","No.");

IF HASLINKS THEN DELETELINKS;
DELETE;
ReserveSalesLine.DeleteInvoiceSpecFromHeader(SalesHeader);
IF SalesLine.FINDFIRST THEN REPEAT
IF SalesLine.HASLINKS THEN
;
// SalesLine.DELETELINKS;
UNTIL SalesLine.NEXT = 0;
// SalesLine.DELETEALL;
DeleteItemChargeAssgnt;
SalesCommentLine.SETRANGE("Document Type","Document Type");
SalesCommentLine.SETRANGE("No.","No.");
IF NOT SalesCommentLine.ISEMPTY THEN
// SalesCommentLine.DELETEALL;
WhseRqst.SETCURRENTKEY("Source Type","Source Subtype","Source No.");
WhseRqst.SETRANGE("Source Type",DATABASE::"Sales Line");
WhseRqst.SETRANGE("Source Subtype","Document Type");
WhseRqst.SETRANGE("Source No.","No.");
IF NOT WhseRqst.ISEMPTY THEN

Comments

  • reijermolenaar
    reijermolenaar Member Posts: 256
    Hi,

    Look for the variable EverythingInvoiced.
    Your records will only be deleted if this variable is true.

    Regards,
    Reijer Molenaar
    Object Manager
  • jannestig
    jannestig Member Posts: 1,000
    Or you could change your process so that you don't invoice from the order, but create the invoice manually then use copy document etc. This doesn't delete the sales order.
  • ssingla
    ssingla Member Posts: 2,973
    I am not sure of NAV 2009 but in earlier versions copy document does not update the remaining quantity on the original sales order which is correct also. This creates problem in calculating pending sales order.
    We can post shipment from sales order and then use Sales invoice function :get shipment lines and then invoice.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • David_Singleton
    David_Singleton Member Posts: 5,479
    Hello Guys,

    I am trying to modify the code 80 to prevent sales order from getting deleted.

    I have able to keep the sales line but I am unable to keep the sales header.

    This can have serious performance issues in a large database, or one where many users are entering orders. Be careful that you now what you are doing before you do this.

    Look at the order archive function first.
    David Singleton
  • kapil4dynamics
    kapil4dynamics Member Posts: 591
    One more option: Or u can receive using Sales Order and Invoice using Get Receipt Lines. Order will stay there.
    Kapil Khanna
  • ara3n
    ara3n Member Posts: 9,258
    I strongly suggest that you archive the Sales order and allow it to get deleted.
    Your MRP will be screwed up, Users will try to modify and repost old sales order,
    Performance as mentioned will go down the drain.
    You will not be able to upgrade your DB.

    Create separate tables and keep the data in separate table. This is the safest option.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kapamarou
    kapamarou Member Posts: 1,152
    ara3n wrote:
    I strongly suggest that you archive the Sales order and allow it to get deleted.
    Your MRP will be screwed up, Users will try to modify and repost old sales order,
    Performance as mentioned will go down the drain.
    You will not be able to upgrade your DB.

    Create separate tables and keep the data in separate table. This is the safest option.

    Been there thanks to the previous developers of a project I took over. So take David Singleton's
    and ara3n's advise. You'll be thankful you did!!! :wink:
  • gemini_shooter
    gemini_shooter Member Posts: 149
    Thanks guys... this is just a test and not in a live setup.

    All I want to do is to prevent the Sales header from being deleted.

    Can anyone tell me where in code or how does this happen.
  • ara3n
    ara3n Member Posts: 9,258
    CU 80 has a

    with salesheader do begin



    end


    So search for just DELETE;

    somebody allready mentioned to look the section that has has everything invoiced.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • gemini_shooter
    gemini_shooter Member Posts: 149
    I commented this part of the code. The sales lines do not get deleted but the sales header still does. Am I still missing something


    DocDim.RESET;
    DocDim.SETRANGE("Table ID",DATABASE::"Sales Header");
    DocDim.SETRANGE("Document Type","Document Type");
    DocDim.SETRANGE("Document No.","No.");
    // DocDim.DELETEALL;
    DocDim.SETRANGE("Table ID",DATABASE::"Sales Line");
    // DocDim.DELETEALL;
  • ara3n
    ara3n Member Posts: 9,258
    Keep looking down a couple of lines and you will see

    DELETE;


    THIS IS THE LINE.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Miklos_Hollender
    Miklos_Hollender Member Posts: 1,598
    Old topic, but as I met the same problem: no, it is not necessarily a bad practice as long as they are regularly deleted by using Report 299. For example every quarter or year.

    If you have a lot of reports or complicated ones that involve orders, also fully invoiced one - e.g. I send out automatically to salespeople every day a report showing the last 3 months of sales orders, showing their status, shipped, invoiced, so they can check how things went - it is easier to turn off automatic deletion and simply run this report as a part of a regular maintenance.

    And yes, the elegant solution is something along the lines of

    IF SalesSetup."Do not delete invoiced orders" THEN
    EverythingInvoiced := FALSE;