-
Notifications
You must be signed in to change notification settings - Fork 390
[Shopify] Fix incorrect G/L line on credit memo for refund with exchange item #8554
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # cost: 15 | ||
| {"query":"{ order(id: \"gid://shopify/Order/{{OrderId}}\") { returns(first: 10, after: \"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id exchangeLineItems(first: 250) { nodes { lineItems { id }}}}}}}"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # cost: 15 | ||
| {"query":"{ order(id: \"gid://shopify/Order/{{OrderId}}\") { returns(first: 10) { pageInfo { endCursor hasNextPage } nodes { id exchangeLineItems(first: 250) { nodes { lineItems { id }}}}}}}"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # cost: 15 | ||
| {"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { return { exchangeLineItems(first: 10, after: \"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id quantity variantId lineItems { id originalUnitPriceSet { presentmentMoney { amount } shopMoney { amount }} discountedUnitPriceSet { presentmentMoney { amount } shopMoney { amount }} totalDiscountSet { presentmentMoney { amount } shopMoney { amount }} taxLines { priceSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}}"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # cost: 15 | ||
| {"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { return { exchangeLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { id quantity variantId lineItems { id originalUnitPriceSet { presentmentMoney { amount } shopMoney { amount }} discountedUnitPriceSet { presentmentMoney { amount } shopMoney { amount }} totalDiscountSet { presentmentMoney { amount } shopMoney { amount }} taxLines { priceSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}}"} |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,6 +122,7 @@ codeunit 30161 "Shpfy Import Order" | |||||||||||||||||||||
| OrderHeader.Modify(); | ||||||||||||||||||||||
| OrderFulfillments.GetFulfillments(Shop, OrderHeader."Shopify Order Id"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| MarkExchangeItemOrderLines(OrderHeader); | ||||||||||||||||||||||
| ConsiderRefundsInQuantityAndAmounts(OrderHeader); | ||||||||||||||||||||||
| DeleteZeroQuantityLines(OrderHeader); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -209,6 +210,7 @@ codeunit 30161 "Shpfy Import Order" | |||||||||||||||||||||
| if not IReturnRefundProcess.IsImportNeededFor("Shpfy Source Document Type"::Refund) then | ||||||||||||||||||||||
| exit; | ||||||||||||||||||||||
| OrderLine.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); | ||||||||||||||||||||||
| OrderLine.SetRange("Is Exchange Item", false); | ||||||||||||||||||||||
| if not OrderLine.FindSet() then | ||||||||||||||||||||||
| exit; | ||||||||||||||||||||||
| repeat | ||||||||||||||||||||||
|
|
@@ -240,6 +242,68 @@ codeunit 30161 "Shpfy Import Order" | |||||||||||||||||||||
| OrderHeader.Modify(); | ||||||||||||||||||||||
| end; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| internal procedure MarkExchangeItemOrderLines(var OrderHeader: Record "Shpfy Order Header") | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
| var | ||||||||||||||||||||||
| OrderLine: Record "Shpfy Order Line"; | ||||||||||||||||||||||
| IReturnRefundProcess: Interface "Shpfy IReturnRefund Process"; | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
| ExchangeLineIds: List of [BigInteger]; | ||||||||||||||||||||||
| ExchangeLineId: BigInteger; | ||||||||||||||||||||||
| GraphQLType: Enum "Shpfy GraphQL Type"; | ||||||||||||||||||||||
| Parameters: Dictionary of [Text, Text]; | ||||||||||||||||||||||
| JResponse: JsonToken; | ||||||||||||||||||||||
| JReturns: JsonArray; | ||||||||||||||||||||||
| JReturn: JsonToken; | ||||||||||||||||||||||
| JExchangeLineItems: JsonArray; | ||||||||||||||||||||||
| JExchangeLineItem: JsonToken; | ||||||||||||||||||||||
| JLineItems: JsonArray; | ||||||||||||||||||||||
| JLineItem: JsonToken; | ||||||||||||||||||||||
| begin | ||||||||||||||||||||||
| IReturnRefundProcess := Shop."Return and Refund Process"; | ||||||||||||||||||||||
| if not IReturnRefundProcess.IsImportNeededFor("Shpfy Source Document Type"::Refund) then | ||||||||||||||||||||||
| exit; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Exchange line items only exist on orders that have a return. Skip the API call for the common case of no return. | ||||||||||||||||||||||
| if OrderHeader."Return Status" in [OrderHeader."Return Status"::" ", OrderHeader."Return Status"::"No Return"] then | ||||||||||||||||||||||
| exit; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Parameters.Add('OrderId', Format(OrderHeader."Shopify Order Id")); | ||||||||||||||||||||||
| GraphQLType := "Shpfy GraphQL Type"::Orders_GetOrderExchangeLineItems; | ||||||||||||||||||||||
| repeat | ||||||||||||||||||||||
| JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); | ||||||||||||||||||||||
| GraphQLType := "Shpfy GraphQL Type"::Orders_GetNextOrderExchangeLineItems; | ||||||||||||||||||||||
| JReturns := JsonHelper.GetJsonArray(JResponse, 'data.order.returns.nodes'); | ||||||||||||||||||||||
| if Parameters.ContainsKey('After') then | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
| Parameters.Set('After', JsonHelper.GetValueAsText(JResponse, 'data.order.returns.pageInfo.endCursor')) | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| Parameters.Add('After', JsonHelper.GetValueAsText(JResponse, 'data.order.returns.pageInfo.endCursor')); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| foreach JReturn in JReturns do begin | ||||||||||||||||||||||
| JExchangeLineItems := JsonHelper.GetJsonArray(JReturn, 'exchangeLineItems.nodes'); | ||||||||||||||||||||||
| foreach JExchangeLineItem in JExchangeLineItems do begin | ||||||||||||||||||||||
| JLineItems := JsonHelper.GetJsonArray(JExchangeLineItem, 'lineItems'); | ||||||||||||||||||||||
| foreach JLineItem in JLineItems do begin | ||||||||||||||||||||||
| ExchangeLineId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLineItem, 'id')); | ||||||||||||||||||||||
| if (ExchangeLineId <> 0) and not ExchangeLineIds.Contains(ExchangeLineId) then | ||||||||||||||||||||||
| ExchangeLineIds.Add(ExchangeLineId); | ||||||||||||||||||||||
| end; | ||||||||||||||||||||||
| end; | ||||||||||||||||||||||
| end; | ||||||||||||||||||||||
| until not JsonHelper.GetValueAsBoolean(JResponse, 'data.order.returns.pageInfo.hasNextPage'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ExchangeLineIds.Count() = 0 then | ||||||||||||||||||||||
| exit; | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| OrderLine.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); | ||||||||||||||||||||||
| OrderLine.SetLoadFields("Line Id", "Is Exchange Item"); | ||||||||||||||||||||||
| if OrderLine.FindSet() then | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
| repeat | ||||||||||||||||||||||
| if ExchangeLineIds.Contains(OrderLine."Line Id") and (not OrderLine."Is Exchange Item") then begin | ||||||||||||||||||||||
|
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. Exchange-item flag never cleared on re-import
Recommendation:
Suggested change
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why |
||||||||||||||||||||||
| OrderLine."Is Exchange Item" := true; | ||||||||||||||||||||||
| OrderLine.Modify(); | ||||||||||||||||||||||
| end; | ||||||||||||||||||||||
| until OrderLine.Next() = 0; | ||||||||||||||||||||||
|
onbuyuka marked this conversation as resolved.
|
||||||||||||||||||||||
| end; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| local procedure IsImportedOrderConflictingExistingOrder(JOrder: JsonObject; OrderHeader: Record "Shpfy Order Header"; var TempOrderLine: Record "Shpfy Order Line" temporary): Boolean | ||||||||||||||||||||||
| var | ||||||||||||||||||||||
| Hash: Codeunit "Shpfy Hash"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.