Can't automatically post sales order with item charges

dulinfdulinf Member Posts: 5
Hello,

I want automatic sales order to be posted while i post warehouse shipment for this order.
My sales order contains assigned item charge.

I post shipment but sales order stay. i should post it manualy.
Can sales order be automatic posted while posting shipment?

I use SetShipInvoice(TRUE, TRUE) function to autopost sales order and it works perfectly without Item Charge.
With item charge i get an error = "Qty. To Assign should be 0".

Comments

  • Alex_ChowAlex_Chow Member Posts: 5,063
    You also need to put in code to allocate the item charge automatically.
  • dulinfdulinf Member Posts: 5
    Charges allocates manually before shipment post.

    But Post Shipment post drops "Qty. to Ship" for Item Charges and then several line of code below rises error - because Qty. to Assign > Qty. To Ship.

    If SalesLine.SHIP then Qty. To Ship := 0;

    But i set Salesline.ship and SalesLine.invoice manually by code in the begining of the Post.

    NAV 5.0 SP1
  • ara3nara3n Member Posts: 9,256
    Try and manually post a sales invoice with item charge and see how it works.
    Then mimic that in your code.

    Item charge has sub table where you are allocating the amount. Then on Sales line you populate qty to assign.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • libin80libin80 Member Posts: 24
    Hi,

    I see this is a very old post. I encountered this issue today and fixed it :lol: . Thought to share the solution with you guys.

    First Solution to solve the error message "You cannot assign more than 0 units in Document Type = Order, Document No. [Document_Number], Line No. = [Line_Number]" is available in KB 960039
    http://support.microsoft.com/kb/960039

    All you have to do is
    1.Change the code in the CopyAndCheckItemCharge function in the Sales-Post codeunit (80) as follows:
    
    [u]Existing code[/u]
    ...
    SalesLine2.SETRANGE(Type,SalesLine2.Type::"Charge (Item)");
    IF SalesLine2.ISEMPTY THEN
      EXIT;
    ...
    
    
    [u] Replacement code[/u]
    ...
    SalesLine2.SETRANGE(Type,SalesLine2.Type::"Charge (Item)");
    
    // Add the following line.
    SalesLine2.SETFILTER("Qty. to Invoice",'<>0');                                 
    
    IF SalesLine2.ISEMPTY THEN
      EXIT;
    ...
    

    This Hotfix fixes the error message. Now you can post the Warehouse shipment, but the charge item will not get posted. you have to post it manually. :roll:

    The reason for the Charge Item not getting posted while posting Warehouse shipment is codeunit 5763 - Whse.-Post Shipment.

    This codeunit changes the "Qty. to Ship" of the Charge Item to 0, before calling Codeunit 80 - Sales-Post.

    Solution
    In function "InitSourceDocumentLines()" find the below code and make the changes as mentioned
                  ModifyLine :=
                    ((SalesHeader."Shipping Advice" <> SalesHeader."Shipping Advice"::Complete) OR
                     (SalesLine.Type = SalesLine.Type::Item)) AND
                    ((SalesLine."Qty. to Ship" <> 0) OR
                     (SalesLine."Return Qty. to Receive" <> 0) OR
                     (SalesLine."Qty. to Invoice" <> 0));
    
    
                   IF SalesLine.Type = SalesLine.Type::"Charge (Item)" THEN               //Add this line
                       ModifyLine := FALSE;                                                                 //Add this line
    
                  IF ModifyLine THEN BEGIN
                    IF "Source Document" = "Source Document"::"Sales Order" THEN
                      SalesLine.VALIDATE("Qty. to Ship",0)
                    ELSE
                      SalesLine.VALIDATE("Return Qty. to Receive",0);
                    SalesLine.VALIDATE("Qty. to Invoice",0);
                  END;
    


    Now, if you have the Charge Item assigned to the lines in the Sales Order, then when you post the warehsouse Shipment, the charge Item will also get posted. :thumbsup: :D

    Hope, it will solve your problem, If you still have it.

    Thanks
    Libin D
Sign In or Register to comment.