diff --git a/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLNextReturnLines.Codeunit.al b/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLNextReturnLines.Codeunit.al index ea5ae95ea3..c394489ecd 100644 --- a/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLNextReturnLines.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLNextReturnLines.Codeunit.al @@ -10,7 +10,7 @@ codeunit 30227 "Shpfy GQL NextReturnLines" implements "Shpfy IGraphQL" internal procedure GetGraphQL(): Text begin - exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { returnLineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { ... on ReturnLineItem { id quantity returnReason returnReasonNote refundableQuantity refundedQuantity customerNote totalWeight { unit value } withCodeDiscountedTotalPriceSet { presentmentMoney { amount } shopMoney { amount } } fulfillmentLineItem { id lineItem { id } quantity originalTotalSet { presentmentMoney { amount } shopMoney { amount } } discountedTotalSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}"}'); + exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { returnLineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id quantity returnReason returnReasonNote refundableQuantity refundedQuantity customerNote ... on UnverifiedReturnLineItem { __typename unitPrice { amount currencyCode } } ... on ReturnLineItem { __typename totalWeight { unit value } withCodeDiscountedTotalPriceSet { presentmentMoney { amount } shopMoney { amount } } fulfillmentLineItem { id lineItem { id } quantity originalTotalSet { presentmentMoney { amount } shopMoney { amount } } discountedTotalSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}"}'); end; internal procedure GetExpectedCost(): Integer diff --git a/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLReturnLines.Codeunit.al b/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLReturnLines.Codeunit.al index 8edaca2ecc..4d91a66c29 100644 --- a/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLReturnLines.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/GraphQL/Codeunits/ShpfyGQLReturnLines.Codeunit.al @@ -10,7 +10,7 @@ codeunit 30226 "Shpfy GQL ReturnLines" implements "Shpfy IGraphQL" internal procedure GetGraphQL(): Text begin - exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { returnLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { ... on ReturnLineItem { id quantity returnReason returnReasonNote refundableQuantity refundedQuantity customerNote totalWeight { unit value } withCodeDiscountedTotalPriceSet { presentmentMoney { amount } shopMoney { amount } } fulfillmentLineItem { id lineItem { id } quantity originalTotalSet { presentmentMoney { amount } shopMoney { amount } } discountedTotalSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}"}'); + exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { returnLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { id quantity returnReason returnReasonNote refundableQuantity refundedQuantity customerNote ... on UnverifiedReturnLineItem { __typename unitPrice { amount currencyCode } } ... on ReturnLineItem { __typename totalWeight { unit value } withCodeDiscountedTotalPriceSet { presentmentMoney { amount } shopMoney { amount } } fulfillmentLineItem { id lineItem { id } quantity originalTotalSet { presentmentMoney { amount } shopMoney { amount } } discountedTotalSet { presentmentMoney { amount } shopMoney { amount }}}}}}}}"}'); end; internal procedure GetExpectedCost(): Integer diff --git a/src/Apps/W1/Shopify/App/src/Order Return Refund Processing/Codeunits/ShpfyCreateSalesDocRefund.Codeunit.al b/src/Apps/W1/Shopify/App/src/Order Return Refund Processing/Codeunits/ShpfyCreateSalesDocRefund.Codeunit.al index f4ee09ff69..20b14d631b 100644 --- a/src/Apps/W1/Shopify/App/src/Order Return Refund Processing/Codeunits/ShpfyCreateSalesDocRefund.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Order Return Refund Processing/Codeunits/ShpfyCreateSalesDocRefund.Codeunit.al @@ -172,6 +172,7 @@ codeunit 30246 "Shpfy Create Sales Doc. Refund" else if RefundHeader."Return Id" > 0 then begin ReturnLine.SetRange("Return Id", RefundHeader."Return Id"); + ReturnLine.SetRange(Type, ReturnLine.Type::Default); ReturnLine.SetAutoCalcFields("Item No.", "Variant Code", Description, "Unit of Measure Code"); if ReturnLine.FindSet(false) then CreateSalesLinesFromReturnLines(ReturnLine, RefundHeader, SalesHeader, LineNo); diff --git a/src/Apps/W1/Shopify/App/src/Order Returns/Codeunits/ShpfyReturnsAPI.Codeunit.al b/src/Apps/W1/Shopify/App/src/Order Returns/Codeunits/ShpfyReturnsAPI.Codeunit.al index 59062881b2..295927b8a3 100644 --- a/src/Apps/W1/Shopify/App/src/Order Returns/Codeunits/ShpfyReturnsAPI.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Order Returns/Codeunits/ShpfyReturnsAPI.Codeunit.al @@ -57,8 +57,12 @@ codeunit 30250 "Shpfy Returns API" LineParameters.Set('After', JsonHelper.GetValueAsText(JResponse, 'data.return.returnLineItems.pageInfo.endCursor')) else LineParameters.Add('After', JsonHelper.GetValueAsText(JResponse, 'data.return.returnLineItems.pageInfo.endCursor')); - foreach JLine in JLines do - FillInReturnLine(ReturnId, JLine.AsObject(), ReturnLocations); + foreach JLine in JLines do begin + if JsonHelper.GetValueAsText(JLine, '__typename') = 'ReturnLineItem' then + FillInReturnLine(ReturnId, JLine.AsObject(), ReturnLocations); + if JsonHelper.GetValueAsText(JLine, '__typename') = 'UnverifiedReturnLineItem' then + FillInUnverifiedReturnLine(ReturnId, JLine.AsObject()); + end; until not JsonHelper.GetValueAsBoolean(JResponse, 'data.return.returnLineItems.pageInfo.hasNextPage'); end; @@ -163,7 +167,7 @@ codeunit 30250 "Shpfy Returns API" if Dispositions.Count = 0 then exit; - // If dispositions have different locations (Item was restocked to multiple locations), + // If dispositions have different locations (Item was restocked to multiple locations), // we cannot determine the return location for the line Dispositions.Get(0, Disposition); LocationId := JsonHelper.GetValueAsBigInteger(Disposition, 'location.legacyResourceId'); @@ -195,6 +199,7 @@ codeunit 30250 "Shpfy Returns API" if not ReturnLine.Get(Id) then begin ReturnLine."Return Line Id" := Id; ReturnLine."Return Id" := ReturnId; + ReturnLine.Type := ReturnLine.Type::Default; ReturnLine."Fulfillment Line Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'fulfillmentLineItem.id')); ReturnLine."Order Line Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'fulfillmentLineItem.lineItem.id')); ReturnLine.Insert(); @@ -219,4 +224,33 @@ codeunit 30250 "Shpfy Returns API" ReturnLineRecordRef.Close(); DataCapture.Add(Database::"Shpfy Return Line", ReturnLine.SystemId, JLine); end; + + local procedure FillInUnverifiedReturnLine(ReturnId: BigInteger; JLine: JsonObject) + var + DataCapture: Record "Shpfy Data Capture"; + ReturnLine: Record "Shpfy Return Line"; + ReturnLineRecordRef: RecordRef; + Id: BigInteger; + begin + Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'id')); + if not ReturnLine.Get(Id) then begin + ReturnLine."Return Line Id" := Id; + ReturnLine."Return Id" := ReturnId; + ReturnLine.Type := ReturnLine.Type::Unverified; + ReturnLine.Insert(); + end; + ReturnLine."Return Reason" := ReturnEnumConvertor.ConvertToReturnReason(JsonHelper.GetValueAsText(JLine, 'returnReason')); + ReturnLine.SetReturnReasonNote(JsonHelper.GetValueAsText(JLine, 'returnReasonNote')); + ReturnLine.SetCustomerNote(JsonHelper.GetValueAsText(JLine, 'customerNote')); + + ReturnLineRecordRef.GetTable(ReturnLine); + JsonHelper.GetValueIntoField(JLine, 'quantity', ReturnLineRecordRef, ReturnLine.FieldNo(Quantity)); + JsonHelper.GetValueIntoField(JLine, 'refundableQuantity', ReturnLineRecordRef, ReturnLine.FieldNo("Refundable Quantity")); + JsonHelper.GetValueIntoField(JLine, 'refundedQuantity', ReturnLineRecordRef, ReturnLine.FieldNo("Refunded Quantity")); + JsonHelper.GetValueIntoField(JLine, 'unitPrice.amount', ReturnLineRecordRef, ReturnLine.FieldNo("Unit Price")); + JsonHelper.GetValueIntoField(JLine, 'unitPrice.currency', ReturnLineRecordRef, ReturnLine.FieldNo("Unit Price Currency")); + ReturnLineRecordRef.Modify(); + ReturnLineRecordRef.Close(); + DataCapture.Add(Database::"Shpfy Return Line", ReturnLine.SystemId, JLine); + end; } \ No newline at end of file diff --git a/src/Apps/W1/Shopify/App/src/Order Returns/Enums/ShpfyReturnLineType.Enum.al b/src/Apps/W1/Shopify/App/src/Order Returns/Enums/ShpfyReturnLineType.Enum.al new file mode 100644 index 0000000000..cfaa343332 --- /dev/null +++ b/src/Apps/W1/Shopify/App/src/Order Returns/Enums/ShpfyReturnLineType.Enum.al @@ -0,0 +1,18 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace Microsoft.Integration.Shopify; + +enum 30170 "Shpfy Return Line Type" +{ + value(0; Default) + { + Caption = 'Default'; + } + value(1; Unverified) + { + Caption = 'Unverified'; + } +} \ No newline at end of file diff --git a/src/Apps/W1/Shopify/App/src/Order Returns/Pages/ShpfyReturnLines.Page.al b/src/Apps/W1/Shopify/App/src/Order Returns/Pages/ShpfyReturnLines.Page.al index f4dd4fd96a..7a210d76c5 100644 --- a/src/Apps/W1/Shopify/App/src/Order Returns/Pages/ShpfyReturnLines.Page.al +++ b/src/Apps/W1/Shopify/App/src/Order Returns/Pages/ShpfyReturnLines.Page.al @@ -17,6 +17,11 @@ page 30149 "Shpfy Return Lines" { repeater(General) { + field(Type; Rec.Type) + { + ApplicationArea = All; + ToolTip = 'Specifies the type of return line.'; + } field("Item No."; Rec."Item No.") { ApplicationArea = All; @@ -67,6 +72,11 @@ page 30149 "Shpfy Return Lines" ApplicationArea = All; ToolTip = 'Specifies the unit of measurement.'; } + field("Unit Price"; Rec."Unit Price") + { + ApplicationArea = All; + ToolTip = 'Specifies the price of a single unit of the item.'; + } } group(ReturnReason) { diff --git a/src/Apps/W1/Shopify/App/src/Order Returns/Tables/ShpfyReturnLine.Table.al b/src/Apps/W1/Shopify/App/src/Order Returns/Tables/ShpfyReturnLine.Table.al index 95a2f5861e..9d4457b975 100644 --- a/src/Apps/W1/Shopify/App/src/Order Returns/Tables/ShpfyReturnLine.Table.al +++ b/src/Apps/W1/Shopify/App/src/Order Returns/Tables/ShpfyReturnLine.Table.al @@ -104,6 +104,26 @@ table 30141 "Shpfy Return Line" Caption = 'Customer Note'; DataClassification = SystemMetadata; } + field(15; Type; Enum "Shpfy Return Line Type") + { + Caption = 'Type'; + DataClassification = SystemMetadata; + Editable = false; + } + field(16; "Unit Price"; Decimal) + { + Caption = 'Unit Price'; + DataClassification = SystemMetadata; + Editable = false; + AutoFormatType = 1; + AutoFormatExpression = "Unit Price Currency"; + } + field(17; "Unit Price Currency"; Code[10]) + { + Caption = 'Unit Price Currency'; + DataClassification = SystemMetadata; + Editable = false; + } field(101; "Item No."; Code[20]) { Caption = 'Item No.'; diff --git a/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundTest.Codeunit.al index 0f8994caa4..35a14eb901 100644 --- a/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundTest.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundTest.Codeunit.al @@ -452,6 +452,7 @@ codeunit 139611 "Shpfy Order Refund Test" OrderRefundsHelper.SetDefaultSeed(); ReturnId := OrderRefundsHelper.CreateReturn(OrderId); OrderRefundsHelper.CreateReturnLine(ReturnId, OrderId, ''); + OrderRefundsHelper.CreateUnverifiedReturnLine(ReturnId, ''); end; local procedure CreateLocation(var Location: Record Location) diff --git a/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundsHelper.Codeunit.al b/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundsHelper.Codeunit.al index 35cf886f80..46fd8a65fc 100644 --- a/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundsHelper.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Order Refunds/ShpfyOrderRefundsHelper.Codeunit.al @@ -43,10 +43,12 @@ codeunit 139564 "Shpfy Order Refunds Helper" ReturnId := CreateReturn(OrderId); CreateReturnLine(ReturnId, ShopifyIds.Get('OrderLine').Get(1), 'DEFECTIVE'); + CreateUnverifiedReturnLine(ReturnId, 'DEFECTIVE'); ShopifyIds.Get('Return').Add(ReturnId); ReturnId := CreateReturn(OrderId); CreateReturnLine(ReturnId, ShopifyIds.Get('OrderLine').Get(2), 'NOT_AS_DESCRIBED'); + CreateUnverifiedReturnLine(ReturnId, 'NOT_AS_DESCRIBED'); ShopifyIds.Get('Return').Add(ReturnId); RefundId := CreateRefundHeader(OrderId, ShopifyIds.Get('Return').Get(1), 156.38); @@ -187,6 +189,7 @@ codeunit 139564 "Shpfy Order Refunds Helper" begin ReturnLine."Return Line Id" := Any.IntegerInRange(100000, 999999); ReturnLine."Return Id" := ReturnOrderId; + ReturnLine.Type := ReturnLine.Type::Default; ReturnLine."Fulfillment Line Id" := Any.IntegerInRange(100000, 999999); ReturnLine."Order Line Id" := OrderLineId; ReturnLine."Return Reason" := ReturnEnumConvertor.ConvertToReturnReason(ReturnReason); @@ -200,6 +203,21 @@ codeunit 139564 "Shpfy Order Refunds Helper" exit(ReturnLine."Return Line Id"); end; + internal procedure CreateUnverifiedReturnLine(ReturnId: BigInteger; ReturnReason: Text): BigInteger + var + ReturnLine: Record "Shpfy Return Line"; + ReturnEnumConvertor: Codeunit "Shpfy Return Enum Convertor"; + begin + ReturnLine."Return Line Id" := Any.IntegerInRange(100000, 999999); + ReturnLine."Return Id" := ReturnId; + ReturnLine.Type := ReturnLine.Type::Unverified; + ReturnLine."Return Reason" := ReturnEnumConvertor.ConvertToReturnReason(ReturnReason); + ReturnLine.Quantity := 1; + ReturnLine."Refundable Quantity" := 1; + ReturnLine."Refunded Quantity" := 0; + ReturnLine."Unit Price" := 156.38; + end; + internal procedure CreateRefundHeader(OrderId: BigInteger; ReturnId: BigInteger; Amount: Decimal): BigInteger var RefundHeader: Record "Shpfy Refund Header";