@@ -31,11 +31,14 @@ codeunit 30228 "Shpfy Refunds API"
31
31
RefundHeader: Record "Shpfy Refund Header";
32
32
GraphQLType: Enum "Shpfy GraphQL Type";
33
33
Parameters: Dictionary of [text , Text ];
34
+ ReturnLocations: Dictionary of [BigInteger , BigInteger ];
34
35
JResponse: JsonToken ;
35
36
JLines: JsonArray ;
36
37
JLine: JsonToken ;
37
38
begin
38
39
GetRefundHeader( RefundId, UpdatedAt, RefundHeader) ;
40
+ ReturnLocations := CollectReturnLocations( RefundHeader. "Return Id") ;
41
+
39
42
Parameters. Add ( ' RefundId' , Format( RefundId)) ;
40
43
GraphQLType := "Shpfy GraphQL Type"::GetRefundLines;
41
44
repeat
@@ -46,8 +49,9 @@ codeunit 30228 "Shpfy Refunds API"
46
49
Parameters. Set( ' After' , JsonHelper. GetValueAsText( JResponse, ' data.refund.refundLineItems.pageInfo.endCursor' ))
47
50
else
48
51
Parameters. Add ( ' After' , JsonHelper. GetValueAsText( JResponse, ' data.refund.refundLineItems.pageInfo.endCursor' )) ;
52
+
49
53
foreach JLine in JLines do
50
- FillInRefundLine( RefundId, JLine. AsObject() , IsNonZeroOrReturnRefund( RefundHeader)) ;
54
+ FillInRefundLine( RefundId, JLine. AsObject() , IsNonZeroOrReturnRefund( RefundHeader) , ReturnLocations ) ;
51
55
until not JsonHelper. GetValueAsBoolean( JResponse, ' data.refund.refundLineItems.pageInfo.hasNextPage' ) ;
52
56
end ;
53
57
@@ -88,21 +92,34 @@ codeunit 30228 "Shpfy Refunds API"
88
92
DataCapture. Add ( Database ::"Shpfy Refund Header", RefundHeader. SystemId, JResponse) ;
89
93
end ;
90
94
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 ])
92
105
var
93
106
DataCapture: Record "Shpfy Data Capture";
94
107
RefundLine: Record "Shpfy Refund Line";
95
108
RefundLineRecordRef: RecordRef ;
96
109
Id: BigInteger ;
110
+ ReturnLocation: BigInteger ;
97
111
begin
98
112
Id := CommunicationMgt. GetIdOfGId( JsonHelper. GetValueAsText( JLine, ' lineItem.id' )) ;
113
+
99
114
if not RefundLine. Get( RefundId, Id) then begin
100
115
RefundLine. "Refund Line Id" := Id;
101
116
RefundLine. "Refund Id" := RefundId;
102
117
RefundLine. "Order Line Id" := Id;
103
118
RefundLine. Insert() ;
104
119
end ;
120
+
105
121
RefundLine. "Restock Type" := RefundEnumConvertor. ConvertToReStockType( JsonHelper. GetValueAsText( JLine, ' restockType' )) ;
122
+
106
123
RefundLineRecordRef. GetTable( RefundLine) ;
107
124
JsonHelper. GetValueIntoField( JLine, ' quantity' , RefundLineRecordRef, RefundLine. FieldNo( Quantity)) ;
108
125
JsonHelper. GetValueIntoField( JLine, ' restocked' , RefundLineRecordRef, RefundLine. FieldNo( Restocked)) ;
@@ -113,8 +130,17 @@ codeunit 30228 "Shpfy Refunds API"
113
130
JsonHelper. GetValueIntoField( JLine, ' totalTaxSet.shopMoney.amount' , RefundLineRecordRef, RefundLine. FieldNo( "Total Tax Amount")) ;
114
131
JsonHelper. GetValueIntoField( JLine, ' totalTaxSet.presentmentMoney.amount' , RefundLineRecordRef, RefundLine. FieldNo( "Presentment Total Tax Amount")) ;
115
132
RefundLineRecordRef. SetTable( RefundLine) ;
133
+
116
134
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
+
117
142
RefundLine. Modify () ;
143
+
118
144
RefundLineRecordRef. Close() ;
119
145
DataCapture. Add ( Database ::"Shpfy Refund Line", RefundLine. SystemId, JLine) ;
120
146
end ;
0 commit comments