Skip to content

Commit 4c96010

Browse files
authored
[Shopify] Fix wrong Refund Line ID being used (#6105)
### Summary This PR fixes a bug where the Shopify Connector was incorrectly using the Order Line ID instead of the actual Refund Line ID when creating refund line records. The issue caused incorrect data to be stored in the `"Refund Line Id"` field of the `"Shpfy Refund Line"` table. ### Problem When importing refund lines from Shopify, the system was extracting the `lineItem.id` from the GraphQL response and using it as both the `"Refund Line Id"` and `"Order Line Id"`. This was incorrect because: - `lineItem.id` represents the original order line item - The actual refund line has its own unique ID that should be stored in `"Refund Line Id"` ### Solution 1. **Updated GraphQL queries** to include the `id` field for refund line items: - ShpfyGQLRefundLines.Codeunit.al - Added `id` to the `nodes` selection - ShpfyGQLNextRefundLines.Codeunit.al - Added `id` to the `nodes` selection 2. **Updated the refund line import logic** in ShpfyRefundsAPI.Codeunit.al: - Now correctly extracts the refund line's own `id` for the `"Refund Line Id"` field - Uses `lineItem.id` only for the `"Order Line Id"` field (the reference to the original order line) #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes [AB#617843](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/617843)
1 parent 1992b9c commit 4c96010

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLNextRefundLines.Codeunit.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ codeunit 30232 "Shpfy GQL NextRefundLines" implements "Shpfy IGraphQL"
1010

1111
internal procedure GetGraphQL(): Text
1212
begin
13-
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { lineItem { id } quantity restockType location { legacyResourceId } restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
13+
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id lineItem { id } quantity restockType location { legacyResourceId } restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
1414
end;
1515

1616
internal procedure GetExpectedCost(): Integer

src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLRefundLines.Codeunit.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ codeunit 30230 "Shpfy GQL RefundLines" implements "Shpfy IGraphQL"
1010

1111
internal procedure GetGraphQL(): Text
1212
begin
13-
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { lineItem { id } quantity restockType location { legacyResourceId } restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
13+
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { id lineItem { id } quantity restockType location { legacyResourceId } restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
1414
end;
1515

1616
internal procedure GetExpectedCost(): Integer

src/Apps/W1/Shopify/App/src/Order Refunds/Codeunits/ShpfyRefundsAPI.Codeunit.al

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,17 @@ codeunit 30228 "Shpfy Refunds API"
147147
DataCapture: Record "Shpfy Data Capture";
148148
RefundLine: Record "Shpfy Refund Line";
149149
RefundLineRecordRef: RecordRef;
150-
Id: BigInteger;
150+
RefundLineId: BigInteger;
151+
LineItemId: BigInteger;
151152
ReturnLocation: BigInteger;
152153
begin
153-
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'lineItem.id'));
154+
RefundLineId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'id'));
155+
LineItemId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'lineItem.id'));
154156

155-
if not RefundLine.Get(RefundId, Id) then begin
156-
RefundLine."Refund Line Id" := Id;
157+
if not RefundLine.Get(RefundId, RefundLineId) then begin
158+
RefundLine."Refund Line Id" := RefundLineId;
157159
RefundLine."Refund Id" := RefundId;
158-
RefundLine."Order Line Id" := Id;
160+
RefundLine."Order Line Id" := LineItemId;
159161
RefundLine.Insert();
160162
end;
161163

src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundTest.Codeunit.al

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ codeunit 139611 "Shpfy Order Refund Test"
213213
JRefundLine: JsonObject;
214214
ReturnLocations: Dictionary of [BigInteger, BigInteger];
215215
RefundLineId: BigInteger;
216+
LineItemId: BigInteger;
216217
ReturnLocationId: BigInteger;
217218
begin
218219
// [SCENARIO] Import refund lines with locations
@@ -222,10 +223,11 @@ codeunit 139611 "Shpfy Order Refund Test"
222223
RefundId := OrderRefundsHelper.CreateRefundHeader();
223224
// [GIVEN] Refund Line response
224225
RefundLineId := Any.IntegerInRange(100000, 999999);
225-
CreateRefundLineResponse(JRefundLine, RefundLineId, 0);
226+
LineItemId := Any.IntegerInRange(100000, 999999);
227+
CreateRefundLineResponse(JRefundLine, RefundLineId, LineItemId, 0);
226228
//[GIVEN] Return Locations
227229
ReturnLocationId := Any.IntegerInRange(100000, 999999);
228-
ReturnLocations.Add(RefundLineId, ReturnLocationId);
230+
ReturnLocations.Add(LineItemId, ReturnLocationId);
229231

230232
// [WHEN] Execute RefundsAPI.FillInRefundLine
231233
RefundsAPI.FillInRefundLine(RefundId, JRefundLine, false, ReturnLocations);
@@ -501,9 +503,17 @@ codeunit 139611 "Shpfy Order Refund Test"
501503

502504
local procedure CreateRefundLineResponse(var JRefundLine: JsonObject; RefundLineId: BigInteger; RefundLocationId: BigInteger)
503505
var
504-
RefundLineLbl: Label '{"lineItem": {"id": "gid://shopify/LineItem/%1"}, "quantity": 1, "restockType": "no_restock", "location": {"legacyResourceId": %2}}', Comment = '%1 = RefundLineId, %2 = RefundLocationId', Locked = true;
506+
LineItemId: BigInteger;
505507
begin
506-
JRefundLine.ReadFrom(StrSubstNo(RefundLineLbl, RefundLineId, RefundLocationId));
508+
LineItemId := Any.IntegerInRange(100000, 999999);
509+
CreateRefundLineResponse(JRefundLine, RefundLineId, LineItemId, RefundLocationId);
510+
end;
511+
512+
local procedure CreateRefundLineResponse(var JRefundLine: JsonObject; RefundLineId: BigInteger; LineItemId: BigInteger; RefundLocationId: BigInteger)
513+
var
514+
RefundLineLbl: Label '{"id": "gid://shopify/RefundLineItem/%1", "lineItem": {"id": "gid://shopify/LineItem/%2"}, "quantity": 1, "restockType": "no_restock", "location": {"legacyResourceId": %3}}', Comment = '%1 = RefundLineId, %2 = LineItemId, %3 = RefundLocationId', Locked = true;
515+
begin
516+
JRefundLine.ReadFrom(StrSubstNo(RefundLineLbl, RefundLineId, LineItemId, RefundLocationId));
507517
end;
508518

509519
local procedure CerateProcessedShopifyOrder(var OrderId: BigInteger; var OrderLineId: BigInteger)

0 commit comments

Comments
 (0)