Skip to content
Open
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 @@ -576,6 +576,10 @@ page 30101 "Shpfy Shop Card"
Caption = 'Return Location Priority';
ToolTip = 'Specifies the priority of the return location.';
}
field("Process Returns As"; Rec."Process Returns As")
{
ApplicationArea = All;
}
field("Location Code of Returns"; Rec."Return Location")
{
ApplicationArea = All;
Expand Down
6 changes: 6 additions & 0 deletions src/Apps/W1/Shopify/App/src/Base/Tables/ShpfyShop.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,12 @@ table 30102 "Shpfy Shop"
Caption = 'Currency Handling';
InitValue = "Shop Currency";
}
field(136; "Process Returns As"; Enum "Shpfy Process Returns As")
{
Caption = 'Process Returns As';
ToolTip = 'Specifies what type of document to create when processing returns. Credit Memo creates a sales credit memo. Return Order creates a sales return order.';
DataClassification = CustomerContent;
}
field(200; "Shop Id"; Integer)
{
DataClassification = SystemMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ page 30145 "Shpfy Refund"
{
action(CreateCreditMemo)
{
Caption = 'Create Credit Memo';
Image = CreateCreditMemo;
ToolTip = 'Create a credit memo for this refund.';
Caption = 'Create Sales Document';
Image = CreateDocument;
ToolTip = 'Create a sales document for this refund. The document type (Credit Memo or Return Order) is determined by the shop setting.';
Enabled = CanCreateDocument;

trigger OnAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ page 30147 "Shpfy Refunds"
{
action(CreateCreditMemo)
{
Caption = 'Create Credit Memo';
Image = CreateCreditMemo;
ToolTip = 'Create a credit memo for this refund.';
Caption = 'Create Sales Document';
Image = CreateDocument;
ToolTip = 'Create a sales document for this refund. The document type (Credit Memo or Return Order) is determined by the shop setting.';
Enabled = CanCreateDocument and not MultipleSelected;

trigger OnAction()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ------------------------------------------------------------------------------------------------
// 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;

using Microsoft.Sales.Document;

codeunit 30236 "Shpfy Process Credit Memo" implements "Shpfy IProcess Returns As"
{
procedure GetTargetDocumentType(): Enum "Sales Document Type"
begin
exit("Sales Document Type"::"Credit Memo");
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ------------------------------------------------------------------------------------------------
// 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;

using Microsoft.Sales.Document;

codeunit 30422 "Shpfy Process Return Order" implements "Shpfy IProcess Returns As"
{
procedure GetTargetDocumentType(): Enum "Sales Document Type"
begin
exit("Sales Document Type"::"Return Order");
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ codeunit 30243 "Shpfy RetRefProc Cr.Memo" implements "Shpfy IReturnRefund Proces

procedure CreateSalesDocument(SourceDocumentType: Enum "Shpfy Source Document Type"; SourceDocumentId: BigInteger) SalesHeader: Record "Sales Header"
var
RefundHeader: Record "Shpfy Refund Header";
RefundLine: Record "Shpfy Refund Line";
CreateSalesDocRefund: codeunit "Shpfy Create Sales Doc. Refund";
Shop: Record "Shpfy Shop";
CreateSalesDocRefund: Codeunit "Shpfy Create Sales Doc. Refund";
IDocumentSource: Interface "Shpfy IDocument Source";
IProcessReturnsAs: Interface "Shpfy IProcess Returns As";
ErrorInfo: ErrorInfo;
TextBuilder: TextBuilder;
begin
Expand All @@ -83,7 +86,12 @@ codeunit 30243 "Shpfy RetRefProc Cr.Memo" implements "Shpfy IReturnRefund Proces
exit;

CreateSalesDocRefund.SetSource(SourceDocumentId);
CreateSalesDocRefund.SetTargetDocumentType(SalesHeader."Document Type"::"Credit Memo");

RefundHeader.Get(SourceDocumentId);
Shop.Get(RefundHeader."Shop Code");
IProcessReturnsAs := Shop."Process Returns As";
CreateSalesDocRefund.SetTargetDocumentType(IProcessReturnsAs.GetTargetDocumentType());

Commit();
if CreateSalesDocRefund.Run() then begin
SalesHeader := CreateSalesDocRefund.GetSalesHeader();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ------------------------------------------------------------------------------------------------
// 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 30180 "Shpfy Process Returns As" implements "Shpfy IProcess Returns As"
{
Extensible = true;

value(0; "Credit Memo")
{
Caption = 'Credit Memo';
Implementation = "Shpfy IProcess Returns As" = "Shpfy Process Credit Memo";
}
value(1; "Return Order")
{
Caption = 'Return Order';
Implementation = "Shpfy IProcess Returns As" = "Shpfy Process Return Order";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum 30139 "Shpfy ReturnRefund ProcessType" implements "Shpfy IReturnRefund Proc
}
value(3; "Auto Create Credit Memo")
{
Caption = 'Auto Create Credit Memo';
Caption = 'Auto Create Sales Document';
Implementation = "Shpfy IReturnRefund Process" = "Shpfy RetRefProc Cr.Memo";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ------------------------------------------------------------------------------------------------
// 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;

using Microsoft.Sales.Document;

interface "Shpfy IProcess Returns As"
{
procedure GetTargetDocumentType(): Enum "Sales Document Type";
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ codeunit 139611 "Shpfy Order Refund Test"
SalesHeader.CalcFields("Amount Including VAT");
LibraryAssert.AreEqual(RefundHeader."Total Refunded Amount", SalesHeader."Amount Including VAT", 'The SalesHeader."Amount Including VAT" must be equal to RefundHeader."Total Refunded Amount".');
// Tear down
ResetProccesOnRefund(RefundId);
ResetProcessOnRefund(RefundId);
end;

[Test]
Expand Down Expand Up @@ -99,7 +99,7 @@ codeunit 139611 "Shpfy Order Refund Test"
SalesHeader.CalcFields("Amount Including VAT");
LibraryAssert.AreNearlyEqual(RefundHeader."Total Refunded Amount", SalesHeader."Amount Including VAT", 0.5, 'The SalesHeader."Amount Including VAT" must be equal to RefundHeader."Total Refunded Amount".');
// Tear down
ResetProccesOnRefund(RefundId);
ResetProcessOnRefund(RefundId);
end;

[Test]
Expand Down Expand Up @@ -136,7 +136,7 @@ codeunit 139611 "Shpfy Order Refund Test"
LibraryAssert.AreEqual(RefundHeader."Total Refunded Amount", SalesHeader."Amount Including VAT", 'The SalesHeader."Amount Including VAT" must be equal to RefundHeader."Total Refunded Amount".');

// Tear down
ResetProccesOnRefund(RefundId);
ResetProcessOnRefund(RefundId);
end;

[Test]
Expand Down Expand Up @@ -434,7 +434,7 @@ codeunit 139611 "Shpfy Order Refund Test"
SalesLine.SetRange(Description, StrSubstNo(ShopifyOrderNoLbl, RefundHeader."Shopify Order No."));
LibraryAssert.RecordIsNotEmpty(SalesLine);
// Tear down
ResetProccesOnRefund(RefundId);
ResetProcessOnRefund(RefundId);
end;

[Test]
Expand All @@ -444,13 +444,15 @@ codeunit 139611 "Shpfy Order Refund Test"
SalesHeader: Record "Sales Header";
RefundHeader: Record "Shpfy Refund Header";
RefundId: BigInteger;
IReturnRefundProcess: Interface "Shpfy IReturnRefund Process";
IReturnRefundProcess: Interface "Shpfy IReturnRefund Process";
CanCreateDocument: Boolean;
ErrorInfo: ErrorInfo;
RefundAccount: Code[20];
begin
// [SCENARIO] Create a Credit Memo from a Shopify Refund where only the shipment is refunded.
Initialize();
Shop := InitializeTest.CreateShop();
RefundAccount := Shop."Refund Account";
Shop."Refund Account" := '';
Shop.Modify(false);

Expand All @@ -473,7 +475,47 @@ codeunit 139611 "Shpfy Order Refund Test"
LibraryAssert.AreEqual(RefundHeader."Has Processing Error", true, 'RefundHeader."Has Processing Error" must be true');

// Tear down
ResetProccesOnRefund(RefundId);
ResetProcessOnRefund(RefundId);
Shop."Refund Account" := RefundAccount;
Shop.Modify(false);
end;

[Test]
procedure UnitTestCreateReturnOrder()
var
SalesHeader: Record "Sales Header";
RefundHeader: Record "Shpfy Refund Header";
Shop: Record "Shpfy Shop";
RefundId: BigInteger;
IReturnRefundProcess: Interface "Shpfy IReturnRefund Process";
CanCreateDocument: Boolean;
ErrorInfo: ErrorInfo;
begin
// [SCENARIO] Create a Return Order from a Shopify Refund where only the shipment is refunded.
Initialize();

// [GIVEN] Shop configured to process returns as Return Order
Shop := InitializeTest.CreateShop();
Shop."Process Returns As" := "Shpfy Process Returns As"::"Return Order";
Shop.Modify(false);

// [GIVEN] Set the process of the document: "Auto Create Credit Memo";
IReturnRefundProcess := Enum::"Shpfy ReturnRefund ProcessType"::"Auto Create Credit Memo";
// [GIVEN] The document type Refund
// [GIVEN] The RefundId of the refund for creating the Return Order.
RefundId := ShopifyIds.Get('Refund').Get(2);

// [WHEN] Execute IReturnRefundProcess.CanCreateSalesDocumentFor(Enum::"Shpfy Source Document Type"::Refund, RefundId, errorInfo)
CanCreateDocument := IReturnRefundProcess.CanCreateSalesDocumentFor(Enum::"Shpfy Source Document Type"::Refund, RefundId, errorInfo);
// [THEN] CanCreateDocument must be true
LibraryAssert.IsTrue(CanCreateDocument, 'The result of IReturnRefundProcess.CanCreateSalesDocumentFor must be true');

// [WHEN] Execute IReturnRefundProcess.CreateSalesDocument(Enum::"Shpfy Source Document Type"::Refund, RefundId)
SalesHeader := IReturnRefundProcess.CreateSalesDocument(Enum::"Shpfy Source Document Type"::Refund, RefundId);
// [THEN] SalesHeader."Document Type" = Enum::"Sales Document Type"::"Return Order"
LibraryAssert.AreEqual(Enum::"Sales Document Type"::"Return Order", SalesHeader."Document Type", 'SalesHeader."Document Type" must be a Return Order');
// Tear down
ResetProcessOnRefund(RefundId);
end;

local procedure Initialize()
Expand All @@ -492,7 +534,7 @@ codeunit 139611 "Shpfy Order Refund Test"
Commit();
end;

local procedure ResetProccesOnRefund(ReFundId: Integer)
local procedure ResetProcessOnRefund(ReFundId: Integer)
var
ShpfyDocLinkToDoc: Record "Shpfy Doc. Link To Doc.";
begin
Expand Down
Loading