Missing code for copy Charge (Item) assignment when Shipment on Invoice = FALSE in table 311
Hi,
The case is: Table 311 "Sales & Receivables Setup" - field 6 -Shipment on Invoice = FALSE; In Sales Order we have line with type Charge (Item); After assign and post we have Item Ledger Entry with Document Type = Sales Invoice ( instead "Sales Shipment" when this setup Shipment on Invoice = TRUE)
and problem is when we try to copy this posted invoice to new document (for example sales credit memo); Could you add aslo code for ItemLedgerEntry."Document Type"::"Sales Invoice" in codeunit 6620? The same case is valid for purchase.
LOCAL CopyFromSalesLineItemChargeAssign(FromSalesLine : Record "Sales Line";ToSalesLine : Record ....................
IF ValueEntry.FINDSET THEN BEGIN REPEAT IF ItemLedgerEntry.GET(ValueEntry."Item Ledger Entry No.") THEN IF ItemLedgerEntry."Document Type" = ItemLedgerEntry."Document Type"::"Sales Shipment" THEN BEGIN Item.GET(ItemLedgerEntry."Item No."); CurrencyFactor := FromSalesHeader."Currency Factor"; IF NOT Currency.GET(FromSalesHeader."Currency Code") THEN BEGIN CurrencyFactor := 1; Currency.InitRoundingPrecision; END; QtyToAssign := ValueEntry."Cost Amount (Actual)" * CurrencyFactor / ToSalesLine."Unit Price"; SumQtyToAssign += QtyToAssign; ItemChargeAssgntSales.InsertItemChargeAssgntWithAssignValues( ToItemChargeAssignmentSales,ToItemChargeAssignmentSales."Applies-to Doc. Type"::Shipment, ItemLedgerEntry."Document No.",ItemLedgerEntry."Document Line No.",ItemLedgerEntry."Item No.",Item.Description, QtyToAssign,0,ItemChargeAssgntNextLineNo); END; // begin new code IF ItemLedgerEntry."Document Type" = ItemLedgerEntry."Document Type"::"Sales Invoice" THEN BEGIN Item.GET(ItemLedgerEntry."Item No."); CurrencyFactor := FromSalesHeader."Currency Factor"; IF NOT Currency.GET(FromSalesHeader."Currency Code") THEN BEGIN CurrencyFactor := 1; Currency.InitRoundingPrecision; END; QtyToAssign := ValueEntry."Cost Amount (Actual)" * CurrencyFactor / ToSalesLine."Unit Price"; SumQtyToAssign += QtyToAssign; ItemChargeAssgntSales.InsertItemChargeAssgntWithAssignValues( ToItemChargeAssignmentSales,ToItemChargeAssignmentSales."Applies-to Doc. Type"::Invoice, ItemLedgerEntry."Document No.",ItemLedgerEntry."Document Line No.",ItemLedgerEntry."Item No.",Item.Description, QtyToAssign,0,ItemChargeAssgntNextLineNo); END; // end new code UNTIL ValueEntry.NEXT = 0;
========================================= LOCAL CopyFromPurchLineItemChargeAssign(FromPurchLine : Record "Purchase Line";ToPurchLine : Record "Purchase Line";FromPurchHeader : Record "Purchase Header";VAR ItemChargeAssgntNextLineNo : Integer) ............................................
IF ValueEntry.FINDSET THEN BEGIN REPEAT IF ItemLedgerEntry.GET(ValueEntry."Item Ledger Entry No.") THEN IF ItemLedgerEntry."Document Type" = ItemLedgerEntry."Document Type"::"Purchase Receipt" THEN BEGIN Item.GET(ItemLedgerEntry."Item No."); CurrencyFactor := FromPurchHeader."Currency Factor"; IF NOT Currency.GET(FromPurchHeader."Currency Code") THEN BEGIN CurrencyFactor := 1; Currency.InitRoundingPrecision; END; QtyToAssign := ValueEntry."Cost Amount (Actual)" * CurrencyFactor / ToPurchLine."Unit Cost"; SumQtyToAssign += QtyToAssign; ItemChargeAssgntPurch.InsertItemChargeAssgntWithAssignValues( ToItemChargeAssignmentPurch,ToItemChargeAssignmentPurch."Applies-to Doc. Type"::Receipt, ItemLedgerEntry."Document No.",ItemLedgerEntry."Document Line No.",ItemLedgerEntry."Item No.",Item.Description, QtyToAssign,0,ItemChargeAssgntNextLineNo); END; // begin new code IF ItemLedgerEntry."Document Type" = ItemLedgerEntry."Document Type"::"Purchase Invoice" THEN BEGIN Item.GET(ItemLedgerEntry."Item No."); CurrencyFactor := FromPurchHeader."Currency Factor"; IF NOT Currency.GET(FromPurchHeader."Currency Code") THEN BEGIN CurrencyFactor := 1; Currency.InitRoundingPrecision; END; QtyToAssign := ValueEntry."Cost Amount (Actual)" * CurrencyFactor / ToPurchLine."Unit Cost"; SumQtyToAssign += QtyToAssign; ItemChargeAssgntPurch.InsertItemChargeAssgntWithAssignValues( ToItemChargeAssignmentPurch,ToItemChargeAssignmentPurch."Applies-to Doc. Type"::Invoice, ItemLedgerEntry."Document No.",ItemLedgerEntry."Document Line No.",ItemLedgerEntry."Item No.",Item.Description, QtyToAssign,0,ItemChargeAssgntNextLineNo); END; // end new code UNTIL ValueEntry.NEXT = 0;
If you want to use Item Charges, you must have Shipment on Invoice = TRUE.
Why is it obligatory? Is there any NAV documentation/guide that refers to your statement?
It's not mandatory to have Shipment on Invoice set to True, but in this case you can distribute item charges only in the current document and not to posted one (you cannot assign item charges to posted invoice, only receipt).
Your repro steps refer to Order, but I assume it's wrong - if you post shipment from Order, then Document Type will be always Shipment irrespective the Shipment on Invoice setting. Probably you meant Invoice. In this case the "Create Corrective Credit Memo" action doesn't copy item charge assignment from posted invoice and I agree this looks like a missed scenario.
I would recommend to report it via https://aka.ms/ideas
Closing as per Andrei's comment.