Skip to content

Commit c02c463

Browse files
committed
Merge branch 'main' into GPUpdates202407
2 parents 04125b7 + 096df31 commit c02c463

15 files changed

+311
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Microsoft.Integration.Shopify;
2+
3+
enum 30162 "Shpfy Return Location Priority"
4+
{
5+
Access = Public;
6+
Extensible = false;
7+
8+
value(0; "Default Return Location")
9+
{
10+
Caption = 'Default Return Location';
11+
}
12+
value(1; "Original -> Default Location")
13+
{
14+
Caption = 'Original -> Default Location';
15+
}
16+
}

Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al

+6
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ page 30101 "Shpfy Shop Card"
540540
ShowCaption = false;
541541
Visible = IsReturnRefundsVisible;
542542

543+
field("Return Location Priority"; Rec."Return Location Priority")
544+
{
545+
ApplicationArea = All;
546+
Caption = 'Return Location Priority';
547+
ToolTip = 'Specifies the priority of the return location.';
548+
}
543549
field("Location Code of Returns"; Rec."Return Location")
544550
{
545551
ApplicationArea = All;

Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al

+8-3
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ table 30102 "Shpfy Shop"
233233
ObsoleteState = Pending;
234234
ObsoleteTag = '24.0';
235235
#else
236-
ObsoleteState = Removed;
237-
ObsoleteTag = '27.0';
236+
ObsoleteState = Removed;
237+
ObsoleteTag = '27.0';
238238
#endif
239239
}
240240
field(30; "Shopify Can Update Customer"; Boolean)
@@ -511,7 +511,7 @@ table 30102 "Shpfy Shop"
511511
}
512512
field(73; "Return Location"; Code[10])
513513
{
514-
Caption = 'Return Location';
514+
Caption = 'Default Return Location';
515515
DataClassification = CustomerContent;
516516
TableRelation = Location where("Use As In-Transit" = const(false));
517517
}
@@ -778,6 +778,11 @@ table 30102 "Shpfy Shop"
778778
end;
779779
#endif
780780
}
781+
field(128; "Return Location Priority"; Enum "Shpfy Return Location Priority")
782+
{
783+
Caption = 'Return Location Priority';
784+
DataClassification = CustomerContent;
785+
}
781786
field(200; "Shop Id"; Integer)
782787
{
783788
DataClassification = SystemMetadata;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ codeunit 30232 "Shpfy GQL NextRefundLines" implements "Shpfy IGraphQL"
55

66
internal procedure GetGraphQL(): Text
77
begin
8-
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { lineItem { id } quantity restockType restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
8+
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 }}}}}}"}');
99
end;
1010

1111
internal procedure GetExpectedCost(): Integer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Microsoft.Integration.Shopify;
2+
3+
/// <summary>
4+
/// Codeunit Shpfy GQL NextRevFulfillOrdLns (ID 30349) implements Interface Shpfy IGraphQL.
5+
/// </summary>
6+
codeunit 30349 "Shpfy GQL NextRevFulfillOrdLns" implements "Shpfy IGraphQL"
7+
{
8+
Access = Internal;
9+
10+
/// <summary>
11+
/// GetGraphQL.
12+
/// </summary>
13+
/// <returns>Return value of type Text.</returns>
14+
internal procedure GetGraphQL(): Text
15+
begin
16+
exit('{"query":"{ reverseFulfillmentOrder(id: \"{{FulfillOrderId}}\") { lineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id fulfillmentLineItem { id lineItem { id name } } dispositions { id quantity type location { id legacyResourceId } } } } } }"}');
17+
end;
18+
19+
/// <summary>
20+
/// GetExpectedCost.
21+
/// </summary>
22+
/// <returns>Return value of type Integer.</returns>
23+
internal procedure GetExpectedCost(): Integer
24+
begin
25+
exit(15);
26+
end;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Microsoft.Integration.Shopify;
2+
3+
/// <summary>
4+
/// Codeunit Shpfy GQL NextRevFulfillOrders (ID 30347) implements Interface Shpfy IGraphQL.
5+
/// </summary>
6+
codeunit 30347 "Shpfy GQL NextRevFulfillOrders" implements "Shpfy IGraphQL"
7+
{
8+
Access = Internal;
9+
10+
/// <summary>
11+
/// GetGraphQL.
12+
/// </summary>
13+
/// <returns>Return value of type Text.</returns>
14+
internal procedure GetGraphQL(): Text
15+
begin
16+
exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { reverseFulfillmentOrders(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id } } } }"}');
17+
18+
end;
19+
20+
/// <summary>
21+
/// GetExpectedCost.
22+
/// </summary>
23+
/// <returns>Return value of type Integer.</returns>
24+
internal procedure GetExpectedCost(): Integer
25+
begin
26+
exit(7);
27+
end;
28+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ codeunit 30230 "Shpfy GQL RefundLines" implements "Shpfy IGraphQL"
55

66
internal procedure GetGraphQL(): Text
77
begin
8-
exit('{"query":"{ refund(id: \"gid://shopify/Refund/{{RefundId}}\") { refundLineItems(first: 10) { pageInfo { endCursor hasNextPage } nodes { lineItem { id } quantity restockType restocked priceSet { presentmentMoney { amount } shopMoney { amount }} subtotalSet { presentmentMoney { amount } shopMoney { amount }} totalTaxSet { presentmentMoney { amount } shopMoney { amount }}}}}}"}');
8+
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 }}}}}}"}');
99
end;
1010

1111
internal procedure GetExpectedCost(): Integer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Microsoft.Integration.Shopify;
2+
3+
/// <summary>
4+
/// Codeunit Shpfy GQL RevFulfillOrderLines (ID 30348) implements Interface Shpfy IGraphQL.
5+
/// </summary>
6+
codeunit 30348 "Shpfy GQL RevFulfillOrderLines" implements "Shpfy IGraphQL"
7+
{
8+
Access = Internal;
9+
10+
/// <summary>
11+
/// GetGraphQL.
12+
/// </summary>
13+
/// <returns>Return value of type Text.</returns>
14+
internal procedure GetGraphQL(): Text
15+
begin
16+
exit('{"query":"{ reverseFulfillmentOrder(id: \"{{FulfillOrderId}}\") { id lineItems(first: 10) { nodes { id fulfillmentLineItem { id lineItem { id name } } dispositions { id quantity type location { id legacyResourceId } } } } } }"}');
17+
end;
18+
19+
/// <summary>
20+
/// GetExpectedCost.
21+
/// </summary>
22+
/// <returns>Return value of type Integer.</returns>
23+
internal procedure GetExpectedCost(): Integer
24+
begin
25+
exit(15);
26+
end;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Microsoft.Integration.Shopify;
2+
3+
/// <summary>
4+
/// Codeunit Shpfy GQL RevFulfillOrders (ID 30346) implements Interface Shpfy IGraphQL.
5+
/// </summary>
6+
codeunit 30346 "Shpfy GQL RevFulfillOrders" implements "Shpfy IGraphQL"
7+
{
8+
Access = Internal;
9+
10+
/// <summary>
11+
/// GetGraphQL.
12+
/// </summary>
13+
/// <returns>Return value of type Text.</returns>
14+
internal procedure GetGraphQL(): Text
15+
begin
16+
exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { reverseFulfillmentOrders(first: 10) { pageInfo { endCursor hasNextPage } nodes { id } } } }"}');
17+
18+
end;
19+
20+
/// <summary>
21+
/// GetExpectedCost.
22+
/// </summary>
23+
/// <returns>Return value of type Integer.</returns>
24+
internal procedure GetExpectedCost(): Integer
25+
begin
26+
exit(7);
27+
end;
28+
}

Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al

+20
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,24 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL"
405405
Caption = 'Get Order Transactions';
406406
Implementation = "Shpfy IGraphQL" = "Shpfy GQL OrderTransactions";
407407
}
408+
value(87; GetReverseFulfillmentOrders)
409+
{
410+
Caption = 'Get Reverse Fulfillment Orders';
411+
Implementation = "Shpfy IGraphQL" = "Shpfy GQL RevFulfillOrders";
412+
}
413+
value(88; GetNextReverseFulfillmentOrders)
414+
{
415+
Caption = 'Get Next Reverse Fulfillment Orders';
416+
Implementation = "Shpfy IGraphQL" = "Shpfy GQL NextRevFulfillOrders";
417+
}
418+
value(89; GetReverseFulfillmentOrderLines)
419+
{
420+
Caption = 'Get Reverse Fulfillment Order Lines';
421+
Implementation = "Shpfy IGraphQL" = "Shpfy GQL RevFulfillOrderLines";
422+
}
423+
value(90; GetNextReverseFulfillmentOrderLines)
424+
{
425+
Caption = 'Get Next Reverse Fulfillment Order Lines';
426+
Implementation = "Shpfy IGraphQL" = "Shpfy GQL NextRevFulfillOrdLns";
427+
}
408428
}

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

+28-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ codeunit 30228 "Shpfy Refunds API"
3131
RefundHeader: Record "Shpfy Refund Header";
3232
GraphQLType: Enum "Shpfy GraphQL Type";
3333
Parameters: Dictionary of [text, Text];
34+
ReturnLocations: Dictionary of [BigInteger, BigInteger];
3435
JResponse: JsonToken;
3536
JLines: JsonArray;
3637
JLine: JsonToken;
3738
begin
3839
GetRefundHeader(RefundId, UpdatedAt, RefundHeader);
40+
ReturnLocations := CollectReturnLocations(RefundHeader."Return Id");
41+
3942
Parameters.Add('RefundId', Format(RefundId));
4043
GraphQLType := "Shpfy GraphQL Type"::GetRefundLines;
4144
repeat
@@ -46,8 +49,9 @@ codeunit 30228 "Shpfy Refunds API"
4649
Parameters.Set('After', JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor'))
4750
else
4851
Parameters.Add('After', JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor'));
52+
4953
foreach JLine in JLines do
50-
FillInRefundLine(RefundId, JLine.AsObject(), IsNonZeroOrReturnRefund(RefundHeader));
54+
FillInRefundLine(RefundId, JLine.AsObject(), IsNonZeroOrReturnRefund(RefundHeader), ReturnLocations);
5155
until not JsonHelper.GetValueAsBoolean(JResponse, 'data.refund.refundLineItems.pageInfo.hasNextPage');
5256
end;
5357

@@ -88,21 +92,34 @@ codeunit 30228 "Shpfy Refunds API"
8892
DataCapture.Add(Database::"Shpfy Refund Header", RefundHeader.SystemId, JResponse);
8993
end;
9094

91-
local procedure FillInRefundLine(RefundId: BigInteger; JLine: JsonObject; NonZeroOrReturnRefund: Boolean)
95+
96+
local procedure CollectReturnLocations(ReturnId: BigInteger): Dictionary of [BigInteger, BigInteger]
97+
var
98+
ReturnsAPI: Codeunit "Shpfy Returns API";
99+
begin
100+
if ReturnId <> 0 then
101+
exit(ReturnsAPI.GetReturnLocations(ReturnId));
102+
end;
103+
104+
local procedure FillInRefundLine(RefundId: BigInteger; JLine: JsonObject; NonZeroOrReturnRefund: Boolean; ReturnLocations: Dictionary of [BigInteger, BigInteger])
92105
var
93106
DataCapture: Record "Shpfy Data Capture";
94107
RefundLine: Record "Shpfy Refund Line";
95108
RefundLineRecordRef: RecordRef;
96109
Id: BigInteger;
110+
ReturnLocation: BigInteger;
97111
begin
98112
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'lineItem.id'));
113+
99114
if not RefundLine.Get(RefundId, Id) then begin
100115
RefundLine."Refund Line Id" := Id;
101116
RefundLine."Refund Id" := RefundId;
102117
RefundLine."Order Line Id" := Id;
103118
RefundLine.Insert();
104119
end;
120+
105121
RefundLine."Restock Type" := RefundEnumConvertor.ConvertToReStockType(JsonHelper.GetValueAsText(JLine, 'restockType'));
122+
106123
RefundLineRecordRef.GetTable(RefundLine);
107124
JsonHelper.GetValueIntoField(JLine, 'quantity', RefundLineRecordRef, RefundLine.FieldNo(Quantity));
108125
JsonHelper.GetValueIntoField(JLine, 'restocked', RefundLineRecordRef, RefundLine.FieldNo(Restocked));
@@ -113,8 +130,17 @@ codeunit 30228 "Shpfy Refunds API"
113130
JsonHelper.GetValueIntoField(JLine, 'totalTaxSet.shopMoney.amount', RefundLineRecordRef, RefundLine.FieldNo("Total Tax Amount"));
114131
JsonHelper.GetValueIntoField(JLine, 'totalTaxSet.presentmentMoney.amount', RefundLineRecordRef, RefundLine.FieldNo("Presentment Total Tax Amount"));
115132
RefundLineRecordRef.SetTable(RefundLine);
133+
116134
RefundLine."Can Create Credit Memo" := NonZeroOrReturnRefund;
135+
RefundLine."Location Id" := JsonHelper.GetValueAsBigInteger(JLine, 'location.legacyResourceId');
136+
137+
// If refund was created from a return, the location needs to come from the return
138+
// If Item was restocked to multiple locations, the return location is not known
139+
if (RefundLine."Location Id" = 0) and (ReturnLocations.Get(RefundLine."Order Line Id", ReturnLocation)) then
140+
RefundLine."Location Id" := ReturnLocation;
141+
117142
RefundLine.Modify();
143+
118144
RefundLineRecordRef.Close();
119145
DataCapture.Add(Database::"Shpfy Refund Line", RefundLine.SystemId, JLine);
120146
end;

Apps/W1/Shopify/app/src/Order Refunds/Tables/ShpfyRefundLine.Table.al

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ table 30145 "Shpfy Refund Line"
115115
CalcFormula = lookup("Shpfy Order Line"."Gift Card" where("Line Id" = field("Order Line Id")));
116116
Editable = false;
117117
}
118+
field(105; "Location Id"; BigInteger)
119+
{
120+
Caption = 'Location Id';
121+
DataClassification = SystemMetadata;
122+
Editable = false;
123+
}
118124
}
119125
keys
120126
{

Apps/W1/Shopify/app/src/Order Return Refund Processing/Codeunits/ShpfyCreateSalesDocRefund.Codeunit.al

+15-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ codeunit 30246 "Shpfy Create Sales Doc. Refund"
111111
SalesHeader.Validate("Document Date", DT2Date(RefundHeader."Created At"));
112112
if OrderMgt.FindTaxArea(OrderHeader, ShopifyTaxArea) and (ShopifyTaxArea."Tax Area Code" <> '') then
113113
SalesHeader.Validate("Tax Area Code", ShopifyTaxArea."Tax Area Code");
114-
SalesHeader.Validate("Location Code", Shop."Return Location");
115114
end;
116115
SalesHeader."Shpfy Refund Id" := RefundHeader."Refund Id";
117116
SalesHeader.Modify(true);
@@ -143,6 +142,7 @@ codeunit 30246 "Shpfy Create Sales Doc. Refund"
143142
RefundLine: Record "Shpfy Refund Line";
144143
ReturnLine: Record "Shpfy Return Line";
145144
GiftCard: Record "Shpfy Gift Card";
145+
ShopLocation: Record "Shpfy Shop Location";
146146
LineNo: Integer;
147147
OpenAmount: Decimal;
148148
IsHandled: Boolean;
@@ -181,7 +181,13 @@ codeunit 30246 "Shpfy Create Sales Doc. Refund"
181181
SalesLine.Validate("No.", RefundLine."Item No.");
182182
if RefundLine."Variant Code" <> '' then
183183
SalesLine.Validate("Variant Code", RefundLine."Variant Code");
184-
SalesLine.Validate("Location Code", Shop."Return Location");
184+
185+
if ShopLocation.Get(Shop.Code, RefundLine."Location Id") then
186+
SalesLine.Validate("Location Code", ShopLocation."Default Location Code");
187+
188+
If (Shop."Return Location Priority" = "Shpfy Return Location Priority"::"Default Return Location") or (SalesLine."Location Code" = '') then
189+
SalesLine.Validate("Location Code", Shop."Return Location");
190+
185191
end;
186192
SalesLine.Validate(Quantity, RefundLine.Quantity);
187193
SalesLine.Validate("Unit Price", RefundLine.Amount);
@@ -233,7 +239,13 @@ codeunit 30246 "Shpfy Create Sales Doc. Refund"
233239
SalesLine.Validate("No.", ReturnLine."Item No.");
234240
if ReturnLine."Variant Code" <> '' then
235241
SalesLine.Validate("Variant Code", ReturnLine."Variant Code");
236-
SalesLine.Validate("Location Code", Shop."Return Location");
242+
243+
if ShopLocation.Get(Shop.Code, ReturnLine."Location Id") then
244+
SalesLine.Validate("Location Code", ShopLocation."Default Location Code");
245+
246+
If (Shop."Return Location Priority" = "Shpfy Return Location Priority"::"Default Return Location") or (SalesLine."Location Code" = '') then
247+
SalesLine.Validate("Location Code", Shop."Return Location");
248+
237249
SalesLine.Validate(Quantity, ReturnLine.Quantity);
238250
SalesLine.Validate("Unit Price", ReturnLine."Discounted Total Amount" / ReturnLine.Quantity);
239251
end;

0 commit comments

Comments
 (0)