Deleting Invoiced Sales Orders

DavedaveDavedave Member Posts: 88
Hi all,

I have just posted a Combined Shipment using the Sales Invoice and now the original Sales Order is left behind. It has been completely shipped and invoiced.

I have tried using the Delete Invoiced Sales Orders batch (R299) but everytime I run it, nothing happens. And when I go check my Sales Orders, the completed ones are still there.

I don't think my Sales Orders have any problems because I can manually delete them. Just not able to do it from the batch job...

Is there anything I am doing wrong?

Thanks
Dave

Answers

  • garakgarak Member Posts: 3,263
    Hi,

    is the "Quantity Invoiced" in all lines <>0 :?:
    is the "Outstanding Quantity" in all lines <>0 :?:
    is the "Qty. Shipped Not Invoiced" in al lines <>0 :?:
    are there some Charge (Item) lines without a "Qty. Assigned" :?:

    If all is fine, start the report in debugmode (if you have the permissions)

    Regards
    Do you make it right, it works too!
  • mart1n0mart1n0 Member Posts: 123
    There is a bug in this report, which makes that orders are never deleted.

    Make the following change in the Sales Header - OnAfterGetRecord() trigger

    IF SalesOrderLine.FIND('-') THEN
              REPEAT
                SalesOrderLine.CALCFIELDS("Qty. Assigned");
                IF ((SalesOrderLine."Qty. Assigned" = SalesOrderLine."Quantity  Invoiced") OR
                   (SalesOrderLine.Type <> SalesOrderLine.Type::"Charge (Item)")) AND
    
                   // OLD CODE
                   //(SalesOrderLine."Qty. Assigned" <> 0)
                   // NEW CODE
                   (SalesOrderLine."Qty. Assigned" = 0)
    
                THEN BEGIN
                  DocDim.SETRANGE("Line No.",SalesOrderLine."Line No.");
                  DocDim.DELETEALL;
                  IF SalesOrderLine.Type = SalesOrderLine.Type::"Charge (Item)" THEN BEGIN
                    ItemChargeAssgntSales.SETRANGE("Document Line No.",SalesOrderLine."Line No.");
                    ItemChargeAssgntSales.DELETEALL;
                  END;
                  IF SalesOrderLine.HASLINKS THEN
                    SalesOrderLine.DELETELINKS;
                  SalesOrderLine.DELETE;
                END ELSE
                  AllLinesDeleted := FALSE;
    

    This should do the trick.

    And while your at it maybe also have a look at Report 6651 - Delete Invd Sales Ret. Orders, which does the same for the return orders.

    Here change the following in the Sales Header - OnAfterGetRecord() trigger:

    SalesOrderLine.SETFILTER("Return Qty. Rcd. Not Invd.",'<>0');
        IF NOT SalesOrderLine.FIND('-') THEN BEGIN
          SalesOrderLine.LOCKTABLE;
          IF NOT SalesOrderLine.FIND('-') THEN BEGIN
            SalesOrderLine.SETRANGE("Return Qty. Rcd. Not Invd.");
            DocDim.SETRANGE("Table ID",DATABASE::"Sales Line");
            IF SalesOrderLine.FIND('-') THEN
              REPEAT
                SalesOrderLine.CALCFIELDS("Qty. Assigned");
                IF ((SalesOrderLine."Qty. Assigned" = SalesOrderLine."Quantity Invoiced") OR
                   (SalesOrderLine.Type <> SalesOrderLine.Type::"Charge (Item)")) AND
      
                   // OLD CODE
                   //(SalesOrderLine."Qty. Assigned" <> 0)
                   // NEW CODE
                   (SalesOrderLine."Qty. Assigned" = 0)
    
                THEN BEGIN
                  DocDim.SETRANGE("Line No.",SalesOrderLine."Line No.");
                  DocDim.DELETEALL;
    
  • ajhvdbajhvdb Member Posts: 672
    Thx, I knew it was a bug in 4.x and thought it would be repaired in 5.x NOT :roll:

    Update:
    :oops: in 5.1 it's fixed
  • DavedaveDavedave Member Posts: 88
    Oh, looks like there was a bug with the batch job after all.

    Thanks for the help guys! Very much appreciated
Sign In or Register to comment.