-
Notifications
You must be signed in to change notification settings - Fork 452
[Master]-[Subcontracting] Purchase Return Order cannot be posted for subcontracting, while Corrective Credit Memo works well #11009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ using Microsoft.Manufacturing.Routing; | |
| using Microsoft.Manufacturing.Setup; | ||
| using Microsoft.Manufacturing.WorkCenter; | ||
| using Microsoft.Purchases.Document; | ||
| using Microsoft.Purchases.History; | ||
| using Microsoft.Purchases.Setup; | ||
| using Microsoft.Purchases.Vendor; | ||
| using Microsoft.Sales.Document; | ||
|
|
@@ -3793,6 +3794,69 @@ codeunit 137063 "SCM Manufacturing 7.0" | |
| Assert.AreEqual(SKURoutingHeader."No.", ProdOrderLine."Routing No.", ProductionRoutingErr); | ||
| end; | ||
|
|
||
| [Test] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test PostPurchaseReturnOrderForSubcontractingWhenLastOperationIsNotSubcontracted() calls CreateSubcontractingSetup(...), but that local procedure is defined only inside Suggested fix (apply manually — could not be anchored as a one-click suggestion): #if not CLEAN29
[Test]
[HandlerFunctions('PostedPurchaseDocumentLinesPageHandler')]
procedure PostPurchaseReturnOrderForSubcontractingWhenLastOperationIsNotSubcontracted()
...
end;
#endifAgent judgement — not directly backed by a BCQuality knowledge article. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.36.6 |
||
| [HandlerFunctions('PostedPurchaseDocumentLinesPageHandler')] | ||
| procedure PostPurchaseReturnOrderForSubcontractingWhenLastOperationIsNotSubcontracted() | ||
| var | ||
| CapacityUnitOfMeasure: Record "Capacity Unit of Measure"; | ||
| Item: Record Item; | ||
| ProductionOrder: Record "Production Order"; | ||
| PurchaseHeader: Record "Purchase Header"; | ||
| PurchaseLine: Record "Purchase Line"; | ||
| PurchInvLine: Record "Purch. Inv. Line"; | ||
| RequisitionLine: Record "Requisition Line"; | ||
| RoutingHeader: Record "Routing Header"; | ||
| RoutingLine: Record "Routing Line"; | ||
| SubcontractingWorkCenter: Record "Work Center"; | ||
| WorkCenter: Record "Work Center"; | ||
| OperationNo: Code[10]; | ||
| begin | ||
| // [FEATURE] [AI test 0.4] | ||
| // [SCENARIO 647380] A subcontracting purchase return order can be posted when a later operation is not subcontracted. | ||
| Initialize(); | ||
|
|
||
| // [GIVEN] A released production order whose subcontracting operation is followed by a non-subcontracting operation. | ||
| OperationNo := Format(10 + LibraryRandom.RandInt(10)); | ||
| CreateSubcontractingSetup(SubcontractingWorkCenter, RoutingHeader, OperationNo); | ||
| UpdateRoutingStatus(RoutingHeader, RoutingHeader.Status::"Under Development"); | ||
| CreateWorkCenterSetup(WorkCenter, CapacityUnitOfMeasure.Type::Minutes, 160000T, 235959T); | ||
| CreateRoutingLine(RoutingLine, RoutingHeader, WorkCenter."No."); | ||
| UpdateRoutingStatus(RoutingHeader, RoutingHeader.Status::Certified); | ||
| CreateProdItem(Item, RoutingHeader."No."); | ||
| CreateAndRefreshProdOrder( | ||
| ProductionOrder, ProductionOrder.Status::Released, Item."No.", LibraryRandom.RandInt(10), | ||
| ProductionOrder."Source Type"::Item, false); | ||
|
|
||
| // [GIVEN] A subcontracting purchase order created from the subcontracting worksheet is received and invoiced. | ||
| CalculateSubcontractOrder(RequisitionLine, SubcontractingWorkCenter."No.", ProductionOrder); | ||
| LibraryPlanning.CarryOutAMSubcontractWksh(RequisitionLine); | ||
| PurchaseLine.SetRange("Document Type", PurchaseLine."Document Type"::Order); | ||
| PurchaseLine.SetRange("Prod. Order No.", ProductionOrder."No."); | ||
| PurchaseLine.SetRange("Operation No.", OperationNo); | ||
| PurchaseLine.FindFirst(); | ||
| PurchaseHeader.Get(PurchaseLine."Document Type", PurchaseLine."Document No."); | ||
| PurchaseHeader.Validate("Vendor Invoice No.", PurchaseHeader."No."); | ||
| PurchaseHeader.Modify(true); | ||
| LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); | ||
|
|
||
| // [GIVEN] A purchase return order populated from the posted subcontracting invoice. | ||
| PurchInvLine.SetRange("Order No.", PurchaseHeader."No."); | ||
| PurchInvLine.SetRange("Prod. Order No.", ProductionOrder."No."); | ||
| PurchInvLine.SetRange("Operation No.", OperationNo); | ||
| PurchInvLine.FindFirst(); | ||
| LibraryPurchase.CreatePurchHeader( | ||
| PurchaseHeader, PurchaseHeader."Document Type"::"Return Order", SubcontractingWorkCenter."Subcontractor No."); | ||
| LibraryVariableStorage.Enqueue(PurchInvLine."Document No."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test enqueues an expectation for the PostedPurchaseDocumentLinesPageHandler modal page handler but never calls LibraryVariableStorage.AssertEmpty() to confirm the queued value was consumed. This leaves the UI-handler interaction only partially verified across all three duplicated copies (W1, BE, IT). Knowledge: 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.36.6 |
||
| PurchaseHeader.GetPstdDocLinesToReverse(); | ||
| PurchaseHeader.Validate("Vendor Cr. Memo No.", PurchaseHeader."Buy-from Vendor No."); | ||
| PurchaseHeader.Modify(true); | ||
|
|
||
| // [WHEN] The purchase return order is shipped and invoiced. | ||
| LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); | ||
|
|
||
| // [THEN] Posting succeeds. | ||
| end; | ||
|
|
||
| local procedure Initialize() | ||
| var | ||
| LibraryERMCountryData: Codeunit "Library - ERM Country Data"; | ||
|
|
@@ -6132,6 +6196,14 @@ codeunit 137063 "SCM Manufacturing 7.0" | |
| ProdOrderComponents.OK().Invoke(); | ||
| end; | ||
|
|
||
| [ModalPageHandler] | ||
| procedure PostedPurchaseDocumentLinesPageHandler(var PostedPurchaseDocumentLines: TestPage "Posted Purchase Document Lines") | ||
| begin | ||
| PostedPurchaseDocumentLines.PostedReceiptsBtn.SetValue('Posted Invoices'); | ||
| PostedPurchaseDocumentLines.PostedInvoices.Filter.SetFilter("Document No.", LibraryVariableStorage.DequeueText()); | ||
| PostedPurchaseDocumentLines.OK().Invoke(); | ||
| end; | ||
|
|
||
| local procedure GetShopCalendarCodeForProductionOrder(ProductionOrder: Record "Production Order"): Code[10] | ||
| var | ||
| ProdOrderRoutingLine: Record "Prod. Order Routing Line"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MfgPurchaseDocumentMgt.Codeunit.al's OnIsSubcontractingCreditMemo event subscriber changed its condition from an exact 'Document Type = Credit Memo' check to PurchaseLine.IsCreditDocType(), which also matches 'Return Order'. This is an intentional fix (validated by the new PostPurchaseReturnOrderForSubcontractingWhenLastOperationIsNotSubcontracted test) enabling posting of subcontracting purchase return orders, but it silently widens what the event named 'OnIsSubcontractingCreditMemo' now considers true (Return Orders too), which may surprise other subscribers/callers relying on the event's literal name/semantics. Consider whether the event name/documentation should be updated to reflect it now also covers Return Orders, or whether Return Order handling should be a distinct, separately named condition.
Agent judgement — not directly backed by a BCQuality knowledge article.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.36.6