Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand Down
Loading