From 713875fede4e90c02f1ee120b7239b6e686cd612 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 25 Sep 2024 16:50:58 +0200 Subject: [PATCH 01/32] Add Skipped Record table definition --- .../Logs/Tables/ShpfySkippedRecord.Table.al | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al new file mode 100644 index 0000000000..1c3e3496db --- /dev/null +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -0,0 +1,71 @@ +namespace Microsoft.Integration.Shopify; + +using System.Reflection; + + +table 30159 "Shpfy Skipped Record" +{ + Caption = 'Shpfy Skipped Record'; + DataClassification = SystemMetadata; + Access = Internal; + + fields + { + field(1; "Entry No."; Integer) + { + AutoIncrement = true; + Caption = 'Entry No.'; + DataClassification = SystemMetadata; + } + field(2; "Shopify Id"; BigInteger) + { + Caption = 'Skipped Record Id'; + DataClassification = SystemMetadata; + } + field(3; "Table ID"; Integer) + { + Caption = 'Table ID'; + DataClassification = SystemMetadata; + + trigger OnValidate() + begin + "Table Name" := GetTableCaption(); + end; + } + field(4; "Table Name"; Text[250]) + { + Caption = 'Table Name'; + DataClassification = SystemMetadata; + } + field(5; "Record ID"; RecordID) + { + Caption = 'Record ID'; + DataClassification = CustomerContent; + } + field(6; Description; Text[250]) + { + Caption = 'Description'; + DataClassification = SystemMetadata; + } + + + + + } + keys + { + key(Key1; "Entry No.") + { + Clustered = true; + } + } + + local procedure GetTableCaption(): Text[250] + var + AllObjWithCaption: Record AllObjWithCaption; + begin + if "Table ID" <> 0 then + if AllObjWithCaption.Get(AllObjWithCaption."Object Type"::Table, "Table ID") then + exit(AllObjWithCaption."Object Caption"); + end; +} From 096152abb8ddcbb04de51a6b65536d4419a520d9 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 27 Sep 2024 16:46:04 +0200 Subject: [PATCH 02/32] Add logging function --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 5 +- .../ShpfyAuthenticationMgt.Codeunit.al | 4 ++ .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 21 +++++++ .../Logs/Pages/ShpfySkippedRecords.Page.al | 62 +++++++++++++++++++ .../Logs/Tables/ShpfySkippedRecord.Table.al | 61 +++++++++++++++++- .../Codeunits/ShpfyProductExport.Codeunit.al | 13 +++- 6 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 363fe23448..c262e129cb 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -296,10 +296,13 @@ codeunit 30116 "Shpfy Customer Export" var ShopifyCustomer: Record "Shpfy Customer"; CustomerAddress: Record "Shpfy Customer Address"; + ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; begin ShopifyCustomer.Get(CustomerID); - if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then + if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, 'Customer already exists with the same e-mail or phone.'); exit; // An other customer with the same e-mail or phone is the source of it. + end; CustomerAddress.SetRange("Customer Id", CustomerId); CustomerAddress.SetRange(Default, true); diff --git a/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al index d57fc3c1be..eaa309953f 100644 --- a/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al @@ -33,6 +33,8 @@ codeunit 30199 "Shpfy Authentication Mgt." EnvironmentInformation: Codeunit "Environment Information"; ClientId: SecretText; begin + exit(SecretText.SecretStrSubstNo('ff3cdb3a6a4fe97dbd9219e32a9594f3')); + if not EnvironmentInformation.IsSaaS() then Error(NotSupportedOnPremErr); @@ -49,6 +51,8 @@ codeunit 30199 "Shpfy Authentication Mgt." EnvironmentInformation: Codeunit "Environment Information"; ClientSecret: SecretText; begin + exit(SecretText.SecretStrSubstNo('96fa169b584920fe01183a02ffd00d7f')); + if not EnvironmentInformation.IsSaaS() then Error(NotSupportedOnPremErr); diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al new file mode 100644 index 0000000000..a9927d4655 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -0,0 +1,21 @@ +namespace Microsoft.Integration.Shopify; + +codeunit 30168 "Shpfy Skip Record Mgt." +{ + Access = Internal; + Permissions = tabledata "Shpfy Skipped Record" = rimd; + + internal procedure LogSkippedRecord(ShopifyId: BigInteger; TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]) + var + ShpfySkippedRecord: Record "Shpfy Skipped Record"; + begin + ShpfySkippedRecord.Init(); + ShpfySkippedRecord.Validate("Shopify Id", ShopifyId); + ShpfySkippedRecord.Validate("Table ID", TableId); + ShpfySkippedRecord.Validate("Record ID", RecordId); + ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason); + ShpfySkippedRecord.Validate("Created On", CURRENTDATETIME); + ShpfySkippedRecord.Insert(false); + end; + +} diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al new file mode 100644 index 0000000000..24a7fd6fb2 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -0,0 +1,62 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Page Shpfy Skipped Records (ID 30119). +/// +page 30165 "Shpfy Skipped Records" +{ + ApplicationArea = All; + Caption = 'Shopify Skipped Records'; + PageType = List; + SourceTable = "Shpfy Skipped Record"; + UsageCategory = Lists; + Editable = false; + InsertAllowed = false; + SourceTableView = sorting("Entry No.") order(descending); + + layout + { + area(Content) + { + repeater(General) + { + field(EntryNo; Rec."Entry No.") + { + ApplicationArea = All; + ToolTip = 'Specifies the number of the entry, as assigned from the specific number series when the entry was created.'; + } + field("Shopify Id"; Rec."Shopify Id") + { + ApplicationArea = All; + ToolTip = 'Specifies the Shopify Id of the skipped record.'; + } + field("Table ID"; Rec."Table ID") + { + ApplicationArea = All; + ToolTip = 'Specifies the Table ID of the skipped record.'; + } + field("Table Name"; Rec."Table Name") + { + ApplicationArea = All; + ToolTip = 'Specifies the Table Name of the skipped record.'; + } + field(Description; Rec.Description) + { + ApplicationArea = All; + ToolTip = 'Specifies the description of the skipped record.'; + + + trigger OnDrillDown() + begin + Rec.ShowPage(); + end; + } + field("Skipped Reason"; Rec."Skipped Reason") + { + ApplicationArea = All; + ToolTip = 'Specifies the reason why the record was skipped.'; + } + } + } + } +} diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index 1c3e3496db..f29ad28351 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -1,8 +1,11 @@ namespace Microsoft.Integration.Shopify; using System.Reflection; +using Microsoft.Utilities; - +/// +/// Table Shpfy Skipped Record (ID 30159). +/// table 30159 "Shpfy Skipped Record" { Caption = 'Shpfy Skipped Record'; @@ -41,13 +44,27 @@ table 30159 "Shpfy Skipped Record" { Caption = 'Record ID'; DataClassification = CustomerContent; + + trigger OnValidate() + begin + Description := GetRecDescription(); + end; } field(6; Description; Text[250]) { Caption = 'Description'; DataClassification = SystemMetadata; } - + field(7; "Skipped Reason"; Text[250]) + { + Caption = 'Skipped Reason'; + DataClassification = SystemMetadata; + } + field(8; "Created On"; DateTime) + { + Caption = 'Created On'; + DataClassification = SystemMetadata; + } @@ -68,4 +85,44 @@ table 30159 "Shpfy Skipped Record" if AllObjWithCaption.Get(AllObjWithCaption."Object Type"::Table, "Table ID") then exit(AllObjWithCaption."Object Caption"); end; + + procedure GetRecDescription() Result: Text + var + RecRef: RecordRef; + PKFilter: Text; + Delimiter: Text; + Pos: Integer; + begin + if RecRef.Get("Record ID") then begin + RecRef.SetRecFilter(); + PKFilter := RecRef.GetView(); + repeat + Pos := StrPos(PKFilter, '=FILTER('); + if Pos <> 0 then begin + PKFilter := CopyStr(PKFilter, Pos + 8); + Result += Delimiter + CopyStr(PKFilter, 1, StrPos(PKFilter, ')') - 1); + Delimiter := ','; + end; + until Pos = 0; + end; + end; + + internal procedure ShowPage() + var + TableMetadata: Record "Table Metadata"; + PageManagement: Codeunit "Page Management"; + RecordId: RecordID; + begin + RecordId := "Record ID"; + + if RecordID.TableNo() = 0 then + exit; + if not TableMetadata.Get(RecordID.TableNo()) then + exit; + + if not TableMetadata.DataIsExternal then begin + PageManagement.PageRun(RecordID); + exit; + end; + end; } diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index ec7c7fbbd5..d0e0c2f69a 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -59,6 +59,7 @@ codeunit 30178 "Shpfy Product Export" ProductEvents: Codeunit "Shpfy Product Events"; ProductPriceCalc: Codeunit "Shpfy Product Price Calc."; VariantApi: Codeunit "Shpfy Variant API"; + ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; OnlyUpdatePrice: Boolean; RecordCount: Integer; NullGuid: Guid; @@ -352,7 +353,9 @@ codeunit 30178 "Shpfy Product Export" begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then - ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price"); + ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") + else + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", Item.RecordId, 'Item is blocked/sales blocked'); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -397,7 +400,9 @@ codeunit 30178 "Shpfy Product Export" begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then - ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price"); + ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") + else + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, 'Price is not synchronized becuse the item is blocked/sales blocked.'); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -554,8 +559,10 @@ codeunit 30178 "Shpfy Product Export" if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then exit; Shop."Action for Removed Products"::DoNothing: - if Item.Blocked then + if Item.Blocked then begin + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, 'Product is blocked'); exit; + end; end; TempShopifyProduct := ShopifyProduct; FillInProductFields(Item, ShopifyProduct); From da67ced5625e1034c07766f87e71247d26690881 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Sat, 28 Sep 2024 17:41:13 +0200 Subject: [PATCH 03/32] Add retention policy related code --- .../Shopify/app/src/Base/Codeunits/ShpfyInstaller.Codeunit.al | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Apps/W1/Shopify/app/src/Base/Codeunits/ShpfyInstaller.Codeunit.al b/Apps/W1/Shopify/app/src/Base/Codeunits/ShpfyInstaller.Codeunit.al index 4072add050..891527bebb 100644 --- a/Apps/W1/Shopify/app/src/Base/Codeunits/ShpfyInstaller.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Base/Codeunits/ShpfyInstaller.Codeunit.al @@ -27,6 +27,7 @@ codeunit 30273 "Shpfy Installer" var LogEntry: Record "Shpfy Log Entry"; DataCapture: Record "Shpfy Data Capture"; + SkippedRecord: Record "Shpfy Skipped Record"; RetentionPolicySetup: Codeunit "Retention Policy Setup"; RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables"; UpgradeTag: Codeunit "Upgrade Tag"; @@ -38,12 +39,14 @@ codeunit 30273 "Shpfy Installer" RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Log Entry", LogEntry.FieldNo(SystemCreatedAt)); RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Data Capture", DataCapture.FieldNo(SystemModifiedAt)); + RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Skipped Record", SkippedRecord.FieldNo(SystemCreatedAt)); if not IsInitialSetup then exit; CreateRetentionPolicySetup(Database::"Shpfy Log Entry", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month")); CreateRetentionPolicySetup(Database::"Shpfy Data Capture", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month")); + CreateRetentionPolicySetup(Database::"Shpfy Skipped Record", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month")); UpgradeTag.SetUpgradeTag(GetShopifyLogEntryAddedToAllowedListUpgradeTag()); end; From 134b1e7b7a95b9fae558e3511aab348cd5b14752 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 1 Oct 2024 14:46:11 +0200 Subject: [PATCH 04/32] Add new logs,add fields in log --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 10 ++++++--- .../ShpfyPostedInvoiceExport.Codeunit.al | 21 +++++++++++++++---- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 3 ++- .../Logs/Pages/ShpfySkippedRecords.Page.al | 12 ++++++++++- .../Logs/Tables/ShpfySkippedRecord.Table.al | 6 +++++- .../Codeunits/ShpfyProductExport.Codeunit.al | 17 +++++++++++---- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index c262e129cb..9d2faca396 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -39,6 +39,7 @@ codeunit 30116 "Shpfy Customer Export" var Shop: Record "Shpfy Shop"; CustomerApi: Codeunit "Shpfy Customer API"; + ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; @@ -87,9 +88,12 @@ codeunit 30116 "Shpfy Customer Export" var ShopifyCustomer: Record "Shpfy Customer"; CustomerAddress: Record "Shpfy Customer Address"; + EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin - if Customer."E-Mail" = '' then + if Customer."E-Mail" = '' then begin + ShopifySkipRecordMgt.LogSkippedRecord(0, Database::Customer, Customer.RecordId, EmptyEmailAddressLbl); exit; + end; Clear(ShopifyCustomer); Clear(CustomerAddress); @@ -296,11 +300,11 @@ codeunit 30116 "Shpfy Customer Export" var ShopifyCustomer: Record "Shpfy Customer"; CustomerAddress: Record "Shpfy Customer Address"; - ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + CustomerWithPhoneNoOrEmailExistsLbl: Label 'Customer already exists with the same e-mail or phone.'; begin ShopifyCustomer.Get(CustomerID); if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, 'Customer already exists with the same e-mail or phone.'); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl); exit; // An other customer with the same e-mail or phone is the source of it. end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 60fe4f7eab..e0df1fdcfc 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -17,6 +17,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" DraftOrdersAPI: Codeunit "Shpfy Draft Orders API"; FulfillmentAPI: Codeunit "Shpfy Fulfillment API"; JsonHelper: Codeunit "Shpfy Json Helper"; + SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; trigger OnRun() begin @@ -88,22 +89,34 @@ codeunit 30362 "Shpfy Posted Invoice Export" var ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; + CustomerNotExistingAsCompanyOrCustomerLbl: Label 'Customer not existing as Shopify company or customer'; + PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify', Comment = '%1 = Payment Terms Code'; + CustomerNoIsDefaultCustomerNoLbl: Label 'Customer No. is the default customer no. from Shopify shop'; + CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2', Comment = '%1 = Customer No., %2 = Shop Code'; begin ShopifyCompany.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCompany.IsEmpty() then begin ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); - if ShopifyCustomer.IsEmpty() then + if ShopifyCustomer.IsEmpty() then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistingAsCompanyOrCustomerLbl); exit(false); + end; end; - if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then + if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code")); exit(false); + end; - if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then + if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl); exit(false); + end; - if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then + if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code)); exit(false); + end; if not CheckSalesInvoiceHeaderLines(SalesInvoiceHeader) then exit(false); diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index a9927d4655..dd673622ed 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -14,7 +14,8 @@ codeunit 30168 "Shpfy Skip Record Mgt." ShpfySkippedRecord.Validate("Table ID", TableId); ShpfySkippedRecord.Validate("Record ID", RecordId); ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason); - ShpfySkippedRecord.Validate("Created On", CURRENTDATETIME); + ShpfySkippedRecord.Validate("Created On", CurrentDateTime); + ShpfySkippedRecord.Validate("Created Time", DT2Time(CurrentDateTime)); ShpfySkippedRecord.Insert(false); end; diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index 24a7fd6fb2..b1b2d46856 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -56,7 +56,17 @@ page 30165 "Shpfy Skipped Records" ApplicationArea = All; ToolTip = 'Specifies the reason why the record was skipped.'; } + field("Created On"; Rec."Created On") + { + ApplicationArea = All; + ToolTip = 'Specifies the date and time when the record was created.'; + } + field("Created Time"; Rec."Created Time") + { + ApplicationArea = All; + ToolTip = 'Specifies the time when the record was created.'; + } } } } -} +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index f29ad28351..d964f213de 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -65,7 +65,11 @@ table 30159 "Shpfy Skipped Record" Caption = 'Created On'; DataClassification = SystemMetadata; } - + field(9; "Created Time"; Time) + { + Caption = 'Created Time'; + DataClassification = SystemMetadata; + } } diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index d0e0c2f69a..0bc8ec07f5 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -350,12 +350,14 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record Item. /// Parameter of type Record "Item Variant". local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant") + var + ItemIsBlockedLbl: Label 'Item is blocked/sales blocked'; begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", Item.RecordId, 'Item is blocked/sales blocked'); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -549,18 +551,25 @@ codeunit 30178 "Shpfy Product Export" RecordRef1: RecordRef; RecordRef2: RecordRef; VariantAction: Option " ",Create,Update; + ItemIsBlockedLbl: Label 'Item is blocked.'; + ItemIsDraftLbl: Label 'Product is draft.'; + ItemIsArchivedLbl: Label 'Product is archived'; begin if ShopifyProduct.Get(ProductId) and Item.GetBySystemId(ShopifyProduct."Item SystemId") then begin case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: - if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then + if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsArchivedLbl); exit; + end; Shop."Action for Removed Products"::StatusToDraft: - if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then + if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsDraftLbl); exit; + end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, 'Product is blocked'); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsBlockedLbl); exit; end; end; From ff08b22fcead8e03d6a7004412d1bc1339e5c8a3 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 1 Oct 2024 17:10:20 +0200 Subject: [PATCH 05/32] add skipping logs to lines export, add shop so logging can be ommited --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 4 +-- .../ShpfyPostedInvoiceExport.Codeunit.al | 30 ++++++++++++------- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 6 +++- .../Codeunits/ShpfyProductExport.Codeunit.al | 12 ++++---- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 9d2faca396..64acfd3522 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -91,7 +91,7 @@ codeunit 30116 "Shpfy Customer Export" EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShopifySkipRecordMgt.LogSkippedRecord(0, Database::Customer, Customer.RecordId, EmptyEmailAddressLbl); + ShopifySkipRecordMgt.LogSkippedRecord(0, Database::Customer, Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; @@ -304,7 +304,7 @@ codeunit 30116 "Shpfy Customer Export" begin ShopifyCustomer.Get(CustomerID); if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); exit; // An other customer with the same e-mail or phone is the source of it. end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index e0df1fdcfc..6c0e5ab5a3 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -89,32 +89,32 @@ codeunit 30362 "Shpfy Posted Invoice Export" var ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; - CustomerNotExistingAsCompanyOrCustomerLbl: Label 'Customer not existing as Shopify company or customer'; - PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify', Comment = '%1 = Payment Terms Code'; - CustomerNoIsDefaultCustomerNoLbl: Label 'Customer No. is the default customer no. from Shopify shop'; - CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2', Comment = '%1 = Customer No., %2 = Shop Code'; + CustomerNotExistingAsCompanyOrCustomerLbl: Label 'Customer not existing as Shopify company or customer.'; + PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; + CustomerNoIsDefaultCustomerNoLbl: Label 'Customer No. is the default customer no. from Shopify shop.'; + CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; begin ShopifyCompany.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCompany.IsEmpty() then begin ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCustomer.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistingAsCompanyOrCustomerLbl); + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistingAsCompanyOrCustomerLbl, Shop); exit(false); end; end; if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code")); + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); exit(false); end; if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl); + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); exit(false); end; if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code)); + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); exit(false); end; @@ -154,10 +154,15 @@ codeunit 30362 "Shpfy Posted Invoice Export" local procedure CheckSalesInvoiceHeaderLines(SalesInvoiceHeader: Record "Sales Invoice Header"): Boolean var SalesInvoiceLine: Record "Sales Invoice Line"; + NoLinesInSalesInvoiceLbl: Label 'No lines in sales invoice.'; + InvalidQuantityLbl: Label 'Invalid quantity in sales invoice line.'; + CommentLineLbl: Label 'Comment line in sales invoice.'; begin SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); - if SalesInvoiceLine.IsEmpty() then + if SalesInvoiceLine.IsEmpty() then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); exit(false); + end; SalesInvoiceLine.Reset(); @@ -165,11 +170,14 @@ codeunit 30362 "Shpfy Posted Invoice Export" SalesInvoiceLine.SetRange(Type, SalesInvoiceLine.Type::Item); if SalesInvoiceLine.FindSet() then repeat - if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then + if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); exit(false); + end; if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then - exit(false); + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, CommentLineLbl, Shop); + exit(false); until SalesInvoiceLine.Next() = 0; exit(true); diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index dd673622ed..4401c9af1d 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -1,14 +1,18 @@ namespace Microsoft.Integration.Shopify; +using Microsoft.Integration.Shopify; + codeunit 30168 "Shpfy Skip Record Mgt." { Access = Internal; Permissions = tabledata "Shpfy Skipped Record" = rimd; - internal procedure LogSkippedRecord(ShopifyId: BigInteger; TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]) + internal procedure LogSkippedRecord(ShopifyId: BigInteger; TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") var ShpfySkippedRecord: Record "Shpfy Skipped Record"; begin + if Shop."Logging Mode" = Enum::"Shpfy Logging Mode"::Disabled then + exit; ShpfySkippedRecord.Init(); ShpfySkippedRecord.Validate("Shopify Id", ShopifyId); ShpfySkippedRecord.Validate("Table ID", TableId); diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 0bc8ec07f5..2d9ab2af56 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -357,7 +357,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -404,7 +404,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, 'Price is not synchronized becuse the item is blocked/sales blocked.'); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, 'Price is not synchronized becuse the item is blocked/sales blocked.', Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -553,23 +553,23 @@ codeunit 30178 "Shpfy Product Export" VariantAction: Option " ",Create,Update; ItemIsBlockedLbl: Label 'Item is blocked.'; ItemIsDraftLbl: Label 'Product is draft.'; - ItemIsArchivedLbl: Label 'Product is archived'; + ItemIsArchivedLbl: Label 'Product is archived.'; begin if ShopifyProduct.Get(ProductId) and Item.GetBySystemId(ShopifyProduct."Item SystemId") then begin case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsArchivedLbl); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsArchivedLbl, Shop); exit; end; Shop."Action for Removed Products"::StatusToDraft: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsDraftLbl); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsDraftLbl, Shop); exit; end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsBlockedLbl); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsBlockedLbl, Shop); exit; end; end; From 7deaef56b3dc2b0730755f73c376b7939986d12b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 2 Oct 2024 11:52:08 +0200 Subject: [PATCH 06/32] fixes after testing --- .../Codeunits/ShpfyPostedInvoiceExport.Codeunit.al | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 6c0e5ab5a3..70c40a7464 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -156,7 +156,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" SalesInvoiceLine: Record "Sales Invoice Line"; NoLinesInSalesInvoiceLbl: Label 'No lines in sales invoice.'; InvalidQuantityLbl: Label 'Invalid quantity in sales invoice line.'; - CommentLineLbl: Label 'Comment line in sales invoice.'; + EmptyNoInLineLbl: Label 'No. is empty in Sales Invoice Line.'; begin SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin @@ -175,9 +175,10 @@ codeunit 30362 "Shpfy Posted Invoice Export" exit(false); end; - if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, CommentLineLbl, Shop); - exit(false); + if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then begin + SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); + exit(false); + end; until SalesInvoiceLine.Next() = 0; exit(true); From 34d4c99cd881422084e69fcb310f6aedc46a0e09 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 2 Oct 2024 17:19:49 +0200 Subject: [PATCH 07/32] Add logging to shopify synch shipments to shopify --- .../Codeunits/ShpfyExportShipments.Codeunit.al | 10 ++++++++-- .../Shipping/Reports/ShpfySyncShipmToShopify.Report.al | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index d3e7ea1fff..65a7b35dec 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -40,9 +40,11 @@ codeunit 30190 "Shpfy Export Shipments" ShopifyOrderHeader: Record "Shpfy Order Header"; OrderFulfillments: Codeunit "Shpfy Order Fulfillments"; JsonHelper: Codeunit "Shpfy Json Helper"; + SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; JFulfillment: JsonToken; JResponse: JsonToken; FulfillmentOrderRequest: Text; + NoCoresspondingFulfilmentLbl: Label 'No corresponding fulfillment found.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); @@ -53,10 +55,14 @@ codeunit 30190 "Shpfy Export Shipments" JFulfillment := JsonHelper.GetJsonToken(JResponse, 'data.fulfillmentCreateV2.fulfillment'); if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) - else + else begin + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCoresspondingFulfilmentLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; - end else + end; + end else begin + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCoresspondingFulfilmentLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; + end; SalesShipmentHeader.Modify(true); end; end; diff --git a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al index 436a966454..3c092222c0 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al +++ b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al @@ -31,11 +31,15 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShopifyOrderHeader: Record "Shpfy Order Header"; ShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; + SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + NoLinesApplicable: Label 'No lines applicable for fulfillment.'; + ShopifyOrderNotExistsLbl: Label 'Shopify order %1 does not exist.', Comment = '%1 = Shopify Order Id'; begin ShipmentLine.SetRange("Document No.", "No."); ShipmentLine.SetRange(Type, ShipmentLine.Type::"Item"); ShipmentLine.SetFilter(Quantity, '>0'); if ShipmentLine.IsEmpty() then begin + SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", Database::"Sales Shipment Header", "Sales Shipment Header".RecordId, NoLinesApplicable, Shop); "Shpfy Fulfillment Id" := -2; Modify(); end else @@ -43,7 +47,8 @@ report 30109 "Shpfy Sync Shipm. to Shopify" Shop.Get(ShopifyOrderHeader."Shop Code"); FulfillmentOrdersAPI.GetShopifyFulfillmentOrdersFromShopifyOrder(Shop, "Sales Shipment Header"."Shpfy Order Id"); ExportShipments.CreateShopifyFulfillment("Sales Shipment Header"); - end; + end else + SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", Database::"Sales Shipment Header", "Sales Shipment Header".RecordId, StrSubstNo(ShopifyOrderNotExistsLbl, "Sales Shipment Header"."Shpfy Order Id"), Shop); end; } } From 6417191eeda3c5059d7c8f4545987ddc340de749 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 09:55:01 +0200 Subject: [PATCH 08/32] Remove development code, add summaries --- .../Codeunits/ShpfyAuthenticationMgt.Codeunit.al | 4 ---- .../app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al | 8 ++++++++ .../app/src/Logs/Tables/ShpfySkippedRecord.Table.al | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al index eaa309953f..d57fc3c1be 100644 --- a/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Integration/Codeunits/ShpfyAuthenticationMgt.Codeunit.al @@ -33,8 +33,6 @@ codeunit 30199 "Shpfy Authentication Mgt." EnvironmentInformation: Codeunit "Environment Information"; ClientId: SecretText; begin - exit(SecretText.SecretStrSubstNo('ff3cdb3a6a4fe97dbd9219e32a9594f3')); - if not EnvironmentInformation.IsSaaS() then Error(NotSupportedOnPremErr); @@ -51,8 +49,6 @@ codeunit 30199 "Shpfy Authentication Mgt." EnvironmentInformation: Codeunit "Environment Information"; ClientSecret: SecretText; begin - exit(SecretText.SecretStrSubstNo('96fa169b584920fe01183a02ffd00d7f')); - if not EnvironmentInformation.IsSaaS() then Error(NotSupportedOnPremErr); diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index 4401c9af1d..50a5269ac8 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -7,6 +7,14 @@ codeunit 30168 "Shpfy Skip Record Mgt." Access = Internal; Permissions = tabledata "Shpfy Skipped Record" = rimd; + /// + /// Creates log entry for skipped record. + /// + /// Related Shopify Id of the record. + /// Table Id of the record. + /// Record Id of the record. + /// Reason for skipping the record. + /// Shop record. internal procedure LogSkippedRecord(ShopifyId: BigInteger; TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") var ShpfySkippedRecord: Record "Shpfy Skipped Record"; diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index d964f213de..a459b3fcbb 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -43,7 +43,7 @@ table 30159 "Shpfy Skipped Record" field(5; "Record ID"; RecordID) { Caption = 'Record ID'; - DataClassification = CustomerContent; + DataClassification = SystemMetadata; trigger OnValidate() begin @@ -90,7 +90,7 @@ table 30159 "Shpfy Skipped Record" exit(AllObjWithCaption."Object Caption"); end; - procedure GetRecDescription() Result: Text + local procedure GetRecDescription() Result: Text var RecRef: RecordRef; PKFilter: Text; @@ -111,6 +111,9 @@ table 30159 "Shpfy Skipped Record" end; end; + /// + /// Show related record from Record ID field. + /// internal procedure ShowPage() var TableMetadata: Record "Table Metadata"; From 2f950bbc220734681b660b1053d1add7047c2eca Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 09:58:13 +0200 Subject: [PATCH 09/32] fix/add summary --- .../app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al | 5 +++-- .../Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index 50a5269ac8..6fb364bc46 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -1,7 +1,8 @@ namespace Microsoft.Integration.Shopify; -using Microsoft.Integration.Shopify; - +/// +/// Codeunit Shpfy Skip Record Mgt. (ID 30168). +/// codeunit 30168 "Shpfy Skip Record Mgt." { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index b1b2d46856..e0247ed9c7 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -1,7 +1,7 @@ namespace Microsoft.Integration.Shopify; /// -/// Page Shpfy Skipped Records (ID 30119). +/// Page Shpfy Skipped Records (ID 30165). /// page 30165 "Shpfy Skipped Records" { From bb49612bbda0bb50f4d741ef6446ac2f8fd9d65a Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 10:30:32 +0200 Subject: [PATCH 10/32] add skip action --- .../Logs/Pages/ShpfySkippedRecords.Page.al | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index e0247ed9c7..a8fa0c0936 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -69,4 +69,27 @@ page 30165 "Shpfy Skipped Records" } } } + + actions + { + area(Promoted) + { + actionref(Show_Promoted; Show) { } + } + area(Processing) + { + action(Show) + { + ApplicationArea = All; + Caption = 'Show record'; + Image = View; + ToolTip = 'Show the details of the selected record.'; + + trigger OnAction() + begin + Rec.ShowPage(); + end; + } + } + } } \ No newline at end of file From 259b6743357da1df2a6e58ec4290c3ea5e95bc4d Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 10:37:29 +0200 Subject: [PATCH 11/32] change text to label variable --- .../app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 2d9ab2af56..9e1ebe5b1c 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -399,12 +399,14 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record "Item Variant". /// Parameter of type Record "Item Unit of Measure". local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant"; ItemUnitofMeasure: Record "Item Unit of Measure") + var + ItemIsBlockedLbl: Label 'Price is not synchronized becuse the item is blocked/sales blocked.'; begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, 'Price is not synchronized becuse the item is blocked/sales blocked.', Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, ItemIsBlockedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); From c704dc4bac2316941294a310b0f654c0255726ad Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 3 Oct 2024 10:41:41 +0200 Subject: [PATCH 12/32] fix label --- .../app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 9e1ebe5b1c..40d969781e 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -351,7 +351,7 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record "Item Variant". local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant") var - ItemIsBlockedLbl: Label 'Item is blocked/sales blocked'; + ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then @@ -400,7 +400,7 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record "Item Unit of Measure". local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant"; ItemUnitofMeasure: Record "Item Unit of Measure") var - ItemIsBlockedLbl: Label 'Price is not synchronized becuse the item is blocked/sales blocked.'; + ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then From 7772a2924a93c0329f77101f8b8c7791488d46c0 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 7 Oct 2024 20:15:07 +0200 Subject: [PATCH 13/32] create tests for customer logs --- .../Logs/ShpfySkippedRecordLogSub.Codeunit.al | 62 +++++++++++++++ .../ShpfySkippedRecordLogTest.Codeunit.al | 77 +++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al create mode 100644 Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al new file mode 100644 index 0000000000..9c6a5f2ab1 --- /dev/null +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al @@ -0,0 +1,62 @@ +codeunit 139583 "Shpfy Skipped Record Log Sub." +{ + SingleInstance = true; + EventSubscriberInstance = Manual; + + var + ShopifyCustomerId: BigInteger; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] + local procedure OnClientSend(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + begin + MakeResponse(HttpRequestMessage, HttpResponseMessage); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnGetContent', '', true, false)] + local procedure OnGetContent(HttpResponseMessage: HttpResponseMessage; var Response: Text) + begin + HttpResponseMessage.Content.ReadAs(Response); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Customer Events", OnBeforeFindMapping, '', true, false)] + local procedure OnBeforeFindMapping(var Handled: Boolean; var ShopifyCustomer: Record "Shpfy Customer") + begin + ShopifyCustomer.Id := ShopifyCustomerId; + Handled := true; + end; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + GraphQLCmdMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; + GraphQLCmdTxt: Label '/graphql.json', Locked = true; + begin + case HttpRequestMessage.Method of + 'POST': + begin + Uri := HttpRequestMessage.GetRequestUri(); + if Uri.EndsWith(GraphQLCmdTxt) then + if HttpRequestMessage.Content.ReadAs(GraphQlQuery) then + if GraphQlQuery.Contains(GraphQLCmdMsg) then + HttpResponseMessage := GetResult(); + end; + end; + end; + + local procedure GetResult(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure SetShopifyCustomerId(Id: BigInteger) + begin + ShopifyCustomerId := Id; + end; + +} diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al new file mode 100644 index 0000000000..f0a363aad3 --- /dev/null +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -0,0 +1,77 @@ +codeunit 139581 "Shpfy Skipped Record Log Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + LibraryAssert: Codeunit "Library Assert"; + ShpfySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + EmptyCustomerIdsTok: Label '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }', Locked = true; + + [Test] + procedure UnitTestLogEmptyCustomerEmail() + var + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + SkippedRecord: Record "Shpfy Skipped Record"; + ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + begin + // [SCENARIO] Log skipped record when customer email is empty on customer export to shopify. + // [GIVEN] A customer record with empty email. + Shop := ShpfyInitializeTest.CreateShop(); + Customer := ShpfyInitializeTest.GetDummyCustomer(); + Customer."E-Mail" := ''; + Customer.Modify(false); + Customer.SetRange("No.", Customer."No."); + // [WHEN] Invoke Shopify Customer Export + BindSubscription(ShpfySkippedRecordLogSub); + ShpfySkippedRecordLogSub.SetShopifyCustomerId(0); + ShpfyCustomerExport.SetShop(Shop); + ShpfyCustomerExport.SetCreateCustomers(true); + ShpfyCustomerExport.Run(Customer); + UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Customer.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogCustomerForSameEmailExist() + var + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShpfyCustomer: Record "Shpfy Customer"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibraryRandom: Codeunit "Library - Random"; + ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + SkippedRecord: Record "Shpfy Skipped Record"; + CustomerId: BigInteger; + begin + // [SCENARIO] Log skipped record when customer with same email already exist on customer export to shopify. + // [GIVEN] A customer record with email that already exist in shopify. + Shop := ShpfyInitializeTest.CreateShop(); + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify customer with random guid. + CustomerInitTest.CreateShopifyCustomer(ShpfyCustomer); + ShpfyCustomer."Customer SystemId" := CreateGuid(); + // [GIVEN] Shop with + Shop."Can Update Shopify Customer" := true; + Shop.Modify(false); + // [WHEN] Invoke Shopify Customer Export + BindSubscription(ShpfySkippedRecordLogSub); + ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomer.Id); + ShpfyCustomerExport.SetShop(Shop); + ShpfyCustomerExport.SetCreateCustomers(true); + ShpfyCustomerExport.Run(Customer); + UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Customer.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + end; + + +} From 092bdc6321a41ddea459a1cb1628863e2a7eba1f Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 7 Oct 2024 20:15:33 +0200 Subject: [PATCH 14/32] fix typo --- .../src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 65a7b35dec..f8b88d2e24 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -44,7 +44,7 @@ codeunit 30190 "Shpfy Export Shipments" JFulfillment: JsonToken; JResponse: JsonToken; FulfillmentOrderRequest: Text; - NoCoresspondingFulfilmentLbl: Label 'No corresponding fulfillment found.'; + NoCorespondingFulfilmentLbl: Label 'No corresponding fulfillment found.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); @@ -56,11 +56,11 @@ codeunit 30190 "Shpfy Export Shipments" if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCoresspondingFulfilmentLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; end else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCoresspondingFulfilmentLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; SalesShipmentHeader.Modify(true); From 7b4b8faa514b57dfc2a0b845f3fa82acce1d45b9 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 8 Oct 2024 17:49:38 +0200 Subject: [PATCH 15/32] add product tests --- .../Logs/ShpfySkippedRecordLogSub.Codeunit.al | 41 +++- .../ShpfySkippedRecordLogTest.Codeunit.al | 204 +++++++++++++++++- 2 files changed, 240 insertions(+), 5 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al index 9c6a5f2ab1..2039aec2c7 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al @@ -29,7 +29,11 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." var Uri: Text; GraphQlQuery: Text; - GraphQLCmdMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; + GetCustomersGQLMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; + GetProductMetafieldsGQLStartMsg: Label '{"query":"{product(id: \"gid://shopify/Product/', Locked = true; + GetProductMetafieldsGQLEndMsg: Label '\") { metafields(first: 50) {edges{node{legacyResourceId updatedAt}}}}}"}', Locked = true; + GetVariantMetafieldsGQLStartMsg: Label '{"query":"{productVariant(id: \"gid://shopify/ProductVariant/', Locked = true; + GetVariantMetafieldGQLEndMsg: Label '\") { metafields(first: 50) {edges{ node{legacyResourceId updatedAt}}}}}"}', Locked = true; GraphQLCmdTxt: Label '/graphql.json', Locked = true; begin case HttpRequestMessage.Method of @@ -38,13 +42,30 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." Uri := HttpRequestMessage.GetRequestUri(); if Uri.EndsWith(GraphQLCmdTxt) then if HttpRequestMessage.Content.ReadAs(GraphQlQuery) then - if GraphQlQuery.Contains(GraphQLCmdMsg) then - HttpResponseMessage := GetResult(); + case true of + GraphQlQuery.Contains(GetCustomersGQLMsg): + HttpResponseMessage := GetCustomersResult(); + GraphQlQuery.StartsWith(GetProductMetafieldsGQLStartMsg) and GraphQlQuery.EndsWith(GetProductMetafieldsGQLEndMsg): + HttpResponseMessage := GetProductMetafieldsEmptyResult(); + GraphQlQuery.StartsWith(GetVariantMetafieldsGQLStartMsg) and GraphQlQuery.EndsWith(GetVariantMetafieldGQLEndMsg): + HttpResponseMessage := GetVariantMetafieldsEmptyResult(); + + end; end; end; end; - local procedure GetResult(): HttpResponseMessage + local procedure GetCustomersResult(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + local procedure GetProductMetafieldsEmptyResult(): HttpResponseMessage var HttpResponseMessage: HttpResponseMessage; Body: Text; @@ -54,6 +75,18 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." exit(HttpResponseMessage); end; + local procedure GetVariantMetafieldsEmptyResult(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{ "data": { "productVariant": { "metafields": { "edges": [] } } }, "extensions": { "cost": { "requestedQueryCost": 10, "actualQueryCost": 3, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1997, "restoreRate": 100 } } } }'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + + internal procedure SetShopifyCustomerId(Id: BigInteger) begin ShopifyCustomerId := Id; diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index f0a363aad3..ddab60661e 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -5,7 +5,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var LibraryAssert: Codeunit "Library Assert"; - ShpfySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + Any: Codeunit Any; EmptyCustomerIdsTok: Label '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }', Locked = true; [Test] @@ -73,5 +73,207 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); end; + [Test] + procedure UnitTestLogProductItemBlocked() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ShpfyItem: Record "Shpfy Product"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + SkippedRecord: Record "Shpfy Skipped Record"; + begin + // [SCENARIO] Log skipped record when product item is blocked + // [GIVEN] A product item record that is blocked. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop.Modify(false); + Item := ShpfyInitializeTest.GetDummyItem(); + Item."Blocked" := true; + Item.Modify(false); + CreateShpfyProduct(ShpfyItem, Item.SystemId, Shop.Code); + // [WHEN] Invoke Shopify Product Export + ProductExport.SetShop(Shop); + Shop.SetRange("Code", Shop.Code); + ProductExport.Run(Shop); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + end; + [Test] + procedure UnitTestLogProductItemBlockedAndProductArchived() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ShpfyProduct: Record "Shpfy Product"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + SkippedRecord: Record "Shpfy Skipped Record"; + begin + // [SCENARIO] Log skipped record when product item is blocked and product is archived + // [GIVEN] A product item record that is blocked and archived. Shop with action for removed products set to status to archived. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; + Shop.Modify(false); + Item := ShpfyInitializeTest.GetDummyItem(); + Item."Blocked" := true; + Item.Modify(false); + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + ShpfyProduct.Status := Enum::"Shpfy Product Status"::Archived; + ShpfyProduct.Modify(false); + // [WHEN] Invoke Shopify Product Export + ProductExport.SetShop(Shop); + Shop.SetRange("Code", Shop.Code); + ProductExport.Run(Shop); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogProductItemBlockedAndProductIsDraft() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ShpfyProduct: Record "Shpfy Product"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + SkippedRecord: Record "Shpfy Skipped Record"; + begin + // [SCENARIO] Log skipped record when product item is blocked and product is draft + // [GIVEN] A product item record that is blocked and draft. Shop with action for removed products set to status to draft. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToDraft; + Shop.Modify(false); + Item := ShpfyInitializeTest.GetDummyItem(); + Item."Blocked" := true; + Item.Modify(false); + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + ShpfyProduct.Status := Enum::"Shpfy Product Status"::Draft; + ShpfyProduct.Modify(false); + // [WHEN] Invoke Shopify Product Export + BindSubscription(ShpfySkippedRecordLogSub); + ProductExport.SetShop(Shop); + Shop.SetRange("Code", Shop.Code); + ProductExport.Run(Shop); + UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogItemVariantIsIsBlockedAndSalesBlocked() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ItemVariant: Record "Item Variant"; + ShpfyProduct: Record "Shpfy Product"; + ShpfyVariant: Record "Shpfy Variant"; + SkippedRecord: Record "Shpfy Skipped Record"; + ProductInitTest: Codeunit "Shpfy Product Init Test"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + begin + // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked + // [GIVEN] Shop with Sync Prices = true. Item with variants which is blocked and sales blocked. + // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; + Shop.Modify(false); + Item := ProductInitTest.CreateItem(true); + Item.Blocked := true; + Item."Sales Blocked" := true; + Item.Modify(false); + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + // [WHEN] Invoke Shopify Product Export + BindSubscription(SkippedrecordLogSub); + Shop.SetRange("Code", Shop.Code); + ProductExport.SetOnlyUpdatePriceOn(); + ProductExport.Run(Shop); + UnbindSubscription(SkippedrecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogItemVariantIsBlockedAndSalesBlockedWithUnitOfMeasure() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ItemVariant: Record "Item Variant"; + ShpfyProduct: Record "Shpfy Product"; + ShpfyVariant: Record "Shpfy Variant"; + SkippedRecord: Record "Shpfy Skipped Record"; + ItemUnitofMeasure: Record "Item Unit of Measure"; + UnitofMeasure: Record "Unit of Measure"; + ProductInitTest: Codeunit "Shpfy Product Init Test"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + LibraryInventory: Codeunit "Library - Inventory"; + begin + // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop. + // [GIVEN] Shop with UoM as Variant set. Item with variants which is blocked and sales blocked. + // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; + Shop."UoM as Variant" := true; + Shop.Modify(false); + Item := ProductInitTest.CreateItem(true); + Item.Blocked := true; + Item."Sales Blocked" := true; + Item.Modify(false); + + // [GIVEN] Product Variant with UoM set. + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + LibraryInventory.CreateUnitOfMeasureCode(UnitofMeasure); + LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); + ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); + ShpfyVariant.FindFirst(); + ShpfyVariant."UoM Option Id" := 1; + ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; + ShpfyVariant.Modify(false); + // [WHEN] Invoke Shopify Product Export + BindSubscription(SkippedrecordLogSub); + Shop.SetRange("Code", Shop.Code); + ProductExport.SetOnlyUpdatePriceOn(); + ProductExport.Run(Shop); + UnbindSubscription(SkippedrecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + + + + + end; + + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) + var + ShopifyVariant: Record "Shpfy Variant"; + begin + ShopifyProduct.DeleteAll(); + ShopifyProduct.Init(); + ShopifyProduct.Id := Any.IntegerInRange(10000, 999999); + ShopifyProduct."Item SystemId" := ItemSystemId; + ShopifyProduct."Shop Code" := ShopCode; + ShopifyProduct.Insert(); + ShopifyVariant.DeleteAll(); + ShopifyVariant.Init(); + ShopifyVariant.Id := Any.IntegerInRange(10000, 999999); + ShopifyVariant."Product Id" := ShopifyProduct.Id; + ShopifyVariant."Item SystemId" := ItemSystemId; + ShopifyVariant."Shop Code" := ShopCode; + ShopifyVariant.Insert(); + end; } From c284c5253f25390351287c92733976c0e145542b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 9 Oct 2024 13:11:16 +0200 Subject: [PATCH 16/32] add missing product variant tests --- .../ShpfySkippedRecordLogTest.Codeunit.al | 178 +++++++++++++++--- 1 file changed, 157 insertions(+), 21 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index ddab60661e..d6b1bad3fe 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -19,12 +19,14 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when customer email is empty on customer export to shopify. + // [GIVEN] A customer record with empty email. Shop := ShpfyInitializeTest.CreateShop(); Customer := ShpfyInitializeTest.GetDummyCustomer(); Customer."E-Mail" := ''; Customer.Modify(false); Customer.SetRange("No.", Customer."No."); + // [WHEN] Invoke Shopify Customer Export BindSubscription(ShpfySkippedRecordLogSub); ShpfySkippedRecordLogSub.SetShopifyCustomerId(0); @@ -32,9 +34,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfyCustomerExport.SetCreateCustomers(true); ShpfyCustomerExport.Run(Customer); UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -43,15 +46,14 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; Customer: Record Customer; ShpfyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibraryRandom: Codeunit "Library - Random"; ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; - SkippedRecord: Record "Shpfy Skipped Record"; - CustomerId: BigInteger; begin // [SCENARIO] Log skipped record when customer with same email already exist on customer export to shopify. + // [GIVEN] A customer record with email that already exist in shopify. Shop := ShpfyInitializeTest.CreateShop(); Customer := ShpfyInitializeTest.GetDummyCustomer(); @@ -61,6 +63,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Shop with Shop."Can Update Shopify Customer" := true; Shop.Modify(false); + // [WHEN] Invoke Shopify Customer Export BindSubscription(ShpfySkippedRecordLogSub); ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomer.Id); @@ -68,9 +71,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfyCustomerExport.SetCreateCustomers(true); ShpfyCustomerExport.Run(Customer); UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -79,10 +83,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; Item: Record Item; ShpfyItem: Record "Shpfy Product"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; - SkippedRecord: Record "Shpfy Skipped Record"; begin // [SCENARIO] Log skipped record when product item is blocked // [GIVEN] A product item record that is blocked. @@ -93,13 +96,15 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Item."Blocked" := true; Item.Modify(false); CreateShpfyProduct(ShpfyItem, Item.SystemId, Shop.Code); + // [WHEN] Invoke Shopify Product Export ProductExport.SetShop(Shop); Shop.SetRange("Code", Shop.Code); ProductExport.Run(Shop); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -108,9 +113,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; Item: Record Item; ShpfyProduct: Record "Shpfy Product"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - SkippedRecord: Record "Shpfy Skipped Record"; begin // [SCENARIO] Log skipped record when product item is blocked and product is archived // [GIVEN] A product item record that is blocked and archived. Shop with action for removed products set to status to archived. @@ -124,13 +129,15 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); ShpfyProduct.Status := Enum::"Shpfy Product Status"::Archived; ShpfyProduct.Modify(false); + // [WHEN] Invoke Shopify Product Export ProductExport.SetShop(Shop); Shop.SetRange("Code", Shop.Code); ProductExport.Run(Shop); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -139,10 +146,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; Item: Record Item; ShpfyProduct: Record "Shpfy Product"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; - SkippedRecord: Record "Shpfy Skipped Record"; begin // [SCENARIO] Log skipped record when product item is blocked and product is draft // [GIVEN] A product item record that is blocked and draft. Shop with action for removed products set to status to draft. @@ -164,7 +171,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" UnbindSubscription(ShpfySkippedRecordLogSub); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -172,9 +179,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var Shop: Record "Shpfy Shop"; Item: Record Item; - ItemVariant: Record "Item Variant"; ShpfyProduct: Record "Shpfy Product"; - ShpfyVariant: Record "Shpfy Variant"; SkippedRecord: Record "Shpfy Skipped Record"; ProductInitTest: Codeunit "Shpfy Product Init Test"; ProductExport: Codeunit "Shpfy Product Export"; @@ -193,23 +198,24 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Item."Sales Blocked" := true; Item.Modify(false); CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + // [WHEN] Invoke Shopify Product Export BindSubscription(SkippedrecordLogSub); Shop.SetRange("Code", Shop.Code); ProductExport.SetOnlyUpdatePriceOn(); ProductExport.Run(Shop); UnbindSubscription(SkippedrecordLogSub); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] - procedure UnitTestLogItemVariantIsBlockedAndSalesBlockedWithUnitOfMeasure() + procedure UnitTestLogItemIsBlockedAndSalesBlockedWithUnitOfMeasureAsUoMOptionId() var Shop: Record "Shpfy Shop"; Item: Record Item; - ItemVariant: Record "Item Variant"; ShpfyProduct: Record "Shpfy Product"; ShpfyVariant: Record "Shpfy Variant"; SkippedRecord: Record "Shpfy Skipped Record"; @@ -221,7 +227,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; LibraryInventory: Codeunit "Library - Inventory"; begin - // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop. + // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop as UoM Option ID. // [GIVEN] Shop with UoM as Variant set. Item with variants which is blocked and sales blocked. // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. Shop := ShpfyInitializeTest.CreateShop(); @@ -229,35 +235,158 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; Shop."UoM as Variant" := true; Shop.Modify(false); - Item := ProductInitTest.CreateItem(true); + // [GIVEN] Item with blocked and sales blocked. + Item := ProductInitTest.CreateItem(false); Item.Blocked := true; Item."Sales Blocked" := true; Item.Modify(false); - - // [GIVEN] Product Variant with UoM set. - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + // [GIVEN] Unit of Measure and Item Unit of Measure. LibraryInventory.CreateUnitOfMeasureCode(UnitofMeasure); LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); + // [GIVEN] Product Variant with UoM and UomM Option Id set. + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); ShpfyVariant.FindFirst(); ShpfyVariant."UoM Option Id" := 1; ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; ShpfyVariant.Modify(false); + // [WHEN] Invoke Shopify Product Export BindSubscription(SkippedrecordLogSub); Shop.SetRange("Code", Shop.Code); ProductExport.SetOnlyUpdatePriceOn(); ProductExport.Run(Shop); UnbindSubscription(SkippedrecordLogSub); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + [Test] + procedure UnitTestLogItemVariantIsBlockedAndSalesBlockedWithUnitOfMeasureSetOnVariantOptions() + var + Shop: Record "Shpfy Shop"; + Item: Record Item; + ShpfyProduct: Record "Shpfy Product"; + ShpfyVariant: Record "Shpfy Variant"; + SkippedRecord: Record "Shpfy Skipped Record"; + ItemUnitofMeasure: Record "Item Unit of Measure"; + UnitofMeasure: Record "Unit of Measure"; + ProductInitTest: Codeunit "Shpfy Product Init Test"; + ProductExport: Codeunit "Shpfy Product Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + LibraryInventory: Codeunit "Library - Inventory"; + begin + // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop. + // [GIVEN] Shop with UoM as Variant and Option name for UoM set. Item with variants which is blocked and sales blocked. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Products" := true; + Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; + Shop."UoM as Variant" := true; + Shop."Option Name for UoM" := Any.AlphanumericText(MaxStrLen(Shop."Option Name for UoM")); + Shop.Modify(false); + // [GIVEN] Item with blocked and sales blocked. + Item := ProductInitTest.CreateItem(false); + Item.Blocked := true; + Item."Sales Blocked" := true; + Item.Modify(false); + // [GIVEN] Unit of Measure and Item Unit of Measure. + LibraryInventory.CreateUnitOfMeasureCode(UnitofMeasure); + LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); + // [GIVEN] Product Variant with UoM and UoM Option name set as in shop. + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); + ShpfyVariant.FindFirst(); + ShpfyVariant."Option 1 Name" := Shop."Option Name for UoM"; + ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; + ShpfyVariant.Modify(false); + // [WHEN] Invoke Shopify Product Export + BindSubscription(SkippedrecordLogSub); + Shop.SetRange("Code", Shop.Code); + ProductExport.SetOnlyUpdatePriceOn(); + ProductExport.Run(Shop); + UnbindSubscription(SkippedrecordLogSub); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", Item.RecordId); + LibraryAssert.AreEqual(2, SkippedRecord.Count(), 'Skipped record is not created'); //Two recrds are created because its not possible to omit one with Shop."UoM as Variant" := true; end; + [Test] + procedure UnitTestLogSalesInvoiceWithNotExistingShopifyCustomer() + var + Customer: Record Customer; + SalesInvoiceHeader: Record "Sales Invoice Header"; + Shop: Record "Shpfy Shop"; + SkippedRecord: Record "Shpfy Skipped Record"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with not existing shopify customer. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + LibrarySales.CreateCustomer(Customer); + // [GIVEN] Sales Invoice + CreateSalesInvoice(SalesInvoiceHeader, Customer."No."); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogSalesInvoiceWithNotExistingShopifyPaymentTerms() + var + Customer: Record Customer; + SalesInvoiceHeader: Record "Sales Invoice Header"; + Shop: Record "Shpfy Shop"; + SkippedRecord: Record "Shpfy Skipped Record"; + ShopifyCustomer: Record "Shpfy Customer"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with not existing shopify payment terms. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Sales Invoice + CreateSalesInvoice(SalesInvoiceHeader, Customer."No."); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + + + + + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) var ShopifyVariant: Record "Shpfy Variant"; @@ -276,4 +405,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyVariant."Shop Code" := ShopCode; ShopifyVariant.Insert(); end; + + local procedure CreateSalesInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]) + begin + SalesInvoiceHeader.Init(); + SalesInvoiceHeader."Sell-to Customer No." := CustomerNo; + SalesInvoiceHeader.Insert(false); + end; } From b83ec4361275046b4b45117897b265138fdde581 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 9 Oct 2024 17:00:51 +0200 Subject: [PATCH 17/32] add invoice tests and shipment tests --- .../ShpfySkippedRecordLogTest.Codeunit.al | 370 +++++++++++++++++- 1 file changed, 362 insertions(+), 8 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index d6b1bad3fe..6890db50b2 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -6,6 +6,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var LibraryAssert: Codeunit "Library Assert"; Any: Codeunit Any; + SalesShipmentNo: Code[20]; EmptyCustomerIdsTok: Label '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }', Locked = true; [Test] @@ -104,7 +105,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsTrue(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; [Test] @@ -246,6 +247,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); // [GIVEN] Product Variant with UoM and UomM Option Id set. CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); ShpfyVariant.FindFirst(); ShpfyVariant."UoM Option Id" := 1; ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; @@ -336,7 +338,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Customer LibrarySales.CreateCustomer(Customer); // [GIVEN] Sales Invoice - CreateSalesInvoice(SalesInvoiceHeader, Customer."No."); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); @@ -372,7 +374,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Sales Invoice - CreateSalesInvoice(SalesInvoiceHeader, Customer."No."); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); @@ -382,34 +384,386 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; + [Test] + procedure UnitTestLogSalesInvoiceWithCustomerNoIsDefaultCustomerNo() + var + SalesInvoiceHeader: Record "Sales Invoice Header"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryPaymentFormat: Codeunit "Library - Payment Format"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with customer no which is default shopify shop customer no. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Shop with default customer no set. + Shop."Default Customer No." := Customer."No."; + Shop.Modify(false); + // [GIVEN] Sales Invoice for default customer no. + CreateSalesInvoiceHeader(SalesInvoiceHeader, Shop."Default Customer No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + end; + + [Test] + procedure UnitTestLogSalesInvoiceWithCustomerNoUsedInShopifyCustomerTemplates() + var + SalesInvoiceHeader: Record "Sales Invoice Header"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + ShopifyCustomerTemplate: Record "Shpfy Customer Template"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryPaymentFormat: Codeunit "Library - Payment Format"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with customer no which is used in shopify customer templates. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Shopify Customer Template with customer no. + ShopifyCustomerTemplate.Init(); + ShopifyCustomerTemplate."Shop Code" := Shop.Code; + ShopifyCustomerTemplate."Default Customer No." := Customer."No."; + ShopifyCustomerTemplate.Insert(false); + // [GIVEN] Sales Invoice for default customer no. + CreateSalesInvoiceHeader(SalesInvoiceHeader, ShopifyCustomerTemplate."Default Customer No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + end; + + [Test] + procedure UnitTestLogSalesInvoiceWithoutSalesLine() + var + SalesInvoiceHeader: Record "Sales Invoice Header"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryPaymentFormat: Codeunit "Library - Payment Format"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + PaymentTermsCode: Code[10]; + LibraryRandom: Codeunit "Library - Random"; + begin + // [SCENARIO] Log skipped record when sales invoice is exported without sales line. + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Sales Invoice without sales line. + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + end; + [Test] + procedure UnitTestLogSalesInvoiceWithSalesLineWithDecimalQuantity() + var + SalesInvoiceHeader: Record "Sales Invoice Header"; + SalesInvoiceLine: Record "Sales Invoice Line"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryRandom: Codeunit "Library - Random"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with sales line with decimal quantity. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Sales Invoice with sales line with decimal quantity. + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", LibraryRandom.RandDecInDecimalRange(0.01, 0.99, 2), Any.AlphanumericText(20)); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + procedure UnitTestLogSalesInvoiceWithSalesLineWithEmptyNoField() + var + SalesInvoiceHeader: Record "Sales Invoice Header"; + SalesInvoiceLine: Record "Sales Invoice Line"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryRandom: Codeunit "Library - Random"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales invoice is exported with sales line with empty No field. + + // [GIVEN] Shop with setup Posted Invoice Sync = true. + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Posted Invoice Sync" := true; + Shop.Modify(false); + // [GIVEN] Customer + Customer := ShpfyInitializeTest.GetDummyCustomer(); + // [GIVEN] Shopify Customer + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Sales Invoice with sales line with empty No field. + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", Any.IntegerInRange(100), ''); + + // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + [HandlerFunctions('SyncPostedShipmentsToShopify')] + procedure UnitTestLogSalesShipmentWithoutShipmentLines() + var + SalesShipmentHeader: Record "Sales Shipment Header"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryRandom: Codeunit "Library - Random"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + SyncShipmentToShopify: Report "Shpfy Sync Shipm. to Shopify"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales shipment is exported without shipment lines. + + // [GIVEN] Shop + Shop := ShpfyInitializeTest.CreateShop(); + // [GIVEN] Posted shipment without lines. + CreateSalesShipmentHeader(SalesShipmentHeader); + SalesShipmentNo := SalesShipmentHeader."No."; + Commit(); + + // [WHEN] Invoke Shopify Sync Shipment to Shopify + Report.Run(Report::"Shpfy Sync Shipm. to Shopify"); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + [HandlerFunctions('SyncPostedShipmentsToShopify')] + procedure UnitTestLogSalesShipmentWithNotExistingShopifyOrder() + var + SalesShipmentHeader: Record "Sales Shipment Header"; + SalesShipmentLine: Record "Sales Shipment Line"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryRandom: Codeunit "Library - Random"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + SyncShipmentToShopify: Report "Shpfy Sync Shipm. to Shopify"; + PaymentTermsCode: Code[10]; + begin + // [SCENARIO] Log skipped record when sales shipment is exported with not existing shopify order. + + // [GIVEN] Shop + Shop := ShpfyInitializeTest.CreateShop(); + // [GIVEN] Posted shipment with line. + CreateSalesShipmentHeader(SalesShipmentHeader); + SalesShipmentNo := SalesShipmentHeader."No."; + SalesShipmentLine.Init(); + SalesShipmentLine."Document No." := SalesShipmentHeader."No."; + SalesShipmentLine."Line No." := 10000; + SalesShipmentLine.Type := SalesShipmentLine.Type::Item; + SalesShipmentLine."No." := Any.AlphanumericText(20); + SalesShipmentLine.Quantity := Any.IntegerInRange(1, 100); + SalesShipmentLine.Insert(false); + Commit(); + + // [WHEN] Invoke Shopify Sync Shipment to Shopify + Report.Run(Report::"Shpfy Sync Shipm. to Shopify"); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + + [Test] + procedure LogSalesShipmentNoCorrespondingFulfillmentWithFailedResponse() + var + SalesShipmentHeader: Record "Sales Shipment Header"; + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + SkippedRecord: Record "Shpfy Skipped Record"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + LibrarySales: Codeunit "Library - Sales"; + LibraryRandom: Codeunit "Library - Random"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + SyncShipmentToShopify: Codeunit "Shpfy Export Shipments"; + PaymentTermsCode: Code[10]; + begin + + end; local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) var ShopifyVariant: Record "Shpfy Variant"; begin - ShopifyProduct.DeleteAll(); + ShopifyProduct.DeleteAll(false); ShopifyProduct.Init(); ShopifyProduct.Id := Any.IntegerInRange(10000, 999999); ShopifyProduct."Item SystemId" := ItemSystemId; ShopifyProduct."Shop Code" := ShopCode; - ShopifyProduct.Insert(); - ShopifyVariant.DeleteAll(); + ShopifyProduct.Insert(false); + ShopifyVariant.DeleteAll(false); ShopifyVariant.Init(); ShopifyVariant.Id := Any.IntegerInRange(10000, 999999); ShopifyVariant."Product Id" := ShopifyProduct.Id; ShopifyVariant."Item SystemId" := ItemSystemId; ShopifyVariant."Shop Code" := ShopCode; - ShopifyVariant.Insert(); + ShopifyVariant.Insert(false); end; - local procedure CreateSalesInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]) + local procedure CreateSalesInvoiceHeader(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]) begin SalesInvoiceHeader.Init(); + SalesInvoiceHeader."No." := Any.AlphanumericText(20); SalesInvoiceHeader."Sell-to Customer No." := CustomerNo; SalesInvoiceHeader.Insert(false); end; + + local procedure CreatePaymentTerms(): Code[10] + var + PaymentTerms: Record "Payment Terms"; + ShopifyPaymentTerms: Record "Shpfy Payment Terms"; + begin + PaymentTerms.DeleteAll(false); + ShopifyPaymentTerms.DeleteAll(false); + PaymentTerms.Init(); + PaymentTerms.Code := Any.AlphanumericText(10); + PaymentTerms.Insert(false); + ShopifyPaymentTerms.Init(); + ShopifyPaymentTerms."Payment Terms Code" := PaymentTerms.Code; + ShopifyPaymentTerms."Is Primary" := true; + ShopifyPaymentTerms.Insert(false); + exit(PaymentTerms.Code); + end; + + local procedure CreateSalesInvoiceLine(SalesInvoiceLine: Record "Sales Invoice Line"; DocumentNo: Code[20]; Quantity: Decimal; No: Text) + begin + SalesInvoiceLine.Init(); + SalesInvoiceLine."Document No." := DocumentNo; + SalesInvoiceLine.Type := SalesInvoiceLine.Type::Item; + SalesInvoiceLine."No." := No; + SalesInvoiceLine.Quantity := Quantity; + SalesInvoiceLine.Insert(false); + end; + + local procedure CreateSalesShipmentHeader(var SalesShipmentHeader: Record "Sales Shipment Header") + begin + SalesShipmentHeader.Init(); + SalesShipmentHeader."No." := Any.AlphanumericText(20); + SalesShipmentHeader."Shpfy Order Id" := Any.IntegerInRange(10000, 999999); + SalesShipmentHeader.Insert(false); + end; + + [RequestPageHandler] + procedure SyncPostedShipmentsToShopify(var SyncShipmToShopify: TestRequestPage "Shpfy Sync Shipm. to Shopify") + begin + SyncShipmToShopify."Sales Shipment Header".SetFilter("No.", SalesShipmentNo); + SyncShipmToShopify.OK().Invoke(); + end; } From b8246a573b859321a3e0225a2581f7c6463ae3d8 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 9 Oct 2024 17:38:56 +0200 Subject: [PATCH 18/32] add shipment export test --- .../ShpfySkippedRecordLogTest.Codeunit.al | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 6890db50b2..d74d55ceb3 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -627,7 +627,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); // [GIVEN] Posted shipment without lines. - CreateSalesShipmentHeader(SalesShipmentHeader); + CreateSalesShipmentHeader(SalesShipmentHeader, Any.IntegerInRange(10000, 999999)); SalesShipmentNo := SalesShipmentHeader."No."; Commit(); @@ -661,7 +661,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); // [GIVEN] Posted shipment with line. - CreateSalesShipmentHeader(SalesShipmentHeader); + CreateSalesShipmentHeader(SalesShipmentHeader, Any.IntegerInRange(10000, 999999)); SalesShipmentNo := SalesShipmentHeader."No."; SalesShipmentLine.Init(); SalesShipmentLine."Document No." := SalesShipmentHeader."No."; @@ -684,7 +684,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure LogSalesShipmentNoCorrespondingFulfillmentWithFailedResponse() var SalesShipmentHeader: Record "Sales Shipment Header"; + SalesShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; + ShopifyOrderHeader: Record "Shpfy Order Header"; + ShopifyOrderLine: Record "Shpfy Order Line"; Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; @@ -692,10 +695,43 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibrarySales: Codeunit "Library - Sales"; LibraryRandom: Codeunit "Library - Random"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - SyncShipmentToShopify: Codeunit "Shpfy Export Shipments"; + ExportShipments: Codeunit "Shpfy Export Shipments"; PaymentTermsCode: Code[10]; begin + // [SCENARIO] Log skipped record when sales shipment is exported with failed fulfillment response from shopify. + + // [GIVEN] Shop + Shop := ShpfyInitializeTest.CreateShop(); + // [GIVEN] Shopify order with line + ShopifyOrderHeader.Init(); + ShopifyOrderHeader."Shop Code" := Shop.Code; + ShopifyOrderHeader."Shopify Order Id" := Any.IntegerInRange(10000, 999999); + ShopifyOrderHeader.Insert(false); + + ShopifyOrderLine.Init(); + ShopifyOrderLine."Shopify Order Id" := ShopifyOrderHeader."Shopify Order Id"; + ShopifyOrderLine."Line Id" := Any.IntegerInRange(10000, 999999); + ShopifyOrderLine.Quantity := Any.IntegerInRange(1, 100); + ShopifyOrderLine.Insert(false); + + // [GIVEN] Posted shipment with line. + CreateSalesShipmentHeader(SalesShipmentHeader, ShopifyOrderHeader."Shopify Order Id"); + SalesShipmentLine.Init(); + SalesShipmentLine."Document No." := SalesShipmentHeader."No."; + SalesShipmentLine."Line No." := 10000; + SalesShipmentLine.Type := SalesShipmentLine.Type::Item; + SalesShipmentLine."No." := Any.AlphanumericText(20); + SalesShipmentLine.Quantity := ShopifyOrderLine.Quantity; + SalesShipmentLine."Shpfy Order Line Id" := ShopifyOrderLine."Line Id"; + SalesShipmentLine.Insert(false); + Commit(); + // [WHEN] Invoke Shopify Sync Shipment to Shopify + ExportShipments.CreateShopifyFulfillment(SalesShipmentHeader); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) @@ -752,11 +788,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesInvoiceLine.Insert(false); end; - local procedure CreateSalesShipmentHeader(var SalesShipmentHeader: Record "Sales Shipment Header") + local procedure CreateSalesShipmentHeader(var SalesShipmentHeader: Record "Sales Shipment Header"; ShpfyOrderId: BigInteger) begin SalesShipmentHeader.Init(); SalesShipmentHeader."No." := Any.AlphanumericText(20); - SalesShipmentHeader."Shpfy Order Id" := Any.IntegerInRange(10000, 999999); + SalesShipmentHeader."Shpfy Order Id" := ShpfyOrderId; SalesShipmentHeader.Insert(false); end; From f5d5da917f0f2df3ef61169d95e47b891d3e1c29 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 9 Oct 2024 21:00:49 +0200 Subject: [PATCH 19/32] Add fulfillment test --- .../ShpfyExportShipments.Codeunit.al | 7 ++-- .../Logs/ShpfySkippedRecordLogSub.Codeunit.al | 14 ++++++- .../ShpfySkippedRecordLogTest.Codeunit.al | 38 +++++++++++++++++++ .../Shipping/ShpfyShippingTest.Codeunit.al | 6 +-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index f8b88d2e24..4c9c49936a 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -44,7 +44,8 @@ codeunit 30190 "Shpfy Export Shipments" JFulfillment: JsonToken; JResponse: JsonToken; FulfillmentOrderRequest: Text; - NoCorespondingFulfilmentLbl: Label 'No corresponding fulfillment found.'; + NoCorespondingFulfilmentLinesLbl: Label 'No corresponding fulfillment lines found.'; + NoFullfilmentFoundInShopifyLbl: Label 'Fullfilment was not created in Shopify.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); @@ -56,11 +57,11 @@ codeunit 30190 "Shpfy Export Shipments" if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoFullfilmentFoundInShopifyLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; end else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLinesLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; SalesShipmentHeader.Modify(true); diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al index 2039aec2c7..376cc2ab64 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al @@ -34,6 +34,7 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." GetProductMetafieldsGQLEndMsg: Label '\") { metafields(first: 50) {edges{node{legacyResourceId updatedAt}}}}}"}', Locked = true; GetVariantMetafieldsGQLStartMsg: Label '{"query":"{productVariant(id: \"gid://shopify/ProductVariant/', Locked = true; GetVariantMetafieldGQLEndMsg: Label '\") { metafields(first: 50) {edges{ node{legacyResourceId updatedAt}}}}}"}', Locked = true; + CreateFulfimentGQLStartMsg: Label '{"query": "mutation {fulfillmentCreateV2( fulfillment: {notifyCustomer: true, trackingInfo: {number: ', Locked = true; GraphQLCmdTxt: Label '/graphql.json', Locked = true; begin case HttpRequestMessage.Method of @@ -49,7 +50,8 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." HttpResponseMessage := GetProductMetafieldsEmptyResult(); GraphQlQuery.StartsWith(GetVariantMetafieldsGQLStartMsg) and GraphQlQuery.EndsWith(GetVariantMetafieldGQLEndMsg): HttpResponseMessage := GetVariantMetafieldsEmptyResult(); - + GraphQlQuery.StartsWith(CreateFulfimentGQLStartMsg): + HttpResponseMessage := GetCreateFulfilmentFailedResult(); end; end; end; @@ -85,7 +87,15 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." exit(HttpResponseMessage); end; - + local procedure GetCreateFulfilmentFailedResult(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{ "data": { "fulfillmentCreateV2": { "fulfillment": null, "userErrors": [ { "field": [ "fulfillment" ], "message": "Fulfillment order does not exist." } ] } }, "extensions": { "cost": { "requestedQueryCost": 24, "actualQueryCost": 10, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1990, "restoreRate": 100 } } } }'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; internal procedure SetShopifyCustomerId(Id: BigInteger) begin diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index d74d55ceb3..6308e87d56 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -734,6 +734,44 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; + [Test] + procedure LogSalesShipmentNoFulfilmentCreatedInSHopify() + var + SalesShipmentHeader: Record "Sales Shipment Header"; + Shop: Record "Shpfy Shop"; + SkippedRecord: Record "Shpfy Skipped Record"; + ExportShipments: Codeunit "Shpfy Export Shipments"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShippingTest: Codeunit "Shpfy Shipping Test"; + SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + ShopifyOrderId: BigInteger; + ShopifyOrderHeader: Record "Shpfy Order Header"; + LocationId: BigInteger; + DeliveryMethodType: Enum "Shpfy Delivery Method Type"; + begin + // [SCENARIO] Log skipped record when sales shipment is exported with no fulfillment created in shopify. + + // [GIVEN] Sales shipment, shopify order and shopify fulfilment + Shop := ShpfyInitializeTest.CreateShop(); + ShopifyOrderId := Any.IntegerInRange(10000, 999999); + DeliveryMethodType := DeliveryMethodType::" "; + ShopifyOrderId := ShippingTest.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); + ShopifyOrderHeader.Get(ShopifyOrderId); + ShopifyOrderHeader."Shop Code" := Shop.Code; + ShopifyOrderHeader.Modify(false); + ShippingTest.CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); + ShippingTest.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); + + // [WHEN] Invoke Shopify Sync Shipment to Shopify + BindSubscription(SkippedRecordLogSub); + ExportShipments.CreateShopifyFulfillment(SalesShipmentHeader); + UnbindSubscription(SkippedRecordLogSub); + + // [THEN] Related record is created in shopify skipped record table. + SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); + LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + end; + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) var ShopifyVariant: Record "Shpfy Variant"; diff --git a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al index 578e420c0a..ad1338d0a7 100644 --- a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al @@ -49,7 +49,7 @@ codeunit 139606 "Shpfy Shipping Test" end; end; - local procedure CreateRandomShopifyOrder(LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger + internal procedure CreateRandomShopifyOrder(LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger var OrderHeader: Record "Shpfy Order Header"; OrderLine: Record "Shpfy Order Line"; @@ -71,7 +71,7 @@ codeunit 139606 "Shpfy Shipping Test" exit(OrderHeader."Shopify Order Id"); end; - local procedure CreateShopifyFulfillmentOrder(ShopifyOrderId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger + internal procedure CreateShopifyFulfillmentOrder(ShopifyOrderId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger var OrderLine: Record "Shpfy Order Line"; FulfillmentOrderHeader: Record "Shpfy FulFillment Order Header"; @@ -102,7 +102,7 @@ codeunit 139606 "Shpfy Shipping Test" exit(FulfillmentOrderHeader."Shopify Fulfillment Order Id"); end; - local procedure CreateRandomSalesShipment(var SalesShipmentHeader: Record "Sales Shipment Header"; ShopifyOrderId: BigInteger) + internal procedure CreateRandomSalesShipment(var SalesShipmentHeader: Record "Sales Shipment Header"; ShopifyOrderId: BigInteger) var SalesShipmentLine: Record "Sales Shipment Line"; OrderLine: Record "Shpfy Order Line"; From 415b042b3d8e38f09e0942ca394e72ad424277bb Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 10 Oct 2024 08:12:23 +0200 Subject: [PATCH 20/32] add DIsable logging test --- .../ShpfySkippedRecordLogTest.Codeunit.al | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 6308e87d56..8c41ed877c 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -229,6 +229,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryInventory: Codeunit "Library - Inventory"; begin // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop as UoM Option ID. + // [GIVEN] Shop with UoM as Variant set. Item with variants which is blocked and sales blocked. // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. Shop := ShpfyInitializeTest.CreateShop(); @@ -329,7 +330,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibrarySales: Codeunit "Library - Sales"; begin - // [SCENARIO] Log skipped record when sales invoice is exported with not existing shopify customer. + // [SCENARIO] Log skipped record when sales invoice export is skipped because not existing shopify customer. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -358,10 +359,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer: Record "Shpfy Customer"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; begin - // [SCENARIO] Log skipped record when sales invoice is exported with not existing shopify payment terms. + // [SCENARIO] Log skipped record when sales invoice export is skipped because of not existing shopify payment terms. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -395,11 +395,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryPaymentFormat: Codeunit "Library - Payment Format"; PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales invoice is exported with customer no which is default shopify shop customer no. + // [SCENARIO] Log skipped record when sales invoice export is skipped because bill to customer no which is default shopify shop customer no. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -440,11 +438,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryPaymentFormat: Codeunit "Library - Payment Format"; PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales invoice is exported with customer no which is used in shopify customer templates. + // [SCENARIO] Log skipped record when sales invoice export is skipped because customer no which is used in shopify customer templates. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -485,13 +481,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryPaymentFormat: Codeunit "Library - Payment Format"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; - LibraryRandom: Codeunit "Library - Random"; begin - // [SCENARIO] Log skipped record when sales invoice is exported without sales line. + // [SCENARIO] Log skipped record when sales invoice export is skipped because it has no sales lines. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -529,12 +522,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; LibraryRandom: Codeunit "Library - Random"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales invoice is exported with sales line with decimal quantity. + // [SCENARIO] Log skipped record when sales invoice export is skipped sales line with decimal quantity. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -573,12 +565,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryRandom: Codeunit "Library - Random"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales invoice is exported with sales line with empty No field. + // [SCENARIO] Log skipped record when sales invoice export is skipped when sales invoice line has empty No field. // [GIVEN] Shop with setup Posted Invoice Sync = true. Shop := ShpfyInitializeTest.CreateShop(); @@ -612,17 +602,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var SalesShipmentHeader: Record "Sales Shipment Header"; Shop: Record "Shpfy Shop"; - Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryRandom: Codeunit "Library - Random"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - SyncShipmentToShopify: Report "Shpfy Sync Shipm. to Shopify"; - PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales shipment is exported without shipment lines. + // [SCENARIO] Log skipped record when sales shipment export is skipped because not existing shipment lines. // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); @@ -646,17 +629,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesShipmentHeader: Record "Sales Shipment Header"; SalesShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; - Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryRandom: Codeunit "Library - Random"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; - SyncShipmentToShopify: Report "Shpfy Sync Shipm. to Shopify"; - PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales shipment is exported with not existing shopify order. + // [SCENARIO] Log skipped record when sales shipment export is skipped because not existing related shopify order. // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); @@ -688,17 +664,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; ShopifyOrderHeader: Record "Shpfy Order Header"; ShopifyOrderLine: Record "Shpfy Order Line"; - Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - LibrarySales: Codeunit "Library - Sales"; - LibraryRandom: Codeunit "Library - Random"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; ExportShipments: Codeunit "Shpfy Export Shipments"; - PaymentTermsCode: Code[10]; begin - // [SCENARIO] Log skipped record when sales shipment is exported with failed fulfillment response from shopify. + // [SCENARIO] Log skipped record when sales shipment is export is skip because theres no fulfillment lines shopify. // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); @@ -772,6 +742,35 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); end; + [Test] + procedure UnitTestSkipLoggingWhenShopHasLoggingModeDisabled() + var + Shop: Record "Shpfy Shop"; + SkippedRecord: Record "Shpfy Skipped Record"; + SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + RecordID: RecordID; + ShopifyId: BigInteger; + TableId: Integer; + begin + // [SCENARIO] Skip logging when setup in shop for logging is Disabled. + + // [GIVEN] Shop with logging mode = Disabled. + Shop.Init(); + Shop.Code := Any.AlphanumericText(20); + Shop."Logging Mode" := Enum::"Shpfy Logging Mode"::Disabled; + Shop.Insert(false); + + // [WHEN] Invoke Skip Record Management + ShopifyId := Any.IntegerInRange(10000, 999999); + TableId := Any.IntegerInRange(1, 50000); + SkipRecordMgt.LogSkippedRecord(ShopifyId, TableId, RecordID, Any.AlphabeticText(250), Shop); + + // [THEN] No record is created in shopify skipped record table. + SkippedRecord.SetRange("Shopify Id", ShopifyId); + SkippedRecord.SetRange("Table Id", TableId); + LibraryAssert.IsTrue(SkippedRecord.IsEmpty(), 'Skipped record is created'); + end; + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) var ShopifyVariant: Record "Shpfy Variant"; From dc61ac06b2b00c41cbb2523d7168537eb5f08276 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 10 Oct 2024 12:55:12 +0200 Subject: [PATCH 21/32] test refactor fixes --- .../ShpfyPostedInvoiceExport.Codeunit.al | 6 +- .../Codeunits/ShpfyProductExport.Codeunit.al | 18 ++- .../ShpfyExportShipments.Codeunit.al | 4 +- .../ShpfySkippedRecordLogTest.Codeunit.al | 128 ++++++++++++------ 4 files changed, 105 insertions(+), 51 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 70c40a7464..32493537c9 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -91,7 +91,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" ShopifyCustomer: Record "Shpfy Customer"; CustomerNotExistingAsCompanyOrCustomerLbl: Label 'Customer not existing as Shopify company or customer.'; PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; - CustomerNoIsDefaultCustomerNoLbl: Label 'Customer No. is the default customer no. from Shopify shop.'; + CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; begin ShopifyCompany.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); @@ -154,9 +154,9 @@ codeunit 30362 "Shpfy Posted Invoice Export" local procedure CheckSalesInvoiceHeaderLines(SalesInvoiceHeader: Record "Sales Invoice Header"): Boolean var SalesInvoiceLine: Record "Sales Invoice Line"; - NoLinesInSalesInvoiceLbl: Label 'No lines in sales invoice.'; + NoLinesInSalesInvoiceLbl: Label 'No relevant sales invoice lines exist.'; InvalidQuantityLbl: Label 'Invalid quantity in sales invoice line.'; - EmptyNoInLineLbl: Label 'No. is empty in Sales Invoice Line.'; + EmptyNoInLineLbl: Label 'No. field is empty in Sales Invoice Line.'; begin SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 40d969781e..129666ab98 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -315,10 +315,14 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record Item. /// Parameter of type Record "Item Unit of Measure". local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemUnitofMeasure: Record "Item Unit of Measure") + var + ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then - ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price"); + ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") + else + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", '', ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -406,7 +410,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::"Shpfy Variant", ItemVariant.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -554,24 +558,24 @@ codeunit 30178 "Shpfy Product Export" RecordRef2: RecordRef; VariantAction: Option " ",Create,Update; ItemIsBlockedLbl: Label 'Item is blocked.'; - ItemIsDraftLbl: Label 'Product is draft.'; - ItemIsArchivedLbl: Label 'Product is archived.'; + ItemIsDraftLbl: Label 'Shopify Product is draft.'; + ItemIsArchivedLbl: Label 'Shopify Product is archived.'; begin if ShopifyProduct.Get(ProductId) and Item.GetBySystemId(ShopifyProduct."Item SystemId") then begin case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsArchivedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsArchivedLbl, Shop); exit; end; Shop."Action for Removed Products"::StatusToDraft: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsDraftLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsDraftLbl, Shop); exit; end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::"Shpfy Product", Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); exit; end; end; diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 4c9c49936a..766458ee65 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -45,7 +45,7 @@ codeunit 30190 "Shpfy Export Shipments" JResponse: JsonToken; FulfillmentOrderRequest: Text; NoCorespondingFulfilmentLinesLbl: Label 'No corresponding fulfillment lines found.'; - NoFullfilmentFoundInShopifyLbl: Label 'Fullfilment was not created in Shopify.'; + NoFullfilmentCreatedInShopifyLbl: Label 'No corresponding fulfillment lines found.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); @@ -57,7 +57,7 @@ codeunit 30190 "Shpfy Export Shipments" if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoFullfilmentFoundInShopifyLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoFullfilmentCreatedInShopifyLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; end else begin diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 8c41ed877c..a27f7c3de6 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -7,7 +7,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert: Codeunit "Library Assert"; Any: Codeunit Any; SalesShipmentNo: Code[20]; - EmptyCustomerIdsTok: Label '{ "data": { "customers": { "pageInfo": { "hasNextPage": false }, "edges": [] } }, "extensions": { "cost": { "requestedQueryCost": 12, "actualQueryCost": 2, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1998, "restoreRate": 100 } } } }', Locked = true; [Test] procedure UnitTestLogEmptyCustomerEmail() @@ -38,7 +37,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Customer has no e-mail address.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -75,7 +75,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Customer already exists with the same e-mail or phone.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -105,7 +106,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Item is blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -138,7 +140,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Shopify Product is archived.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -172,7 +176,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" UnbindSubscription(ShpfySkippedRecordLogSub); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Shopify Product is draft.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -181,6 +187,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; Item: Record Item; ShpfyProduct: Record "Shpfy Product"; + ShpfyVariant: Record "Shpfy Variant"; SkippedRecord: Record "Shpfy Skipped Record"; ProductInitTest: Codeunit "Shpfy Product Init Test"; ProductExport: Codeunit "Shpfy Product Export"; @@ -198,7 +205,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Item.Blocked := true; Item."Sales Blocked" := true; Item.Modify(false); - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code, ShpfyVariant); // [WHEN] Invoke Shopify Product Export BindSubscription(SkippedrecordLogSub); @@ -209,7 +216,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Shopify Id", ShpfyVariant.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -247,9 +256,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); // [GIVEN] Product Variant with UoM and UomM Option Id set. - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); - ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); - ShpfyVariant.FindFirst(); + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code, ShpfyVariant); ShpfyVariant."UoM Option Id" := 1; ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; ShpfyVariant.Modify(false); @@ -263,7 +270,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Shopify Id", ShpfyVariant.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -317,6 +326,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); LibraryAssert.AreEqual(2, SkippedRecord.Count(), 'Skipped record is not created'); //Two recrds are created because its not possible to omit one with Shop."UoM as Variant" := true; + SkippedRecord.FindLast(); + LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -346,7 +357,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Customer not existing as Shopify company or customer.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -360,6 +372,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because of not existing shopify payment terms. @@ -373,15 +386,20 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); + // [GIVEN] Payment Terms Code + PaymentTermsCode := Any.AlphanumericText(10); // [GIVEN] Sales Invoice CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; + SalesInvoiceHeader.Modify(false); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual(StrSubstNo('Payment terms %1 does not exist in Shopify.', PaymentTermsCode), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -410,7 +428,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(); + PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Shop with default customer no set. Shop."Default Customer No." := Customer."No."; Shop.Modify(false); @@ -420,10 +438,13 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesInvoiceHeader.Modify(false); // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.SetShop(Shop.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Bill-to customer no. is the default customer no. for Shopify shop.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -447,13 +468,15 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop."Posted Invoice Sync" := true; Shop.Modify(false); // [GIVEN] Customer - Customer := ShpfyInitializeTest.GetDummyCustomer(); + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer.Insert(false); // [GIVEN] Shopify Customer CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(); + PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Shopify Customer Template with customer no. ShopifyCustomerTemplate.Init(); ShopifyCustomerTemplate."Shop Code" := Shop.Code; @@ -465,16 +488,20 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesInvoiceHeader.Modify(false); // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.SetShop(Shop.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", Shop.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] procedure UnitTestLogSalesInvoiceWithoutSalesLine() var SalesInvoiceHeader: Record "Sales Invoice Header"; + SalesInvoiceLine: Record "Sales Invoice Line"; Shop: Record "Shpfy Shop"; Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; @@ -498,17 +525,22 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(); + PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice without sales line. CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; SalesInvoiceHeader.Modify(false); + if not SalesInvoiceLine.IsEmpty() then + SalesInvoiceLine.DeleteAll(false); // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.SetShop(Shop.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('No relevant sales invoice lines exist.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -539,7 +571,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(); + PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice with sales line with decimal quantity. CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; @@ -547,11 +579,13 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", LibraryRandom.RandDecInDecimalRange(0.01, 0.99, 2), Any.AlphanumericText(20)); // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.SetShop(Shop.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. - SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Record ID", SalesInvoiceLine.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Invalid quantity in sales invoice line.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -581,7 +615,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyCustomer."Customer SystemId" := Customer.SystemId; ShopifyCustomer.Modify(false); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(); + PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice with sales line with empty No field. CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; @@ -589,11 +623,14 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", Any.IntegerInRange(100), ''); // [WHEN] Invoke Shopify Posted Invoice Export + PostedInvoiceExport.SetShop(Shop.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. - SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + SkippedRecord.SetRange("Record ID", SalesInvoiceLine.RecordId); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('No. field is empty in Sales Invoice Line.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + end; [Test] @@ -619,7 +656,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('No lines applicable for fulfillment.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -631,13 +669,15 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; + ShopifyOrderId: BigInteger; begin // [SCENARIO] Log skipped record when sales shipment export is skipped because not existing related shopify order. // [GIVEN] Shop Shop := ShpfyInitializeTest.CreateShop(); // [GIVEN] Posted shipment with line. - CreateSalesShipmentHeader(SalesShipmentHeader, Any.IntegerInRange(10000, 999999)); + ShopifyOrderId := Any.IntegerInRange(10000, 999999); + CreateSalesShipmentHeader(SalesShipmentHeader, ShopifyOrderId); SalesShipmentNo := SalesShipmentHeader."No."; SalesShipmentLine.Init(); SalesShipmentLine."Document No." := SalesShipmentHeader."No."; @@ -653,7 +693,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual(StrSubstNo('Shopify order %1 does not exist.', ShopifyOrderId), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -701,21 +742,22 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('No corresponding fulfillment lines found.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] - procedure LogSalesShipmentNoFulfilmentCreatedInSHopify() + procedure LogSalesShipmentNoFulfilmentCreatedInShopify() var SalesShipmentHeader: Record "Sales Shipment Header"; Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; + ShopifyOrderHeader: Record "Shpfy Order Header"; ExportShipments: Codeunit "Shpfy Export Shipments"; ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShippingTest: Codeunit "Shpfy Shipping Test"; SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; ShopifyOrderId: BigInteger; - ShopifyOrderHeader: Record "Shpfy Order Header"; LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; begin @@ -739,7 +781,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); - LibraryAssert.IsFalse(SkippedRecord.IsEmpty(), 'Skipped record is not created'); + LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); + LibraryAssert.AreEqual('No corresponding fulfillment lines found.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -771,34 +814,40 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsTrue(SkippedRecord.IsEmpty(), 'Skipped record is created'); end; - local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) - var - ShopifyVariant: Record "Shpfy Variant"; + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]; var ShopifyVariant: Record "Shpfy Variant") begin + Randomize(); ShopifyProduct.DeleteAll(false); ShopifyProduct.Init(); - ShopifyProduct.Id := Any.IntegerInRange(10000, 999999); + ShopifyProduct.Id := Random(999999); ShopifyProduct."Item SystemId" := ItemSystemId; ShopifyProduct."Shop Code" := ShopCode; ShopifyProduct.Insert(false); ShopifyVariant.DeleteAll(false); ShopifyVariant.Init(); - ShopifyVariant.Id := Any.IntegerInRange(10000, 999999); + ShopifyVariant.Id := Random(999999); ShopifyVariant."Product Id" := ShopifyProduct.Id; ShopifyVariant."Item SystemId" := ItemSystemId; ShopifyVariant."Shop Code" := ShopCode; ShopifyVariant.Insert(false); end; + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]) + var + ShopifyVariant: Record "Shpfy Variant"; + begin + CreateShpfyProduct(ShopifyProduct, ItemSystemId, ShopCode, ShopifyVariant); + end; + local procedure CreateSalesInvoiceHeader(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]) begin SalesInvoiceHeader.Init(); SalesInvoiceHeader."No." := Any.AlphanumericText(20); - SalesInvoiceHeader."Sell-to Customer No." := CustomerNo; + SalesInvoiceHeader."Bill-to Customer No." := CustomerNo; SalesInvoiceHeader.Insert(false); end; - local procedure CreatePaymentTerms(): Code[10] + local procedure CreatePaymentTerms(ShopCode: Code[20]): Code[10] var PaymentTerms: Record "Payment Terms"; ShopifyPaymentTerms: Record "Shpfy Payment Terms"; @@ -809,13 +858,14 @@ codeunit 139581 "Shpfy Skipped Record Log Test" PaymentTerms.Code := Any.AlphanumericText(10); PaymentTerms.Insert(false); ShopifyPaymentTerms.Init(); + ShopifyPaymentTerms."Shop Code" := ShopCode; ShopifyPaymentTerms."Payment Terms Code" := PaymentTerms.Code; ShopifyPaymentTerms."Is Primary" := true; ShopifyPaymentTerms.Insert(false); exit(PaymentTerms.Code); end; - local procedure CreateSalesInvoiceLine(SalesInvoiceLine: Record "Sales Invoice Line"; DocumentNo: Code[20]; Quantity: Decimal; No: Text) + local procedure CreateSalesInvoiceLine(var SalesInvoiceLine: Record "Sales Invoice Line"; DocumentNo: Code[20]; Quantity: Decimal; No: Text) begin SalesInvoiceLine.Init(); SalesInvoiceLine."Document No." := DocumentNo; From 27c753834186412906a755ab8e4952131a949b35 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 11 Oct 2024 15:10:36 +0200 Subject: [PATCH 22/32] tests refactor --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 2 +- .../ShpfyPostedInvoiceExport.Codeunit.al | 16 +- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 7 +- .../Codeunits/ShpfyProductExport.Codeunit.al | 19 +- .../ShpfyExportShipments.Codeunit.al | 2 +- .../ShpfySkippedRecordLogTest.Codeunit.al | 630 ++++++++---------- .../Shipping/ShpfyShippingTest.Codeunit.al | 1 + 7 files changed, 313 insertions(+), 364 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 64acfd3522..de7d7d55dd 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -91,7 +91,7 @@ codeunit 30116 "Shpfy Customer Export" EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShopifySkipRecordMgt.LogSkippedRecord(0, Database::Customer, Customer.RecordId, EmptyEmailAddressLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(Database::Customer, Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 32493537c9..355fa86692 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -89,7 +89,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" var ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; - CustomerNotExistingAsCompanyOrCustomerLbl: Label 'Customer not existing as Shopify company or customer.'; + CustomerNotExistInShopifyLbl: Label 'Customer not existing as Shopify company or customer.'; PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; @@ -98,23 +98,23 @@ codeunit 30362 "Shpfy Posted Invoice Export" if ShopifyCompany.IsEmpty() then begin ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCustomer.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistingAsCompanyOrCustomerLbl, Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop); exit(false); end; end; if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); exit(false); end; if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); exit(false); end; if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); exit(false); end; @@ -160,7 +160,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" begin SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); exit(false); end; @@ -171,12 +171,12 @@ codeunit 30362 "Shpfy Posted Invoice Export" if SalesInvoiceLine.FindSet() then repeat if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); exit(false); end; if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then begin - SkipRecordMgt.LogSkippedRecord(0, Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); + SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); exit(false); end; until SalesInvoiceLine.Next() = 0; diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index 6fb364bc46..093e0d7430 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -29,7 +29,12 @@ codeunit 30168 "Shpfy Skip Record Mgt." ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason); ShpfySkippedRecord.Validate("Created On", CurrentDateTime); ShpfySkippedRecord.Validate("Created Time", DT2Time(CurrentDateTime)); - ShpfySkippedRecord.Insert(false); + ShpfySkippedRecord.Insert(true); + end; + + internal procedure LogSkippedRecord(TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") + begin + LogSkippedRecord(0, TableId, RecordId, SkippedReason, Shop); end; } diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 129666ab98..c6ae670621 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -65,6 +65,7 @@ codeunit 30178 "Shpfy Product Export" NullGuid: Guid; BulkOperationInput: TextBuilder; GraphQueryList: List of [TextBuilder]; + VariantPriceCalcSkippedLbl: Label 'Variant price is not synchronized because the item is blocked and sales blocked.'; /// /// Creates html body for a product from extended text, marketing text and attributes. @@ -314,15 +315,13 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record "Shopify Variant". /// Parameter of type Record Item. /// Parameter of type Record "Item Unit of Measure". - local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemUnitofMeasure: Record "Item Unit of Measure") - var - ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; + internal procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemUnitofMeasure: Record "Item Unit of Measure") begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", '', ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -353,15 +352,13 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record "Shopify Variant". /// Parameter of type Record Item. /// Parameter of type Record "Item Variant". - local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant") - var - ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; + internal procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant") begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -402,15 +399,13 @@ codeunit 30178 "Shpfy Product Export" /// Parameter of type Record Item. /// Parameter of type Record "Item Variant". /// Parameter of type Record "Item Unit of Measure". - local procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant"; ItemUnitofMeasure: Record "Item Unit of Measure") - var - ItemIsBlockedLbl: Label 'Price is not synchronized because the item is blocked and sales blocked.'; + internal procedure FillInProductVariantData(var ShopifyVariant: Record "Shpfy Variant"; Item: Record Item; ItemVariant: Record "Item Variant"; ItemUnitofMeasure: Record "Item Unit of Measure") begin if Shop."Sync Prices" or OnlyUpdatePrice then if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 766458ee65..9a3991950e 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -45,7 +45,7 @@ codeunit 30190 "Shpfy Export Shipments" JResponse: JsonToken; FulfillmentOrderRequest: Text; NoCorespondingFulfilmentLinesLbl: Label 'No corresponding fulfillment lines found.'; - NoFullfilmentCreatedInShopifyLbl: Label 'No corresponding fulfillment lines found.'; + NoFullfilmentCreatedInShopifyLbl: Label 'Fullfilment was not created in Shopify.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index a27f7c3de6..9106043c7b 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -4,34 +4,39 @@ codeunit 139581 "Shpfy Skipped Record Log Test" TestPermissions = Disabled; var + Shop: Record "Shpfy Shop"; + ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibraryAssert: Codeunit "Library Assert"; Any: Codeunit Any; SalesShipmentNo: Code[20]; + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; [Test] procedure UnitTestLogEmptyCustomerEmail() var - Shop: Record "Shpfy Shop"; + Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when customer email is empty on customer export to shopify. + Initialize(); // [GIVEN] A customer record with empty email. - Shop := ShpfyInitializeTest.CreateShop(); - Customer := ShpfyInitializeTest.GetDummyCustomer(); - Customer."E-Mail" := ''; - Customer.Modify(false); - Customer.SetRange("No.", Customer."No."); + CreateCustomerWithEmail(Customer, ''); // [WHEN] Invoke Shopify Customer Export BindSubscription(ShpfySkippedRecordLogSub); ShpfySkippedRecordLogSub.SetShopifyCustomerId(0); ShpfyCustomerExport.SetShop(Shop); ShpfyCustomerExport.SetCreateCustomers(true); + Customer.SetRange("No.", Customer."No."); ShpfyCustomerExport.Run(Customer); UnbindSubscription(ShpfySkippedRecordLogSub); @@ -44,32 +49,26 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogCustomerForSameEmailExist() var - Shop: Record "Shpfy Shop"; Customer: Record Customer; ShpfyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when customer with same email already exist on customer export to shopify. + Initialize(); // [GIVEN] A customer record with email that already exist in shopify. - Shop := ShpfyInitializeTest.CreateShop(); - Customer := ShpfyInitializeTest.GetDummyCustomer(); + CreateCustomerWithEmail(Customer, 'dummy@cust.com'); // [GIVEN] Shopify customer with random guid. - CustomerInitTest.CreateShopifyCustomer(ShpfyCustomer); - ShpfyCustomer."Customer SystemId" := CreateGuid(); - // [GIVEN] Shop with - Shop."Can Update Shopify Customer" := true; - Shop.Modify(false); + CreateShopifyCustomerWithRandomGuid(ShpfyCustomer); // [WHEN] Invoke Shopify Customer Export BindSubscription(ShpfySkippedRecordLogSub); ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomer.Id); ShpfyCustomerExport.SetShop(Shop); ShpfyCustomerExport.SetCreateCustomers(true); + Customer.SetRange("No.", Customer."No."); ShpfyCustomerExport.Run(Customer); UnbindSubscription(ShpfySkippedRecordLogSub); @@ -82,21 +81,18 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogProductItemBlocked() var - Shop: Record "Shpfy Shop"; + Item: Record Item; ShpfyItem: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; begin // [SCENARIO] Log skipped record when product item is blocked + Initialize(); + // [GIVEN] A product item record that is blocked. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop.Modify(false); - Item := ShpfyInitializeTest.GetDummyItem(); - Item."Blocked" := true; - Item.Modify(false); + CreateBlockedItem(Item); + // [GIVEN] Shopify Product CreateShpfyProduct(ShpfyItem, Item.SystemId, Shop.Code); // [WHEN] Invoke Shopify Product Export @@ -113,25 +109,21 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogProductItemBlockedAndProductArchived() var - Shop: Record "Shpfy Shop"; + Item: Record Item; ShpfyProduct: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; begin // [SCENARIO] Log skipped record when product item is blocked and product is archived + Initialize(); + // [GIVEN] A product item record that is blocked and archived. Shop with action for removed products set to status to archived. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; - Shop.Modify(false); - Item := ShpfyInitializeTest.GetDummyItem(); - Item."Blocked" := true; - Item.Modify(false); - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); - ShpfyProduct.Status := Enum::"Shpfy Product Status"::Archived; - ShpfyProduct.Modify(false); + SetActionForRemovedProducts(Shop, Enum::"Shpfy Remove Product Action"::StatusToArchived); + // [GIVEN] Item that is blocked. + CreateBlockedItem(Item); + // [GIVEN] Shpify Product with status archived. + CreateSHopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Archived); // [WHEN] Invoke Shopify Product Export ProductExport.SetShop(Shop); @@ -148,32 +140,32 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogProductItemBlockedAndProductIsDraft() var - Shop: Record "Shpfy Shop"; + Item: Record Item; ShpfyProduct: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when product item is blocked and product is draft - // [GIVEN] A product item record that is blocked and draft. Shop with action for removed products set to status to draft. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToDraft; - Shop.Modify(false); - Item := ShpfyInitializeTest.GetDummyItem(); - Item."Blocked" := true; - Item.Modify(false); - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); - ShpfyProduct.Status := Enum::"Shpfy Product Status"::Draft; - ShpfyProduct.Modify(false); + Initialize(); + + // [GIVEN] Shop with action for removed products set to status to draft. + SetActionForRemovedProducts(Shop, Enum::"Shpfy Remove Product Action"::StatusToDraft); + + // [GIVEN] Item that is blocked. + CreateBlockedItem(Item); + + // [GIVEN] Shpify Product with status draft. + CreateSHopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Draft); + // [WHEN] Invoke Shopify Product Export BindSubscription(ShpfySkippedRecordLogSub); ProductExport.SetShop(Shop); Shop.SetRange("Code", Shop.Code); ProductExport.Run(Shop); UnbindSubscription(ShpfySkippedRecordLogSub); + // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); @@ -182,152 +174,94 @@ codeunit 139581 "Shpfy Skipped Record Log Test" end; [Test] - procedure UnitTestLogItemVariantIsIsBlockedAndSalesBlocked() + procedure UnitTestSkipShopifyVariantPriceCalcWithItemUnitOfMeasureForVariantWithBlockedItem() var - Shop: Record "Shpfy Shop"; Item: Record Item; - ShpfyProduct: Record "Shpfy Product"; - ShpfyVariant: Record "Shpfy Variant"; - SkippedRecord: Record "Shpfy Skipped Record"; - ProductInitTest: Codeunit "Shpfy Product Init Test"; + ShopifyProduct: Record "Shpfy Product"; + ShopifyVariant: Record "Shpfy Variant"; + ItemunitOfMeasure: Record "Item Unit of Measure"; + ShpfySkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin - // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked - // [GIVEN] Shop with Sync Prices = true. Item with variants which is blocked and sales blocked. - // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; - Shop.Modify(false); - Item := ProductInitTest.CreateItem(true); - Item.Blocked := true; - Item."Sales Blocked" := true; - Item.Modify(false); - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code, ShpfyVariant); + // [SCENARIO] Skip shopify variant price calculation using item unit of measure for variant with blocked item. + Initialize(); - // [WHEN] Invoke Shopify Product Export - BindSubscription(SkippedrecordLogSub); - Shop.SetRange("Code", Shop.Code); + // [GIVEN] Blocked and sales blokced item + CreateBlockedItem(Item); + // [GIVEN] Shopify Product + CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); + + // [WHEN] Invoke FillInProductVariantData + ProductExport.SetShop(Shop); ProductExport.SetOnlyUpdatePriceOn(); - ProductExport.Run(Shop); - UnbindSubscription(SkippedrecordLogSub); + ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemUnitOfMeasure); - // [THEN] Related record is created in shopify skipped record table. - SkippedRecord.SetRange("Record ID", Item.RecordId); - SkippedRecord.SetRange("Shopify Id", ShpfyVariant.Id); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + // [THEN] Related log record is created in shopify skipped record table. + ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); + ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] - procedure UnitTestLogItemIsBlockedAndSalesBlockedWithUnitOfMeasureAsUoMOptionId() + procedure UnitTestSkipShopifyVariantPriceCalcWithItemVariantForVariantWithBlockedItem() var - Shop: Record "Shpfy Shop"; Item: Record Item; - ShpfyProduct: Record "Shpfy Product"; - ShpfyVariant: Record "Shpfy Variant"; - SkippedRecord: Record "Shpfy Skipped Record"; - ItemUnitofMeasure: Record "Item Unit of Measure"; - UnitofMeasure: Record "Unit of Measure"; - ProductInitTest: Codeunit "Shpfy Product Init Test"; + ShopifyProduct: Record "Shpfy Product"; + ShopifyVariant: Record "Shpfy Variant"; + ItemVariant: Record "Item Variant"; + ShpfySkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; - LibraryInventory: Codeunit "Library - Inventory"; begin - // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop as UoM Option ID. + // [SCENARIO] Skip shopify variant price calculation using item variant for variant with blocked item. + Initialize(); - // [GIVEN] Shop with UoM as Variant set. Item with variants which is blocked and sales blocked. - // [GIVEN] Shopify Shop Remove Product Action diffrent than DoNothing. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; - Shop."UoM as Variant" := true; - Shop.Modify(false); - // [GIVEN] Item with blocked and sales blocked. - Item := ProductInitTest.CreateItem(false); - Item.Blocked := true; - Item."Sales Blocked" := true; - Item.Modify(false); - // [GIVEN] Unit of Measure and Item Unit of Measure. - LibraryInventory.CreateUnitOfMeasureCode(UnitofMeasure); - LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); - ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); - // [GIVEN] Product Variant with UoM and UomM Option Id set. - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code, ShpfyVariant); - ShpfyVariant."UoM Option Id" := 1; - ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; - ShpfyVariant.Modify(false); + // [GIVEN] Blocked and sales blokced item + CreateBlockedItem(Item); + // [GIVEN] Shopify Product + CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); - // [WHEN] Invoke Shopify Product Export - BindSubscription(SkippedrecordLogSub); - Shop.SetRange("Code", Shop.Code); + // [WHEN] Invoke FillInProductVariantData + ProductExport.SetShop(Shop); ProductExport.SetOnlyUpdatePriceOn(); - ProductExport.Run(Shop); - UnbindSubscription(SkippedrecordLogSub); + ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemVariant); - // [THEN] Related record is created in shopify skipped record table. - SkippedRecord.SetRange("Record ID", Item.RecordId); - SkippedRecord.SetRange("Shopify Id", ShpfyVariant.Id); - LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + // [THEN] Related log record is created in shopify skipped record table. + ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); + ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] - procedure UnitTestLogItemVariantIsBlockedAndSalesBlockedWithUnitOfMeasureSetOnVariantOptions() + procedure UnitTestSkipShopifyVariantPriceCalcWithItemUnitOfMeasureAndItemVariantForVariantWithBlockedItem() var - Shop: Record "Shpfy Shop"; Item: Record Item; - ShpfyProduct: Record "Shpfy Product"; - ShpfyVariant: Record "Shpfy Variant"; - SkippedRecord: Record "Shpfy Skipped Record"; - ItemUnitofMeasure: Record "Item Unit of Measure"; - UnitofMeasure: Record "Unit of Measure"; - ProductInitTest: Codeunit "Shpfy Product Init Test"; + ShopifyProduct: Record "Shpfy Product"; + ShopifyVariant: Record "Shpfy Variant"; + ItemUnitOfMeasure: Record "Item Unit of Measure"; + ItemVariant: Record "Item Variant"; + ShpfySkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - SkippedrecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; - LibraryInventory: Codeunit "Library - Inventory"; begin - // [SCENARIO] Log skipped record when item variant item is blocked and sales blocked with unit of measure set fot shopify variant and shop. + // [SCENARIO] Skip shopify variant price calculation using item unit of measure and item variant for variant with blocked item. + Initialize(); - // [GIVEN] Shop with UoM as Variant and Option name for UoM set. Item with variants which is blocked and sales blocked. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Can Update Shopify Products" := true; - Shop."Action for Removed Products" := Enum::"Shpfy Remove Product Action"::StatusToArchived; - Shop."UoM as Variant" := true; - Shop."Option Name for UoM" := Any.AlphanumericText(MaxStrLen(Shop."Option Name for UoM")); - Shop.Modify(false); - // [GIVEN] Item with blocked and sales blocked. - Item := ProductInitTest.CreateItem(false); - Item.Blocked := true; - Item."Sales Blocked" := true; - Item.Modify(false); - // [GIVEN] Unit of Measure and Item Unit of Measure. - LibraryInventory.CreateUnitOfMeasureCode(UnitofMeasure); - LibraryInventory.CreateItemUnitOfMeasure(ItemUnitofMeasure, Item."No.", UnitofMeasure.Code, Any.DecimalInRange(1, 2)); - // [GIVEN] Product Variant with UoM and UoM Option name set as in shop. - CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); - ShpfyVariant.SetRange("Product Id", ShpfyProduct.Id); - ShpfyVariant.FindFirst(); - ShpfyVariant."Option 1 Name" := Shop."Option Name for UoM"; - ShpfyVariant."Option 1 Value" := ItemUnitofMeasure.Code; - ShpfyVariant.Modify(false); + // [GIVEN] Blocked and sales blokced item + CreateBlockedItem(Item); + // [GIVEN] Shopify Product + CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); - // [WHEN] Invoke Shopify Product Export - BindSubscription(SkippedrecordLogSub); - Shop.SetRange("Code", Shop.Code); + // [WHEN] Invoke FillInProductVariantData + ProductExport.SetShop(Shop); ProductExport.SetOnlyUpdatePriceOn(); - ProductExport.Run(Shop); - UnbindSubscription(SkippedrecordLogSub); + ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemVariant, ItemUnitOfMeasure); - // [THEN] Related record is created in shopify skipped record table. - SkippedRecord.SetRange("Record ID", Item.RecordId); - LibraryAssert.AreEqual(2, SkippedRecord.Count(), 'Skipped record is not created'); //Two recrds are created because its not possible to omit one with Shop."UoM as Variant" := true; - SkippedRecord.FindLast(); - LibraryAssert.AreEqual('Price is not synchronized because the item is blocked and sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + // [THEN] Related log record is created in shopify skipped record table. + ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); + ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -335,22 +269,17 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var Customer: Record Customer; SalesInvoiceHeader: Record "Sales Invoice Header"; - Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibrarySales: Codeunit "Library - Sales"; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because not existing shopify customer. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer LibrarySales.CreateCustomer(Customer); // [GIVEN] Sales Invoice - CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", ''); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); @@ -366,32 +295,21 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var Customer: Record Customer; SalesInvoiceHeader: Record "Sales Invoice Header"; - Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - ShopifyCustomer: Record "Shpfy Customer"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because of not existing shopify payment terms. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code PaymentTermsCode := Any.AlphanumericText(10); // [GIVEN] Sales Invoice - CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", PaymentTermsCode); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); @@ -406,39 +324,30 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure UnitTestLogSalesInvoiceWithCustomerNoIsDefaultCustomerNo() var SalesInvoiceHeader: Record "Sales Invoice Header"; - Shop: Record "Shpfy Shop"; Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; + Shop2: Record "Shpfy Shop"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because bill to customer no which is default shopify shop customer no. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer - Customer := ShpfyInitializeTest.GetDummyCustomer(); + CreateRandomCustomer(Customer); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); + // [GIVEN] Shop with default customer no set. + CreateShop(Shop2, Customer."No."); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(Shop.Code); + PaymentTermsCode := CreatePaymentTerms(Shop2.Code); // [GIVEN] Shop with default customer no set. - Shop."Default Customer No." := Customer."No."; - Shop.Modify(false); + SetCustomerAsDefaultForShop(Shop2, Customer); // [GIVEN] Sales Invoice for default customer no. - CreateSalesInvoiceHeader(SalesInvoiceHeader, Shop."Default Customer No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Shop2."Default Customer No.", PaymentTermsCode); // [WHEN] Invoke Shopify Posted Invoice Export - PostedInvoiceExport.SetShop(Shop.Code); + PostedInvoiceExport.SetShop(Shop2.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. @@ -451,50 +360,37 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure UnitTestLogSalesInvoiceWithCustomerNoUsedInShopifyCustomerTemplates() var SalesInvoiceHeader: Record "Sales Invoice Header"; - Shop: Record "Shpfy Shop"; Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; + Shop2: Record "Shpfy Shop"; ShopifyCustomerTemplate: Record "Shpfy Customer Template"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because customer no which is used in shopify customer templates. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer.Insert(false); + CreateRandomCustomer(Customer); + // [GIVEN] Shop + CreateShop(Shop2, ''); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(Shop.Code); + PaymentTermsCode := CreatePaymentTerms(Shop2.Code); // [GIVEN] Shopify Customer Template with customer no. - ShopifyCustomerTemplate.Init(); - ShopifyCustomerTemplate."Shop Code" := Shop.Code; - ShopifyCustomerTemplate."Default Customer No." := Customer."No."; - ShopifyCustomerTemplate.Insert(false); + CreateShopifyCustomerTemplate(ShopifyCustomerTemplate, Shop2, Customer); // [GIVEN] Sales Invoice for default customer no. - CreateSalesInvoiceHeader(SalesInvoiceHeader, ShopifyCustomerTemplate."Default Customer No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, ShopifyCustomerTemplate."Default Customer No.", PaymentTermsCode); // [WHEN] Invoke Shopify Posted Invoice Export - PostedInvoiceExport.SetShop(Shop.Code); + PostedInvoiceExport.SetShop(Shop2.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", Shop.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", Shop2.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -502,34 +398,23 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var SalesInvoiceHeader: Record "Sales Invoice Header"; SalesInvoiceLine: Record "Sales Invoice Line"; - Shop: Record "Shpfy Shop"; Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped because it has no sales lines. - - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); + Initialize(); // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice without sales line. - CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", PaymentTermsCode); + // [GIVEN] No existing sales lines. if not SalesInvoiceLine.IsEmpty() then SalesInvoiceLine.DeleteAll(false); @@ -548,34 +433,23 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var SalesInvoiceHeader: Record "Sales Invoice Header"; SalesInvoiceLine: Record "Sales Invoice Line"; - Shop: Record "Shpfy Shop"; Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; LibraryRandom: Codeunit "Library - Random"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped sales line with decimal quantity. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice with sales line with decimal quantity. - CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", PaymentTermsCode); CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", LibraryRandom.RandDecInDecimalRange(0.01, 0.99, 2), Any.AlphanumericText(20)); // [WHEN] Invoke Shopify Posted Invoice Export @@ -593,33 +467,22 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var SalesInvoiceHeader: Record "Sales Invoice Header"; SalesInvoiceLine: Record "Sales Invoice Line"; - Shop: Record "Shpfy Shop"; Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; - CustomerInitTest: Codeunit "Shpfy Customer Init Test"; PaymentTermsCode: Code[10]; begin // [SCENARIO] Log skipped record when sales invoice export is skipped when sales invoice line has empty No field. + Initialize(); - // [GIVEN] Shop with setup Posted Invoice Sync = true. - Shop := ShpfyInitializeTest.CreateShop(); - Shop."Posted Invoice Sync" := true; - Shop.Modify(false); // [GIVEN] Customer Customer := ShpfyInitializeTest.GetDummyCustomer(); // [GIVEN] Shopify Customer - CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Modify(false); + CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code PaymentTermsCode := CreatePaymentTerms(Shop.Code); // [GIVEN] Sales Invoice with sales line with empty No field. - CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No."); - SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; - SalesInvoiceHeader.Modify(false); + CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", PaymentTermsCode); CreateSalesInvoiceLine(SalesInvoiceLine, SalesInvoiceHeader."No.", Any.IntegerInRange(100), ''); // [WHEN] Invoke Shopify Posted Invoice Export @@ -638,17 +501,13 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure UnitTestLogSalesShipmentWithoutShipmentLines() var SalesShipmentHeader: Record "Sales Shipment Header"; - Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; begin // [SCENARIO] Log skipped record when sales shipment export is skipped because not existing shipment lines. + Initialize(); - // [GIVEN] Shop - Shop := ShpfyInitializeTest.CreateShop(); // [GIVEN] Posted shipment without lines. CreateSalesShipmentHeader(SalesShipmentHeader, Any.IntegerInRange(10000, 999999)); - SalesShipmentNo := SalesShipmentHeader."No."; Commit(); // [WHEN] Invoke Shopify Sync Shipment to Shopify @@ -665,30 +524,22 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure UnitTestLogSalesShipmentWithNotExistingShopifyOrder() var SalesShipmentHeader: Record "Sales Shipment Header"; - SalesShipmentLine: Record "Sales Shipment Line"; - Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShopifyOrderId: BigInteger; begin // [SCENARIO] Log skipped record when sales shipment export is skipped because not existing related shopify order. + Initialize(); - // [GIVEN] Shop - Shop := ShpfyInitializeTest.CreateShop(); - // [GIVEN] Posted shipment with line. + // [GIVEN] Random shopify order id ShopifyOrderId := Any.IntegerInRange(10000, 999999); + + // [GIVEN] Posted shipment with line. CreateSalesShipmentHeader(SalesShipmentHeader, ShopifyOrderId); - SalesShipmentNo := SalesShipmentHeader."No."; - SalesShipmentLine.Init(); - SalesShipmentLine."Document No." := SalesShipmentHeader."No."; - SalesShipmentLine."Line No." := 10000; - SalesShipmentLine.Type := SalesShipmentLine.Type::Item; - SalesShipmentLine."No." := Any.AlphanumericText(20); - SalesShipmentLine.Quantity := Any.IntegerInRange(1, 100); - SalesShipmentLine.Insert(false); + CreateSalesShipmentLine(SalesShipmentHeader."No."); Commit(); // [WHEN] Invoke Shopify Sync Shipment to Shopify + SalesShipmentNo := SalesShipmentHeader."No."; Report.Run(Report::"Shpfy Sync Shipm. to Shopify"); // [THEN] Related record is created in shopify skipped record table. @@ -701,41 +552,18 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure LogSalesShipmentNoCorrespondingFulfillmentWithFailedResponse() var SalesShipmentHeader: Record "Sales Shipment Header"; - SalesShipmentLine: Record "Sales Shipment Line"; - Shop: Record "Shpfy Shop"; - ShopifyOrderHeader: Record "Shpfy Order Header"; - ShopifyOrderLine: Record "Shpfy Order Line"; SkippedRecord: Record "Shpfy Skipped Record"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ExportShipments: Codeunit "Shpfy Export Shipments"; + ShippingTest: Codeunit "Shpfy Shipping Test"; + ShopifyOrderId: BigInteger; begin // [SCENARIO] Log skipped record when sales shipment is export is skip because theres no fulfillment lines shopify. + Initialize(); - // [GIVEN] Shop - Shop := ShpfyInitializeTest.CreateShop(); // [GIVEN] Shopify order with line - ShopifyOrderHeader.Init(); - ShopifyOrderHeader."Shop Code" := Shop.Code; - ShopifyOrderHeader."Shopify Order Id" := Any.IntegerInRange(10000, 999999); - ShopifyOrderHeader.Insert(false); - - ShopifyOrderLine.Init(); - ShopifyOrderLine."Shopify Order Id" := ShopifyOrderHeader."Shopify Order Id"; - ShopifyOrderLine."Line Id" := Any.IntegerInRange(10000, 999999); - ShopifyOrderLine.Quantity := Any.IntegerInRange(1, 100); - ShopifyOrderLine.Insert(false); - + ShopifyOrderId := CreateshopifyOrder(Shop, Enum::"Shpfy Delivery Method Type"::" "); // [GIVEN] Posted shipment with line. - CreateSalesShipmentHeader(SalesShipmentHeader, ShopifyOrderHeader."Shopify Order Id"); - SalesShipmentLine.Init(); - SalesShipmentLine."Document No." := SalesShipmentHeader."No."; - SalesShipmentLine."Line No." := 10000; - SalesShipmentLine.Type := SalesShipmentLine.Type::Item; - SalesShipmentLine."No." := Any.AlphanumericText(20); - SalesShipmentLine.Quantity := ShopifyOrderLine.Quantity; - SalesShipmentLine."Shpfy Order Line Id" := ShopifyOrderLine."Line Id"; - SalesShipmentLine.Insert(false); - Commit(); + ShippingTest.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); // [WHEN] Invoke Shopify Sync Shipment to Shopify ExportShipments.CreateShopifyFulfillment(SalesShipmentHeader); @@ -750,28 +578,24 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure LogSalesShipmentNoFulfilmentCreatedInShopify() var SalesShipmentHeader: Record "Sales Shipment Header"; - Shop: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - ShopifyOrderHeader: Record "Shpfy Order Header"; ExportShipments: Codeunit "Shpfy Export Shipments"; - ShpfyInitializeTest: Codeunit "Shpfy Initialize Test"; ShippingTest: Codeunit "Shpfy Shipping Test"; SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; ShopifyOrderId: BigInteger; - LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; begin // [SCENARIO] Log skipped record when sales shipment is exported with no fulfillment created in shopify. + Initialize(); - // [GIVEN] Sales shipment, shopify order and shopify fulfilment - Shop := ShpfyInitializeTest.CreateShop(); - ShopifyOrderId := Any.IntegerInRange(10000, 999999); + // [GIVEN] Shopify order with line DeliveryMethodType := DeliveryMethodType::" "; - ShopifyOrderId := ShippingTest.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); - ShopifyOrderHeader.Get(ShopifyOrderId); - ShopifyOrderHeader."Shop Code" := Shop.Code; - ShopifyOrderHeader.Modify(false); + ShopifyOrderId := CreateShopifyOrder(Shop, DeliveryMethodType); + + // [GIVEN] Shopify fulfilment related to shopify order ShippingTest.CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); + + // [GIVEN] Sales shipment related to shopify order ShippingTest.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); // [WHEN] Invoke Shopify Sync Shipment to Shopify @@ -782,13 +606,13 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual('No corresponding fulfillment lines found.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Fullfilment was not created in Shopify.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] procedure UnitTestSkipLoggingWhenShopHasLoggingModeDisabled() var - Shop: Record "Shpfy Shop"; + SkippedRecord: Record "Shpfy Skipped Record"; SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; RecordID: RecordID; @@ -796,16 +620,16 @@ codeunit 139581 "Shpfy Skipped Record Log Test" TableId: Integer; begin // [SCENARIO] Skip logging when setup in shop for logging is Disabled. + Initialize(); // [GIVEN] Shop with logging mode = Disabled. - Shop.Init(); - Shop.Code := Any.AlphanumericText(20); - Shop."Logging Mode" := Enum::"Shpfy Logging Mode"::Disabled; - Shop.Insert(false); - - // [WHEN] Invoke Skip Record Management + CreateShopWithDisabledLogging(Shop); + // [GIVEN] Random Shopify Id ShopifyId := Any.IntegerInRange(10000, 999999); + // [GIVEN] Random Table Id TableId := Any.IntegerInRange(1, 50000); + + // [WHEN] Invoke Skip Record Management SkipRecordMgt.LogSkippedRecord(ShopifyId, TableId, RecordID, Any.AlphabeticText(250), Shop); // [THEN] No record is created in shopify skipped record table. @@ -814,6 +638,18 @@ codeunit 139581 "Shpfy Skipped Record Log Test" LibraryAssert.IsTrue(SkippedRecord.IsEmpty(), 'Skipped record is created'); end; + local procedure Initialize() + begin + if IsInitialized then + exit; + Shop := ShpfyInitializeTest.CreateShop(); + Shop."Can Update Shopify Customer" := true; + Shop."Can Update Shopify Products" := true; + Shop.Modify(false); + + IsInitialized := true; + end; + local procedure CreateShpfyProduct(var ShopifyProduct: Record "Shpfy Product"; ItemSystemId: Guid; ShopCode: Code[20]; var ShopifyVariant: Record "Shpfy Variant") begin Randomize(); @@ -839,11 +675,12 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShpfyProduct(ShopifyProduct, ItemSystemId, ShopCode, ShopifyVariant); end; - local procedure CreateSalesInvoiceHeader(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]) + local procedure CreateSalesInvoiceHeader(var SalesInvoiceHeader: Record "Sales Invoice Header"; CustomerNo: Code[20]; PaymentTermsCode: Code[10]) begin SalesInvoiceHeader.Init(); SalesInvoiceHeader."No." := Any.AlphanumericText(20); SalesInvoiceHeader."Bill-to Customer No." := CustomerNo; + SalesInvoiceHeader."Payment Terms Code" := PaymentTermsCode; SalesInvoiceHeader.Insert(false); end; @@ -883,6 +720,117 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesShipmentHeader.Insert(false); end; + local procedure CreateShopWithDisabledLogging(var Shop: Record "Shpfy Shop") + begin + CreateShop(Shop, ''); + Shop."Logging Mode" := Enum::"Shpfy Logging Mode"::Disabled; + Shop.Modify(false); + end; + + local procedure CreateShopifyOrder(Shop: Record "Shpfy Shop"; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger + var + ShopifyOrderHeader: Record "Shpfy Order Header"; + ShippingTest: Codeunit "Shpfy Shipping Test"; + LocationId: BigInteger; + ShopifyOrderId: BigInteger; + begin + ShopifyOrderId := ShippingTest.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); + ShopifyOrderHeader.Get(ShopifyOrderId); + ShopifyOrderHeader."Shop Code" := Shop.Code; + ShopifyOrderHeader.Modify(false); + exit(ShopifyOrderId); + end; + + local procedure CreateShopifyCustomer(Customer: Record Customer) + var + ShopifyCustomer: Record "Shpfy Customer"; + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + begin + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Modify(false); + end; + + local procedure CreateRandomCustomer(var Customer: Record Customer) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer.Insert(false); + end; + + local procedure SetCustomerAsDefaultForShop(var Shop: Record "Shpfy Shop"; Customer: Record Customer) + begin + Shop."Default Customer No." := Customer."No."; + Shop.Modify(false); + end; + + local procedure CreateShopifyCustomerTemplate(var ShopifyCustomerTemplate: Record "Shpfy Customer Template"; Shop: Record "Shpfy Shop"; Customer: Record Customer) + begin + ShopifyCustomerTemplate.Init(); + ShopifyCustomerTemplate."Shop Code" := Shop.Code; + ShopifyCustomerTemplate."Default Customer No." := Customer."No."; + ShopifyCustomerTemplate.Insert(false); + end; + + local procedure CreateSalesShipmentLine(SalesShipmentNo: Code[20]) + var + SalesShipmentLine: Record "Sales Shipment Line"; + begin + SalesShipmentLine.Init(); + SalesShipmentLine."Document No." := SalesShipmentNo; + SalesShipmentLine."Line No." := 10000; + SalesShipmentLine."No." := Any.AlphanumericText(20); + SalesShipmentLine.Type := SalesShipmentLine.Type::Item; + SalesShipmentLine.Quantity := Any.IntegerInRange(1, 100); + SalesShipmentLine.Insert(false); + end; + + local procedure CreateBlockedItem(var Item: Record Item) + begin + Item.Init(); + Item."No." := Any.AlphanumericText(20); + Item.Blocked := true; + Item."Sales Blocked" := true; + Item.Insert(false); + end; + + local procedure CreateShopifyCustomerWithRandomGuid(var ShpfyCustomer: Record "Shpfy Customer") + var + CustomerInitTest: Codeunit "Shpfy Customer Init Test"; + begin + CustomerInitTest.CreateShopifyCustomer(ShpfyCustomer); + ShpfyCustomer."Customer SystemId" := CreateGuid(); + end; + + local procedure SetActionForRemovedProducts(var Shop: Record "Shpfy Shop"; ShpfyRemoveProductAction: Enum Microsoft.Integration.Shopify."Shpfy Remove Product Action") + begin + Shop."Action for Removed Products" := ShpfyRemoveProductAction; + Shop.Modify(false); + end; + + local procedure CreateSHopifyProductWithStatus(var Item: Record Item; var ShpfyProduct: Record "Shpfy Product"; ShpfyProductStatus: Enum Microsoft.Integration.Shopify."Shpfy Product Status") + begin + CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); + ShpfyProduct.Status := ShpfyProductStatus; + ShpfyProduct.Modify(false); + end; + + local procedure CreateCustomerWithEmail(var Customer: Record Customer; EmailAdress: Text) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."E-Mail" := EmailAdress; + Customer.Insert(true); + end; + + local procedure CreateShop(var Shop: Record "Shpfy Shop"; DefaultCustomer: Code[20]) + begin + Shop.Init(); + Shop.Code := Any.AlphanumericText(20); + Shop."Default Customer No." := DefaultCustomer; + Shop.Insert(false); + end; + [RequestPageHandler] procedure SyncPostedShipmentsToShopify(var SyncShipmToShopify: TestRequestPage "Shpfy Sync Shipm. to Shopify") begin diff --git a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al index ad1338d0a7..4feaeb2ee4 100644 --- a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al @@ -54,6 +54,7 @@ codeunit 139606 "Shpfy Shipping Test" OrderHeader: Record "Shpfy Order Header"; OrderLine: Record "Shpfy Order Line"; begin + Any.SetDefaultSeed(); Clear(OrderHeader); OrderHeader."Shopify Order Id" := Any.IntegerInRange(10000, 99999); OrderHeader.Insert(); From e3b5e6ceea71df4d2ef376ee912502e348c5cfd1 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 11 Oct 2024 15:56:22 +0200 Subject: [PATCH 23/32] tests refactor and pr comments resolve --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 2 +- .../ShpfyPostedInvoiceExport.Codeunit.al | 2 +- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 10 ++--- .../Logs/Pages/ShpfySkippedRecords.Page.al | 43 +++---------------- .../Logs/Tables/ShpfySkippedRecord.Table.al | 42 +++++------------- .../Codeunits/ShpfyProductExport.Codeunit.al | 12 +++--- .../ShpfyExportShipments.Codeunit.al | 4 +- .../Reports/ShpfySyncShipmToShopify.Report.al | 4 +- .../ShpfySkippedRecordLogTest.Codeunit.al | 6 +-- 9 files changed, 34 insertions(+), 91 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index de7d7d55dd..f2aaf7097a 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -304,7 +304,7 @@ codeunit 30116 "Shpfy Customer Export" begin ShopifyCustomer.Get(CustomerID); if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Database::"Shpfy Customer", Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); exit; // An other customer with the same e-mail or phone is the source of it. end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 355fa86692..2cc0e887de 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -90,7 +90,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; CustomerNotExistInShopifyLbl: Label 'Customer not existing as Shopify company or customer.'; - PaymentTermsNotExistLbl: Label 'Payment terms %1 does not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; + PaymentTermsNotExistLbl: Label 'Payment terms %1 do not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; begin diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index 093e0d7430..e30fb66bcc 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -16,7 +16,7 @@ codeunit 30168 "Shpfy Skip Record Mgt." /// Record Id of the record. /// Reason for skipping the record. /// Shop record. - internal procedure LogSkippedRecord(ShopifyId: BigInteger; TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") + internal procedure LogSkippedRecord(ShopifyId: BigInteger; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") var ShpfySkippedRecord: Record "Shpfy Skipped Record"; begin @@ -24,17 +24,15 @@ codeunit 30168 "Shpfy Skip Record Mgt." exit; ShpfySkippedRecord.Init(); ShpfySkippedRecord.Validate("Shopify Id", ShopifyId); - ShpfySkippedRecord.Validate("Table ID", TableId); + ShpfySkippedRecord.Validate("Table ID", RecordId.TableNo()); ShpfySkippedRecord.Validate("Record ID", RecordId); ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason); - ShpfySkippedRecord.Validate("Created On", CurrentDateTime); - ShpfySkippedRecord.Validate("Created Time", DT2Time(CurrentDateTime)); ShpfySkippedRecord.Insert(true); end; - internal procedure LogSkippedRecord(TableId: Integer; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") + internal procedure LogSkippedRecord(RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") begin - LogSkippedRecord(0, TableId, RecordId, SkippedReason, Shop); + LogSkippedRecord(0, RecordId, SkippedReason, Shop); end; } diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index a8fa0c0936..032f682be0 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -20,52 +20,19 @@ page 30165 "Shpfy Skipped Records" { repeater(General) { - field(EntryNo; Rec."Entry No.") - { - ApplicationArea = All; - ToolTip = 'Specifies the number of the entry, as assigned from the specific number series when the entry was created.'; - } - field("Shopify Id"; Rec."Shopify Id") - { - ApplicationArea = All; - ToolTip = 'Specifies the Shopify Id of the skipped record.'; - } - field("Table ID"; Rec."Table ID") - { - ApplicationArea = All; - ToolTip = 'Specifies the Table ID of the skipped record.'; - } - field("Table Name"; Rec."Table Name") - { - ApplicationArea = All; - ToolTip = 'Specifies the Table Name of the skipped record.'; - } + field(EntryNo; Rec."Entry No.") { } + field("Shopify Id"; Rec."Shopify Id") { } + field("Table ID"; Rec."Table ID") { } + field("Table Name"; Rec."Table Name") { } field(Description; Rec.Description) { - ApplicationArea = All; - ToolTip = 'Specifies the description of the skipped record.'; - trigger OnDrillDown() begin Rec.ShowPage(); end; } - field("Skipped Reason"; Rec."Skipped Reason") - { - ApplicationArea = All; - ToolTip = 'Specifies the reason why the record was skipped.'; - } - field("Created On"; Rec."Created On") - { - ApplicationArea = All; - ToolTip = 'Specifies the date and time when the record was created.'; - } - field("Created Time"; Rec."Created Time") - { - ApplicationArea = All; - ToolTip = 'Specifies the time when the record was created.'; - } + field("Skipped Reason"; Rec."Skipped Reason") { } } } } diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index a459b3fcbb..8d29084d44 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -9,7 +9,7 @@ using Microsoft.Utilities; table 30159 "Shpfy Skipped Record" { Caption = 'Shpfy Skipped Record'; - DataClassification = SystemMetadata; + DataClassification = CustomerContent; Access = Internal; fields @@ -18,17 +18,18 @@ table 30159 "Shpfy Skipped Record" { AutoIncrement = true; Caption = 'Entry No.'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the number of the entry, as assigned from the specific number series when the entry was created.'; + } field(2; "Shopify Id"; BigInteger) { Caption = 'Skipped Record Id'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the Shopify Id of the skipped record.'; } field(3; "Table ID"; Integer) { Caption = 'Table ID'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the Table ID of the skipped record.'; trigger OnValidate() begin @@ -38,12 +39,12 @@ table 30159 "Shpfy Skipped Record" field(4; "Table Name"; Text[250]) { Caption = 'Table Name'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the Table Name of the skipped record.'; } field(5; "Record ID"; RecordID) { Caption = 'Record ID'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the Record ID of the skipped record.'; trigger OnValidate() begin @@ -53,22 +54,12 @@ table 30159 "Shpfy Skipped Record" field(6; Description; Text[250]) { Caption = 'Description'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the description of the skipped record.'; } field(7; "Skipped Reason"; Text[250]) { Caption = 'Skipped Reason'; - DataClassification = SystemMetadata; - } - field(8; "Created On"; DateTime) - { - Caption = 'Created On'; - DataClassification = SystemMetadata; - } - field(9; "Created Time"; Time) - { - Caption = 'Created Time'; - DataClassification = SystemMetadata; + ToolTip = 'Specifies the reason why the record was skipped.'; } @@ -116,20 +107,9 @@ table 30159 "Shpfy Skipped Record" /// internal procedure ShowPage() var - TableMetadata: Record "Table Metadata"; PageManagement: Codeunit "Page Management"; - RecordId: RecordID; begin - RecordId := "Record ID"; - - if RecordID.TableNo() = 0 then - exit; - if not TableMetadata.Get(RecordID.TableNo()) then - exit; - - if not TableMetadata.DataIsExternal then begin - PageManagement.PageRun(RecordID); - exit; - end; + if "Record ID".TableNo() <> 0 then + PageManagement.PageRun("Record ID"); end; } diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index c6ae670621..c24921a5fe 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -321,7 +321,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", '', ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -358,7 +358,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -405,7 +405,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Database::Item, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -560,17 +560,17 @@ codeunit 30178 "Shpfy Product Export" case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsArchivedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsArchivedLbl, Shop); exit; end; Shop."Action for Removed Products"::StatusToDraft: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsDraftLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsDraftLbl, Shop); exit; end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Database::Item, Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsBlockedLbl, Shop); exit; end; end; diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 9a3991950e..75602207f0 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -57,11 +57,11 @@ codeunit 30190 "Shpfy Export Shipments" if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoFullfilmentCreatedInShopifyLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoFullfilmentCreatedInShopifyLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; end else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", Database::"Sales Shipment Header", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLinesLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLinesLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; SalesShipmentHeader.Modify(true); diff --git a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al index 3c092222c0..d478f10ea3 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al +++ b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al @@ -39,7 +39,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShipmentLine.SetRange(Type, ShipmentLine.Type::"Item"); ShipmentLine.SetFilter(Quantity, '>0'); if ShipmentLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", Database::"Sales Shipment Header", "Sales Shipment Header".RecordId, NoLinesApplicable, Shop); + SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, NoLinesApplicable, Shop); "Shpfy Fulfillment Id" := -2; Modify(); end else @@ -48,7 +48,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" FulfillmentOrdersAPI.GetShopifyFulfillmentOrdersFromShopifyOrder(Shop, "Sales Shipment Header"."Shpfy Order Id"); ExportShipments.CreateShopifyFulfillment("Sales Shipment Header"); end else - SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", Database::"Sales Shipment Header", "Sales Shipment Header".RecordId, StrSubstNo(ShopifyOrderNotExistsLbl, "Sales Shipment Header"."Shpfy Order Id"), Shop); + SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, StrSubstNo(ShopifyOrderNotExistsLbl, "Sales Shipment Header"."Shpfy Order Id"), Shop); end; } } diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 9106043c7b..86cfd6dc09 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -317,7 +317,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual(StrSubstNo('Payment terms %1 does not exist in Shopify.', PaymentTermsCode), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual(StrSubstNo('Payment terms %1 do not exist in Shopify.', PaymentTermsCode), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -626,11 +626,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShopWithDisabledLogging(Shop); // [GIVEN] Random Shopify Id ShopifyId := Any.IntegerInRange(10000, 999999); - // [GIVEN] Random Table Id - TableId := Any.IntegerInRange(1, 50000); // [WHEN] Invoke Skip Record Management - SkipRecordMgt.LogSkippedRecord(ShopifyId, TableId, RecordID, Any.AlphabeticText(250), Shop); + SkipRecordMgt.LogSkippedRecord(ShopifyId, RecordID, Any.AlphabeticText(250), Shop); // [THEN] No record is created in shopify skipped record table. SkippedRecord.SetRange("Shopify Id", ShopifyId); From adca60e13fa80e90af4ffb2561925f24fad27a49 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 11 Oct 2024 16:06:52 +0200 Subject: [PATCH 24/32] small refactors --- Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al | 1 - Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al | 2 -- .../app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al | 2 +- Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index 032f682be0..5b52eb895e 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -26,7 +26,6 @@ page 30165 "Shpfy Skipped Records" field("Table Name"; Rec."Table Name") { } field(Description; Rec.Description) { - trigger OnDrillDown() begin Rec.ShowPage(); diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index 8d29084d44..45eaa98e42 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -61,8 +61,6 @@ table 30159 "Shpfy Skipped Record" Caption = 'Skipped Reason'; ToolTip = 'Specifies the reason why the record was skipped.'; } - - } keys { diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index c24921a5fe..d4a71071d2 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -553,7 +553,7 @@ codeunit 30178 "Shpfy Product Export" RecordRef2: RecordRef; VariantAction: Option " ",Create,Update; ItemIsBlockedLbl: Label 'Item is blocked.'; - ItemIsDraftLbl: Label 'Shopify Product is draft.'; + ItemIsDraftLbl: Label 'Shopify Product is in draft status.'; ItemIsArchivedLbl: Label 'Shopify Product is archived.'; begin if ShopifyProduct.Get(ProductId) and Item.GetBySystemId(ShopifyProduct."Item SystemId") then begin diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 86cfd6dc09..ddea757758 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -170,7 +170,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord.SetRange("Record ID", Item.RecordId); SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Shopify Product is draft.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Shopify Product is in draft status.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] From 6b32486538600c6f8ceb2d37716c22584af478d2 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 14 Oct 2024 08:53:33 +0200 Subject: [PATCH 25/32] reafactors --- .../Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al | 2 +- Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al | 2 ++ Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 2cc0e887de..a52375f2bf 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -89,7 +89,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" var ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; - CustomerNotExistInShopifyLbl: Label 'Customer not existing as Shopify company or customer.'; + CustomerNotExistInShopifyLbl: Label 'Customer does not exists as Shopify company of customer.'; PaymentTermsNotExistLbl: Label 'Payment terms %1 do not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index 45eaa98e42..e57a8a2062 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -30,6 +30,7 @@ table 30159 "Shpfy Skipped Record" { Caption = 'Table ID'; ToolTip = 'Specifies the Table ID of the skipped record.'; + DataClassification = SystemMetadata; trigger OnValidate() begin @@ -40,6 +41,7 @@ table 30159 "Shpfy Skipped Record" { Caption = 'Table Name'; ToolTip = 'Specifies the Table Name of the skipped record.'; + DataClassification = SystemMetadata; } field(5; "Record ID"; RecordID) { diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index ddea757758..0e6c85afbd 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -287,7 +287,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Customer not existing as Shopify company or customer.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Customer does not exists as Shopify company of customer.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] From def03a787ec2efef3a7fb7b678a467a2e1ec60a5 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 14 Oct 2024 11:02:02 +0200 Subject: [PATCH 26/32] PR fixes --- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 2 +- .../ShpfyPostedInvoiceExport.Codeunit.al | 16 +-- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 6 ++ .../Reports/ShpfySyncShipmToShopify.Report.al | 4 +- .../Logs/ShpfySkippedRecordLogSub.Codeunit.al | 1 - .../ShpfySkippedRecordLogTest.Codeunit.al | 97 +++++++++---------- 6 files changed, 64 insertions(+), 62 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index f2aaf7097a..c1132d682d 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -91,7 +91,7 @@ codeunit 30116 "Shpfy Customer Export" EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShopifySkipRecordMgt.LogSkippedRecord(Database::Customer, Customer.RecordId, EmptyEmailAddressLbl, Shop); + ShopifySkipRecordMgt.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index a52375f2bf..de7a1a174d 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -89,7 +89,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" var ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; - CustomerNotExistInShopifyLbl: Label 'Customer does not exists as Shopify company of customer.'; + CustomerNotExistInShopifyLbl: Label 'Customer does not exists as Shopify company or customer.'; PaymentTermsNotExistLbl: Label 'Payment terms %1 do not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; @@ -98,23 +98,23 @@ codeunit 30362 "Shpfy Posted Invoice Export" if ShopifyCompany.IsEmpty() then begin ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCustomer.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop); exit(false); end; end; if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); exit(false); end; if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); exit(false); end; if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); exit(false); end; @@ -160,7 +160,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" begin SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Header", SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); exit(false); end; @@ -171,12 +171,12 @@ codeunit 30362 "Shpfy Posted Invoice Export" if SalesInvoiceLine.FindSet() then repeat if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); exit(false); end; if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then begin - SkipRecordMgt.LogSkippedRecord(Database::"Sales Invoice Line", SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); + SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); exit(false); end; until SalesInvoiceLine.Next() = 0; diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index e30fb66bcc..df6551573d 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -30,6 +30,12 @@ codeunit 30168 "Shpfy Skip Record Mgt." ShpfySkippedRecord.Insert(true); end; + /// + /// Creates log entry for skipped recordwith empty Shopify Id. + /// + /// Record Id of the record. + /// Reason for skipping the record. + /// Shop record. internal procedure LogSkippedRecord(RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") begin LogSkippedRecord(0, RecordId, SkippedReason, Shop); diff --git a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al index d478f10ea3..7c5f206ecf 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al +++ b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al @@ -32,14 +32,14 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; - NoLinesApplicable: Label 'No lines applicable for fulfillment.'; + NoLinesApplicableLbl: Label 'No lines applicable for fulfillment.'; ShopifyOrderNotExistsLbl: Label 'Shopify order %1 does not exist.', Comment = '%1 = Shopify Order Id'; begin ShipmentLine.SetRange("Document No.", "No."); ShipmentLine.SetRange(Type, ShipmentLine.Type::"Item"); ShipmentLine.SetFilter(Quantity, '>0'); if ShipmentLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, NoLinesApplicable, Shop); + SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, NoLinesApplicableLbl, Shop); "Shpfy Fulfillment Id" := -2; Modify(); end else diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al index 376cc2ab64..36fe59f879 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogSub.Codeunit.al @@ -1,6 +1,5 @@ codeunit 139583 "Shpfy Skipped Record Log Sub." { - SingleInstance = true; EventSubscriberInstance = Manual; var diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 0e6c85afbd..d106d190fc 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -22,8 +22,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; - ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; - ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when customer email is empty on customer export to shopify. Initialize(); @@ -32,13 +30,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateCustomerWithEmail(Customer, ''); // [WHEN] Invoke Shopify Customer Export - BindSubscription(ShpfySkippedRecordLogSub); - ShpfySkippedRecordLogSub.SetShopifyCustomerId(0); - ShpfyCustomerExport.SetShop(Shop); - ShpfyCustomerExport.SetCreateCustomers(true); - Customer.SetRange("No.", Customer."No."); - ShpfyCustomerExport.Run(Customer); - UnbindSubscription(ShpfySkippedRecordLogSub); + InvokeShopifyCustomerExport(Customer, 0); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); @@ -52,8 +44,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Customer: Record Customer; ShpfyCustomer: Record "Shpfy Customer"; SkippedRecord: Record "Shpfy Skipped Record"; - ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; - ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when customer with same email already exist on customer export to shopify. Initialize(); @@ -64,13 +54,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShopifyCustomerWithRandomGuid(ShpfyCustomer); // [WHEN] Invoke Shopify Customer Export - BindSubscription(ShpfySkippedRecordLogSub); - ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomer.Id); - ShpfyCustomerExport.SetShop(Shop); - ShpfyCustomerExport.SetCreateCustomers(true); - Customer.SetRange("No.", Customer."No."); - ShpfyCustomerExport.Run(Customer); - UnbindSubscription(ShpfySkippedRecordLogSub); + InvokeShopifyCustomerExport(Customer, ShpfyCustomer.Id); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Customer.RecordId); @@ -109,7 +93,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogProductItemBlockedAndProductArchived() var - Item: Record Item; ShpfyProduct: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; @@ -123,7 +106,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Item that is blocked. CreateBlockedItem(Item); // [GIVEN] Shpify Product with status archived. - CreateSHopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Archived); + CreateShopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Archived); // [WHEN] Invoke Shopify Product Export ProductExport.SetShop(Shop); @@ -157,7 +140,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateBlockedItem(Item); // [GIVEN] Shpify Product with status draft. - CreateSHopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Draft); + CreateShopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Draft); // [WHEN] Invoke Shopify Product Export BindSubscription(ShpfySkippedRecordLogSub); @@ -287,7 +270,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Customer does not exists as Shopify company of customer.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Customer does not exists as Shopify company or customer.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -324,9 +307,9 @@ codeunit 139581 "Shpfy Skipped Record Log Test" procedure UnitTestLogSalesInvoiceWithCustomerNoIsDefaultCustomerNo() var SalesInvoiceHeader: Record "Sales Invoice Header"; + ShopWithDefaultCustomerNo: Record "Shpfy Shop"; Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; - Shop2: Record "Shpfy Shop"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; PaymentTermsCode: Code[10]; begin @@ -338,16 +321,14 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Shopify Customer CreateShopifyCustomer(Customer); // [GIVEN] Shop with default customer no set. - CreateShop(Shop2, Customer."No."); + CreateShopWithDefCustomerNo(ShopWithDefaultCustomerNo, Customer."No."); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(Shop2.Code); - // [GIVEN] Shop with default customer no set. - SetCustomerAsDefaultForShop(Shop2, Customer); + PaymentTermsCode := CreatePaymentTerms(ShopWithDefaultCustomerNo.Code); // [GIVEN] Sales Invoice for default customer no. - CreateSalesInvoiceHeader(SalesInvoiceHeader, Shop2."Default Customer No.", PaymentTermsCode); + CreateSalesInvoiceHeader(SalesInvoiceHeader, ShopWithDefaultCustomerNo."Default Customer No.", PaymentTermsCode); // [WHEN] Invoke Shopify Posted Invoice Export - PostedInvoiceExport.SetShop(Shop2.Code); + PostedInvoiceExport.SetShop(ShopWithDefaultCustomerNo.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. @@ -362,7 +343,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesInvoiceHeader: Record "Sales Invoice Header"; Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; - Shop2: Record "Shpfy Shop"; + ShopWithCustTemplates: Record "Shpfy Shop"; ShopifyCustomerTemplate: Record "Shpfy Customer Template"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; PaymentTermsCode: Code[10]; @@ -372,25 +353,23 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Customer CreateRandomCustomer(Customer); - // [GIVEN] Shop - CreateShop(Shop2, ''); // [GIVEN] Shopify Customer CreateShopifyCustomer(Customer); + // [GIVEN] Shop with Shopify Customer Template for customer no. + CreateShopWithCustomerTemplate(ShopWithCustTemplates, ShopifyCustomerTemplate, Customer."No."); // [GIVEN] Payment Terms Code - PaymentTermsCode := CreatePaymentTerms(Shop2.Code); - // [GIVEN] Shopify Customer Template with customer no. - CreateShopifyCustomerTemplate(ShopifyCustomerTemplate, Shop2, Customer); + PaymentTermsCode := CreatePaymentTerms(ShopWithCustTemplates.Code); // [GIVEN] Sales Invoice for default customer no. CreateSalesInvoiceHeader(SalesInvoiceHeader, ShopifyCustomerTemplate."Default Customer No.", PaymentTermsCode); // [WHEN] Invoke Shopify Posted Invoice Export - PostedInvoiceExport.SetShop(Shop2.Code); + PostedInvoiceExport.SetShop(ShopWithCustTemplates.Code); PostedInvoiceExport.ExportPostedSalesInvoiceToShopify(SalesInvoiceHeader); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", Shop2.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", ShopWithCustTemplates.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -612,7 +591,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestSkipLoggingWhenShopHasLoggingModeDisabled() var - + ShopWithDisabledLogging: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; RecordID: RecordID; @@ -623,12 +602,12 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Initialize(); // [GIVEN] Shop with logging mode = Disabled. - CreateShopWithDisabledLogging(Shop); + CreateShopWithDisabledLogging(ShopWithDisabledLogging); // [GIVEN] Random Shopify Id ShopifyId := Any.IntegerInRange(10000, 999999); // [WHEN] Invoke Skip Record Management - SkipRecordMgt.LogSkippedRecord(ShopifyId, RecordID, Any.AlphabeticText(250), Shop); + SkipRecordMgt.LogSkippedRecord(ShopifyId, RecordID, Any.AlphabeticText(250), ShopWithDisabledLogging); // [THEN] No record is created in shopify skipped record table. SkippedRecord.SetRange("Shopify Id", ShopifyId); @@ -645,6 +624,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop."Can Update Shopify Products" := true; Shop.Modify(false); + Commit(); + IsInitialized := true; end; @@ -720,7 +701,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" local procedure CreateShopWithDisabledLogging(var Shop: Record "Shpfy Shop") begin - CreateShop(Shop, ''); + CreateShopWithDefCustomerNo(Shop, ''); Shop."Logging Mode" := Enum::"Shpfy Logging Mode"::Disabled; Shop.Modify(false); end; @@ -756,17 +737,12 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Customer.Insert(false); end; - local procedure SetCustomerAsDefaultForShop(var Shop: Record "Shpfy Shop"; Customer: Record Customer) - begin - Shop."Default Customer No." := Customer."No."; - Shop.Modify(false); - end; - local procedure CreateShopifyCustomerTemplate(var ShopifyCustomerTemplate: Record "Shpfy Customer Template"; Shop: Record "Shpfy Shop"; Customer: Record Customer) + local procedure CreateShopifyCustomerTemplate(var ShopifyCustomerTemplate: Record "Shpfy Customer Template"; Shop: Record "Shpfy Shop"; CustomerNo: Code[20]) begin ShopifyCustomerTemplate.Init(); ShopifyCustomerTemplate."Shop Code" := Shop.Code; - ShopifyCustomerTemplate."Default Customer No." := Customer."No."; + ShopifyCustomerTemplate."Default Customer No." := CustomerNo; ShopifyCustomerTemplate.Insert(false); end; @@ -806,7 +782,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop.Modify(false); end; - local procedure CreateSHopifyProductWithStatus(var Item: Record Item; var ShpfyProduct: Record "Shpfy Product"; ShpfyProductStatus: Enum Microsoft.Integration.Shopify."Shpfy Product Status") + local procedure CreateShopifyProductWithStatus(var Item: Record Item; var ShpfyProduct: Record "Shpfy Product"; ShpfyProductStatus: Enum Microsoft.Integration.Shopify."Shpfy Product Status") begin CreateShpfyProduct(ShpfyProduct, Item.SystemId, Shop.Code); ShpfyProduct.Status := ShpfyProductStatus; @@ -821,7 +797,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Customer.Insert(true); end; - local procedure CreateShop(var Shop: Record "Shpfy Shop"; DefaultCustomer: Code[20]) + local procedure CreateShopWithDefCustomerNo(var Shop: Record "Shpfy Shop"; DefaultCustomer: Code[20]) begin Shop.Init(); Shop.Code := Any.AlphanumericText(20); @@ -829,6 +805,27 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Shop.Insert(false); end; + local procedure InvokeShopifyCustomerExport(var Customer: Record Customer; ShpfyCustomerId: BigInteger) + var + ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; + ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + begin + BindSubscription(ShpfySkippedRecordLogSub); + if ShpfyCustomerId <> 0 then + ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomerId); + ShpfyCustomerExport.SetShop(Shop); + ShpfyCustomerExport.SetCreateCustomers(true); + Customer.SetRange("No.", Customer."No."); + ShpfyCustomerExport.Run(Customer); + UnbindSubscription(ShpfySkippedRecordLogSub); + end; + + local procedure CreateShopWithCustomerTemplate(var ShopWithCustTemplates: Record "Shpfy Shop"; var ShopifyCustomerTemplate: Record "Shpfy Customer Template"; CustomerNo: Code[20]) + begin + CreateShopWithDefCustomerNo(ShopWithCustTemplates, ''); + CreateShopifyCustomerTemplate(ShopifyCustomerTemplate, ShopWithCustTemplates, CustomerNo); + end; + [RequestPageHandler] procedure SyncPostedShipmentsToShopify(var SyncShipmToShopify: TestRequestPage "Shpfy Sync Shipm. to Shopify") begin From dc6c44381134578c2974c4ed890af0c8933016c2 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 15 Oct 2024 10:37:48 +0200 Subject: [PATCH 27/32] fix bug, move procedures to helper codeunit --- .../ShpfyPostedInvoiceExport.Codeunit.al | 1 + .../ShpfySkippedRecordLogTest.Codeunit.al | 19 ++-- .../Shipping/ShpfyShippingHelper.Codeunit.al | 86 +++++++++++++++++++ .../Shipping/ShpfyShippingTest.Codeunit.al | 86 +------------------ 4 files changed, 99 insertions(+), 93 deletions(-) create mode 100644 Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 3c7e3ec43d..0dc07c5e47 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -162,6 +162,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" InvalidQuantityLbl: Label 'Invalid quantity in sales invoice line.'; EmptyNoInLineLbl: Label 'No. field is empty in Sales Invoice Line.'; begin + SalesInvoiceLine.SetRange("Document No.", SalesInvoiceHeader."No."); SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index d106d190fc..99d2f673ba 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -391,11 +391,8 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShopifyCustomer(Customer); // [GIVEN] Payment Terms Code PaymentTermsCode := CreatePaymentTerms(Shop.Code); - // [GIVEN] Sales Invoice without sales line. + // [GIVEN] Sales Invoice without sales lines. CreateSalesInvoiceHeader(SalesInvoiceHeader, Customer."No.", PaymentTermsCode); - // [GIVEN] No existing sales lines. - if not SalesInvoiceLine.IsEmpty() then - SalesInvoiceLine.DeleteAll(false); // [WHEN] Invoke Shopify Posted Invoice Export PostedInvoiceExport.SetShop(Shop.Code); @@ -533,7 +530,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesShipmentHeader: Record "Sales Shipment Header"; SkippedRecord: Record "Shpfy Skipped Record"; ExportShipments: Codeunit "Shpfy Export Shipments"; - ShippingTest: Codeunit "Shpfy Shipping Test"; + ShippingHelper: Codeunit "Shpfy Shipping Helper"; ShopifyOrderId: BigInteger; begin // [SCENARIO] Log skipped record when sales shipment is export is skip because theres no fulfillment lines shopify. @@ -542,7 +539,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [GIVEN] Shopify order with line ShopifyOrderId := CreateshopifyOrder(Shop, Enum::"Shpfy Delivery Method Type"::" "); // [GIVEN] Posted shipment with line. - ShippingTest.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); + ShippingHelper.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); // [WHEN] Invoke Shopify Sync Shipment to Shopify ExportShipments.CreateShopifyFulfillment(SalesShipmentHeader); @@ -559,7 +556,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SalesShipmentHeader: Record "Sales Shipment Header"; SkippedRecord: Record "Shpfy Skipped Record"; ExportShipments: Codeunit "Shpfy Export Shipments"; - ShippingTest: Codeunit "Shpfy Shipping Test"; + ShippingHelper: Codeunit "Shpfy Shipping Helper"; SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; ShopifyOrderId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; @@ -572,10 +569,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyOrderId := CreateShopifyOrder(Shop, DeliveryMethodType); // [GIVEN] Shopify fulfilment related to shopify order - ShippingTest.CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); + ShippingHelper.CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); // [GIVEN] Sales shipment related to shopify order - ShippingTest.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); + ShippingHelper.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); // [WHEN] Invoke Shopify Sync Shipment to Shopify BindSubscription(SkippedRecordLogSub); @@ -709,11 +706,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" local procedure CreateShopifyOrder(Shop: Record "Shpfy Shop"; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger var ShopifyOrderHeader: Record "Shpfy Order Header"; - ShippingTest: Codeunit "Shpfy Shipping Test"; + ShippingHelper: Codeunit "Shpfy Shipping Helper"; LocationId: BigInteger; ShopifyOrderId: BigInteger; begin - ShopifyOrderId := ShippingTest.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); + ShopifyOrderId := ShippingHelper.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); ShopifyOrderHeader.Get(ShopifyOrderId); ShopifyOrderHeader."Shop Code" := Shop.Code; ShopifyOrderHeader.Modify(false); diff --git a/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al b/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al new file mode 100644 index 0000000000..df4d7391c6 --- /dev/null +++ b/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al @@ -0,0 +1,86 @@ +codeunit 139618 "Shpfy Shipping Helper" +{ + internal procedure CreateRandomShopifyOrder(LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger + var + OrderHeader: Record "Shpfy Order Header"; + OrderLine: Record "Shpfy Order Line"; + Any: Codeunit Any; + begin + Any.SetDefaultSeed(); + Clear(OrderHeader); + OrderHeader."Shopify Order Id" := Any.IntegerInRange(10000, 99999); + OrderHeader.Insert(); + + Clear(OrderLine); + OrderLine."Shopify Order Id" := OrderHeader."Shopify Order Id"; + OrderLine."Shopify Product Id" := Any.IntegerInRange(10000, 99999); + OrderLine."Shopify Variant Id" := Any.IntegerInRange(10000, 99999); + OrderLine."Line Id" := Any.IntegerInRange(10000, 99999); + OrderLine.Quantity := Any.IntegerInRange(1, 10); + OrderLine."Location Id" := LocationId; + OrderLine."Delivery Method Type" := DeliveryMethodType; + OrderLine.Insert(); + + exit(OrderHeader."Shopify Order Id"); + end; + + internal procedure CreateShopifyFulfillmentOrder(ShopifyOrderId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger + var + OrderLine: Record "Shpfy Order Line"; + FulfillmentOrderHeader: Record "Shpfy FulFillment Order Header"; + FulfillmentOrderLine: Record "Shpfy FulFillment Order Line"; + Any: Codeunit Any; + begin + Any.SetDefaultSeed(); + Clear(FulfillmentOrderHeader); + FulfillmentOrderHeader."Shopify Fulfillment Order Id" := Any.IntegerInRange(10000, 99999); + FulfillmentOrderHeader."Shopify Order Id" := ShopifyOrderId; + FulfillmentOrderHeader."Delivery Method Type" := FulfillmentOrderHeader."Delivery Method Type"::Shipping; + FulfillmentOrderHeader.Insert(); + + OrderLine.Reset(); + OrderLine.SetRange("Shopify Order Id", ShopifyOrderId); + if OrderLine.FindSet() then + repeat + Clear(FulfillmentOrderLine); + FulfillmentOrderLine."Shopify Fulfillment Order Id" := FulfillmentOrderHeader."Shopify Fulfillment Order Id"; + FulfillmentOrderLine."Shopify Fulfillm. Ord. Line Id" := Any.IntegerInRange(10000, 99999); + FulfillmentOrderLine."Shopify Order Id" := FulfillmentOrderHeader."Shopify Order Id"; + FulfillmentOrderLine."Shopify Product Id" := OrderLine."Shopify Product Id"; + FulfillmentOrderLine."Shopify Variant Id" := OrderLine."Shopify Variant Id"; + FulfillmentOrderLine."Remaining Quantity" := OrderLine.Quantity; + FulfillmentOrderLine."Shopify Location Id" := OrderLine."Location Id"; + FulfillmentOrderLine."Delivery Method Type" := DeliveryMethodType; + FulfillmentOrderLine.Insert(); + until OrderLine.Next() = 0; + + exit(FulfillmentOrderHeader."Shopify Fulfillment Order Id"); + end; + + internal procedure CreateRandomSalesShipment(var SalesShipmentHeader: Record "Sales Shipment Header"; ShopifyOrderId: BigInteger) + var + SalesShipmentLine: Record "Sales Shipment Line"; + OrderLine: Record "Shpfy Order Line"; + Any: Codeunit Any; + begin + Any.SetDefaultSeed(); + Clear(SalesShipmentHeader); + SalesShipmentHeader."No." := Any.AlphanumericText(MaxStrLen(SalesShipmentHeader."No.")); + SalesShipmentHeader."Shpfy Order Id" := ShopifyOrderId; + SalesShipmentHeader."Package Tracking No." := Any.AlphanumericText(MaxStrLen(SalesShipmentHeader."Package Tracking No.")); + SalesShipmentHeader.Insert(); + + OrderLine.Reset(); + OrderLine.SetRange("Shopify Order Id", ShopifyOrderId); + if OrderLine.FindSet() then + repeat + Clear(SalesShipmentLine); + SalesShipmentLine."Document No." := SalesShipmentHeader."No."; + SalesShipmentLine.Type := SalesShipmentLine.type::Item; + SalesShipmentLine."No." := Any.AlphanumericText(MaxStrLen(SalesShipmentLine."No.")); + SalesShipmentLine."Shpfy Order Line Id" := OrderLine."Line Id"; + SalesShipmentLine.Quantity := OrderLine.Quantity; + SalesShipmentLine.Insert(); + until OrderLine.Next() = 0; + end; +} diff --git a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al index 4feaeb2ee4..2a412294f6 100644 --- a/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Shipping/ShpfyShippingTest.Codeunit.al @@ -15,6 +15,7 @@ codeunit 139606 "Shpfy Shipping Test" Shop: Record "Shpfy Shop"; ExportShipments: Codeunit "Shpfy Export Shipments"; JsonHelper: Codeunit "Shpfy Json Helper"; + ShippingHelper: Codeunit "Shpfy Shipping Helper"; DeliveryMethodType: Enum "Shpfy Delivery Method Type"; FulfillmentRequest: Text; JFulfillment: JsonObject; @@ -29,9 +30,9 @@ codeunit 139606 "Shpfy Shipping Test" Shop.Init(); LocationId := Any.IntegerInRange(10000, 99999); DeliveryMethodType := DeliveryMethodType::Shipping; - ShopifyOrderId := CreateRandomShopifyOrder(LocationId, DeliveryMethodType); - ShopifyFulfillmentOrderId := CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); - CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); + ShopifyOrderId := ShippingHelper.CreateRandomShopifyOrder(LocationId, DeliveryMethodType); + ShopifyFulfillmentOrderId := ShippingHelper.CreateShopifyFulfillmentOrder(ShopifyOrderId, DeliveryMethodType); + ShippingHelper.CreateRandomSalesShipment(SalesShipmentHeader, ShopifyOrderId); // [WHEN] Invoke the function CreateFulfillmentRequest() FulfillmentRequest := ExportShipments.CreateFulfillmentOrderRequest(SalesShipmentHeader, Shop, LocationId, DeliveryMethodType); @@ -48,83 +49,4 @@ codeunit 139606 "Shpfy Shipping Test" LibraryAssert.AreEqual(SalesShipmentLine.Quantity, JsonHelper.GetValueAsDecimal(JLineItem, 'quantity'), 'quanity check'); end; end; - - internal procedure CreateRandomShopifyOrder(LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger - var - OrderHeader: Record "Shpfy Order Header"; - OrderLine: Record "Shpfy Order Line"; - begin - Any.SetDefaultSeed(); - Clear(OrderHeader); - OrderHeader."Shopify Order Id" := Any.IntegerInRange(10000, 99999); - OrderHeader.Insert(); - - Clear(OrderLine); - OrderLine."Shopify Order Id" := OrderHeader."Shopify Order Id"; - OrderLine."Shopify Product Id" := Any.IntegerInRange(10000, 99999); - OrderLine."Shopify Variant Id" := Any.IntegerInRange(10000, 99999); - OrderLine."Line Id" := Any.IntegerInRange(10000, 99999); - OrderLine.Quantity := Any.IntegerInRange(1, 10); - OrderLine."Location Id" := LocationId; - OrderLine."Delivery Method Type" := DeliveryMethodType; - OrderLine.Insert(); - - exit(OrderHeader."Shopify Order Id"); - end; - - internal procedure CreateShopifyFulfillmentOrder(ShopifyOrderId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger - var - OrderLine: Record "Shpfy Order Line"; - FulfillmentOrderHeader: Record "Shpfy FulFillment Order Header"; - FulfillmentOrderLine: Record "Shpfy FulFillment Order Line"; - begin - Clear(FulfillmentOrderHeader); - FulfillmentOrderHeader."Shopify Fulfillment Order Id" := Any.IntegerInRange(10000, 99999); - FulfillmentOrderHeader."Shopify Order Id" := ShopifyOrderId; - FulfillmentOrderHeader."Delivery Method Type" := FulfillmentOrderHeader."Delivery Method Type"::Shipping; - FulfillmentOrderHeader.Insert(); - - OrderLine.Reset(); - OrderLine.SetRange("Shopify Order Id", ShopifyOrderId); - if OrderLine.FindSet() then - repeat - Clear(FulfillmentOrderLine); - FulfillmentOrderLine."Shopify Fulfillment Order Id" := FulfillmentOrderHeader."Shopify Fulfillment Order Id"; - FulfillmentOrderLine."Shopify Fulfillm. Ord. Line Id" := Any.IntegerInRange(10000, 99999); - FulfillmentOrderLine."Shopify Order Id" := FulfillmentOrderHeader."Shopify Order Id"; - FulfillmentOrderLine."Shopify Product Id" := OrderLine."Shopify Product Id"; - FulfillmentOrderLine."Shopify Variant Id" := OrderLine."Shopify Variant Id"; - FulfillmentOrderLine."Remaining Quantity" := OrderLine.Quantity; - FulfillmentOrderLine."Shopify Location Id" := OrderLine."Location Id"; - FulfillmentOrderLine."Delivery Method Type" := DeliveryMethodType; - FulfillmentOrderLine.Insert(); - until OrderLine.Next() = 0; - - exit(FulfillmentOrderHeader."Shopify Fulfillment Order Id"); - end; - - internal procedure CreateRandomSalesShipment(var SalesShipmentHeader: Record "Sales Shipment Header"; ShopifyOrderId: BigInteger) - var - SalesShipmentLine: Record "Sales Shipment Line"; - OrderLine: Record "Shpfy Order Line"; - begin - Clear(SalesShipmentHeader); - SalesShipmentHeader."No." := Any.AlphanumericText(MaxStrLen(SalesShipmentHeader."No.")); - SalesShipmentHeader."Shpfy Order Id" := ShopifyOrderId; - SalesShipmentHeader."Package Tracking No." := Any.AlphanumericText(MaxStrLen(SalesShipmentHeader."Package Tracking No.")); - SalesShipmentHeader.Insert(); - - OrderLine.Reset(); - OrderLine.SetRange("Shopify Order Id", ShopifyOrderId); - if OrderLine.FindSet() then - repeat - Clear(SalesShipmentLine); - SalesShipmentLine."Document No." := SalesShipmentHeader."No."; - SalesShipmentLine.Type := SalesShipmentLine.type::Item; - SalesShipmentLine."No." := Any.AlphanumericText(MaxStrLen(SalesShipmentLine."No.")); - SalesShipmentLine."Shpfy Order Line Id" := OrderLine."Line Id"; - SalesShipmentLine.Quantity := OrderLine.Quantity; - SalesShipmentLine.Insert(); - until OrderLine.Next() = 0; - end; } \ No newline at end of file From 6f3e4c87c08d20dff62561ad7c7f20256f35390e Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 25 Oct 2024 09:10:38 +0200 Subject: [PATCH 28/32] Renumber objects, add table to permissionsets --- .../app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al | 4 ++-- .../W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al | 4 ++-- .../Shopify/app/src/PermissionSets/ShpfyEdit.PermissionSet.al | 1 + .../Shopify/app/src/PermissionSets/ShpfyRead.PermissionSet.al | 1 + Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index df6551573d..d9726a2339 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -1,9 +1,9 @@ namespace Microsoft.Integration.Shopify; /// -/// Codeunit Shpfy Skip Record Mgt. (ID 30168). +/// Codeunit Shpfy Skip Record Mgt. (ID 30313). /// -codeunit 30168 "Shpfy Skip Record Mgt." +codeunit 30313 "Shpfy Skip Record Mgt." { Access = Internal; Permissions = tabledata "Shpfy Skipped Record" = rimd; diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index 5b52eb895e..d192927f60 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -1,9 +1,9 @@ namespace Microsoft.Integration.Shopify; /// -/// Page Shpfy Skipped Records (ID 30165). +/// Page Shpfy Skipped Records (ID 30166). /// -page 30165 "Shpfy Skipped Records" +page 30166 "Shpfy Skipped Records" { ApplicationArea = All; Caption = 'Shopify Skipped Records'; diff --git a/Apps/W1/Shopify/app/src/PermissionSets/ShpfyEdit.PermissionSet.al b/Apps/W1/Shopify/app/src/PermissionSets/ShpfyEdit.PermissionSet.al index d8296da1f9..b5b9defb15 100644 --- a/Apps/W1/Shopify/app/src/PermissionSets/ShpfyEdit.PermissionSet.al +++ b/Apps/W1/Shopify/app/src/PermissionSets/ShpfyEdit.PermissionSet.al @@ -63,6 +63,7 @@ permissionset 30102 "Shpfy - Edit" tabledata "Shpfy Shop Collection Map" = IMD, tabledata "Shpfy Shop Inventory" = IMD, tabledata "Shpfy Shop Location" = IMD, + tabledata "Shpfy Skipped Record" = IMD, tabledata "Shpfy Synchronization Info" = IMD, tabledata "Shpfy Tag" = IMD, tabledata "Shpfy Tax Area" = IMD, diff --git a/Apps/W1/Shopify/app/src/PermissionSets/ShpfyRead.PermissionSet.al b/Apps/W1/Shopify/app/src/PermissionSets/ShpfyRead.PermissionSet.al index 2fab53a2b8..a41a5b602e 100644 --- a/Apps/W1/Shopify/app/src/PermissionSets/ShpfyRead.PermissionSet.al +++ b/Apps/W1/Shopify/app/src/PermissionSets/ShpfyRead.PermissionSet.al @@ -63,6 +63,7 @@ permissionset 30100 "Shpfy - Read" tabledata "Shpfy Shop Collection Map" = R, tabledata "Shpfy Shop Inventory" = R, tabledata "Shpfy Shop Location" = R, + tabledata "Shpfy Skipped Record" = R, tabledata "Shpfy Synchronization Info" = R, tabledata "Shpfy Tag" = R, tabledata "Shpfy Tax Area" = R, diff --git a/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al b/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al index df4d7391c6..e10cfceb43 100644 --- a/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al +++ b/Apps/W1/Shopify/test/Shipping/ShpfyShippingHelper.Codeunit.al @@ -1,4 +1,4 @@ -codeunit 139618 "Shpfy Shipping Helper" +codeunit 139614 "Shpfy Shipping Helper" { internal procedure CreateRandomShopifyOrder(LocationId: BigInteger; DeliveryMethodType: Enum "Shpfy Delivery Method Type"): BigInteger var From 713a726690e27d6e47ba926a3861d99a88281508 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 25 Oct 2024 16:36:17 +0200 Subject: [PATCH 29/32] PR fixes --- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 12 +++++- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 6 +-- .../ShpfyPostedInvoiceExport.Codeunit.al | 4 +- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 4 +- .../Logs/Pages/ShpfySkippedRecords.Page.al | 40 +++++++++++++++++-- .../Logs/Tables/ShpfySkippedRecord.Table.al | 38 ++++++++++++++---- .../Codeunits/ShpfyProductExport.Codeunit.al | 20 +++++----- .../ShpfyExportShipments.Codeunit.al | 2 +- .../Reports/ShpfySyncShipmToShopify.Report.al | 2 +- .../ShpfySkippedRecordLogTest.Codeunit.al | 14 +++---- 10 files changed, 103 insertions(+), 39 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al index cf65199341..2415447a1f 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -1,5 +1,6 @@ namespace Microsoft.Integration.Shopify; +using Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; using Microsoft.Foundation.Company; using Microsoft.Foundation.Address; @@ -36,6 +37,7 @@ codeunit 30284 "Shpfy Company Export" Shop: Record "Shpfy Shop"; CompanyAPI: Codeunit "Shpfy Company API"; CatalogAPI: Codeunit "Shpfy Catalog API"; + ShpfySkipRecord: Codeunit "Shpfy Skip Record"; CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; @@ -44,9 +46,12 @@ codeunit 30284 "Shpfy Company Export" ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; CompanyLocation: Record "Shpfy Company Location"; + EmptyEmailAddressLbl: Label 'Customer (Company) has no e-mail address.'; begin - if Customer."E-Mail" = '' then + if Customer."E-Mail" = '' then begin + ShpfySkipRecord.LogSkippedRecord(Customer.RecordId, 'Customer does not have an email address.', Shop); exit; + end; if CreateCompanyMainContact(Customer, ShopifyCustomer) then if FillInShopifyCompany(Customer, ShopifyCompany, CompanyLocation) then @@ -180,10 +185,13 @@ codeunit 30284 "Shpfy Company Export" var ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; + CompanyWithPhoneNoOrEmailExistsLbl: Label 'Company already exists with the same e-mail or phone.'; begin ShopifyCompany.Get(CompanyId); - if ShopifyCompany."Customer SystemId" <> Customer.SystemId then + if ShopifyCompany."Customer SystemId" <> Customer.SystemId then begin + ShpfySkipRecord.LogSkippedRecord(ShopifyCompany.Id, Customer.RecordId, CompanyWithPhoneNoOrEmailExistsLbl, Shop); exit; + end; CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); CompanyLocation.FindFirst(); diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index df102e01ce..3403047aee 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -39,7 +39,7 @@ codeunit 30116 "Shpfy Customer Export" var Shop: Record "Shpfy Shop"; CustomerApi: Codeunit "Shpfy Customer API"; - ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + ShopifySkipRecord: Codeunit "Shpfy Skip Record"; CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; @@ -91,7 +91,7 @@ codeunit 30116 "Shpfy Customer Export" EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShopifySkipRecordMgt.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; @@ -304,7 +304,7 @@ codeunit 30116 "Shpfy Customer Export" begin ShopifyCustomer.Get(CustomerID); if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); exit; // An other customer with the same e-mail or phone is the source of it. end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 0dc07c5e47..4aefa5c514 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -17,7 +17,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" DraftOrdersAPI: Codeunit "Shpfy Draft Orders API"; FulfillmentAPI: Codeunit "Shpfy Fulfillment API"; JsonHelper: Codeunit "Shpfy Json Helper"; - SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + SkipRecordMgt: Codeunit "Shpfy Skip Record"; trigger OnRun() begin @@ -96,7 +96,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" CustomerNotExistInShopifyLbl: Label 'Customer does not exists as Shopify company or customer.'; PaymentTermsNotExistLbl: Label 'Payment terms %1 do not exist in Shopify.', Comment = '%1 = Payment Terms Code.'; CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.'; - CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; + CustomerTemplateExistsLbl: Label 'Shopify customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code'; begin ShopifyCompany.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCompany.IsEmpty() then begin diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index d9726a2339..082d171178 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -1,9 +1,9 @@ namespace Microsoft.Integration.Shopify; /// -/// Codeunit Shpfy Skip Record Mgt. (ID 30313). +/// Codeunit Shpfy Skip Record (ID 30313). /// -codeunit 30313 "Shpfy Skip Record Mgt." +codeunit 30313 "Shpfy Skip Record" { Access = Internal; Permissions = tabledata "Shpfy Skipped Record" = rimd; diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index d192927f60..6914f2be15 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -20,7 +20,6 @@ page 30166 "Shpfy Skipped Records" { repeater(General) { - field(EntryNo; Rec."Entry No.") { } field("Shopify Id"; Rec."Shopify Id") { } field("Table ID"; Rec."Table ID") { } field("Table Name"; Rec."Table Name") { } @@ -40,7 +39,18 @@ page 30166 "Shpfy Skipped Records" { area(Promoted) { - actionref(Show_Promoted; Show) { } + group(Category_Process) + { + actionref(Show_Promoted; Show) { } + } + + group(Category_Category4) + { + Caption = 'Log Entries'; + + actionref(Delete7days_Promoted; Delete7days) { } + actionref(Delete0days_Promoted; Delete0days) { } + } } area(Processing) { @@ -56,6 +66,30 @@ page 30166 "Shpfy Skipped Records" Rec.ShowPage(); end; } + action(Delete7days) + { + ApplicationArea = All; + Caption = 'Delete Entries Older Than 7 Days'; + Image = ClearLog; + ToolTip = 'Clear the list of log entries that are older than 7 days.'; + + trigger OnAction(); + begin + Rec.DeleteEntries(7); + end; + } + action(Delete0days) + { + ApplicationArea = All; + Caption = 'Delete All Entries'; + Image = Delete; + ToolTip = 'Clear the list of all log entries.'; + + trigger OnAction(); + begin + Rec.DeleteEntries(0); + end; + } } } -} \ No newline at end of file +} diff --git a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al index e57a8a2062..90734c6c31 100644 --- a/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al +++ b/Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al @@ -23,13 +23,13 @@ table 30159 "Shpfy Skipped Record" } field(2; "Shopify Id"; BigInteger) { - Caption = 'Skipped Record Id'; + Caption = 'Shopify Id'; ToolTip = 'Specifies the Shopify Id of the skipped record.'; } - field(3; "Table ID"; Integer) + field(3; "Table Id"; Integer) { - Caption = 'Table ID'; - ToolTip = 'Specifies the Table ID of the skipped record.'; + Caption = 'Table Id'; + ToolTip = 'Specifies the Table Id of the skipped record.'; DataClassification = SystemMetadata; trigger OnValidate() @@ -40,13 +40,13 @@ table 30159 "Shpfy Skipped Record" field(4; "Table Name"; Text[250]) { Caption = 'Table Name'; - ToolTip = 'Specifies the Table Name of the skipped record.'; + ToolTip = 'Specifies the table name of the skipped record.'; DataClassification = SystemMetadata; } field(5; "Record ID"; RecordID) { - Caption = 'Record ID'; - ToolTip = 'Specifies the Record ID of the skipped record.'; + Caption = 'Record Id'; + ToolTip = 'Specifies the record Id of the skipped record.'; trigger OnValidate() begin @@ -72,6 +72,9 @@ table 30159 "Shpfy Skipped Record" } } + var + DeleteLogEntriesLbl: Label 'Are you sure that you want to delete Shopify log entries?'; + local procedure GetTableCaption(): Text[250] var AllObjWithCaption: Record AllObjWithCaption; @@ -112,4 +115,23 @@ table 30159 "Shpfy Skipped Record" if "Record ID".TableNo() <> 0 then PageManagement.PageRun("Record ID"); end; -} + + /// + /// Delete Entries. + /// + /// Parameter of type Integer. + internal procedure DeleteEntries(DaysOld: Integer); + begin + if not Confirm(DeleteLogEntriesLbl) then + exit; + + if DaysOld > 0 then begin + Rec.SetFilter(SystemCreatedAt, '<=%1', CreateDateTime(Today - DaysOld, Time)); + if not Rec.IsEmpty() then + Rec.DeleteAll(false); + Rec.SetRange(SystemCreatedAt); + end else + if not Rec.IsEmpty() then + Rec.DeleteAll(false); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index d4a71071d2..36cab46a37 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -59,13 +59,13 @@ codeunit 30178 "Shpfy Product Export" ProductEvents: Codeunit "Shpfy Product Events"; ProductPriceCalc: Codeunit "Shpfy Product Price Calc."; VariantApi: Codeunit "Shpfy Variant API"; - ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + ShopifySkipRecord: Codeunit "Shpfy Skip Record"; OnlyUpdatePrice: Boolean; RecordCount: Integer; NullGuid: Guid; BulkOperationInput: TextBuilder; GraphQueryList: List of [TextBuilder]; - VariantPriceCalcSkippedLbl: Label 'Variant price is not synchronized because the item is blocked and sales blocked.'; + VariantPriceCalcSkippedLbl: Label 'Variant price is not synchronized because the item is blocked or sales blocked.'; /// /// Creates html body for a product from extended text, marketing text and attributes. @@ -321,7 +321,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", '', ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -358,7 +358,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -405,7 +405,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -553,24 +553,24 @@ codeunit 30178 "Shpfy Product Export" RecordRef2: RecordRef; VariantAction: Option " ",Create,Update; ItemIsBlockedLbl: Label 'Item is blocked.'; - ItemIsDraftLbl: Label 'Shopify Product is in draft status.'; - ItemIsArchivedLbl: Label 'Shopify Product is archived.'; + ItemIsDraftLbl: Label 'Shopify product is in draft status.'; + ItemIsArchivedLbl: Label 'Shopify product is archived.'; begin if ShopifyProduct.Get(ProductId) and Item.GetBySystemId(ShopifyProduct."Item SystemId") then begin case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsArchivedLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsArchivedLbl, Shop); exit; end; Shop."Action for Removed Products"::StatusToDraft: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsDraftLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsDraftLbl, Shop); exit; end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecordMgt.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsBlockedLbl, Shop); + ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsBlockedLbl, Shop); exit; end; end; diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 75602207f0..0e3e76fff5 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -40,7 +40,7 @@ codeunit 30190 "Shpfy Export Shipments" ShopifyOrderHeader: Record "Shpfy Order Header"; OrderFulfillments: Codeunit "Shpfy Order Fulfillments"; JsonHelper: Codeunit "Shpfy Json Helper"; - SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + SkipRecordMgt: Codeunit "Shpfy Skip Record"; JFulfillment: JsonToken; JResponse: JsonToken; FulfillmentOrderRequest: Text; diff --git a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al index 7c5f206ecf..672f9b8bed 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al +++ b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al @@ -31,7 +31,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShopifyOrderHeader: Record "Shpfy Order Header"; ShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; - SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + SkipRecordMgt: Codeunit "Shpfy Skip Record"; NoLinesApplicableLbl: Label 'No lines applicable for fulfillment.'; ShopifyOrderNotExistsLbl: Label 'Shopify order %1 does not exist.', Comment = '%1 = Shopify Order Id'; begin diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 99d2f673ba..e85a16a03d 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -169,7 +169,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [SCENARIO] Skip shopify variant price calculation using item unit of measure for variant with blocked item. Initialize(); - // [GIVEN] Blocked and sales blokced item + // [GIVEN] Blocked or sales blokced item CreateBlockedItem(Item); // [GIVEN] Shopify Product CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); @@ -183,7 +183,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -199,7 +199,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [SCENARIO] Skip shopify variant price calculation using item variant for variant with blocked item. Initialize(); - // [GIVEN] Blocked and sales blokced item + // [GIVEN] Blocked or sales blokced item CreateBlockedItem(Item); // [GIVEN] Shopify Product CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); @@ -213,7 +213,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -230,7 +230,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [SCENARIO] Skip shopify variant price calculation using item unit of measure and item variant for variant with blocked item. Initialize(); - // [GIVEN] Blocked and sales blokced item + // [GIVEN] Blocked or sales blokced item CreateBlockedItem(Item); // [GIVEN] Shopify Product CreateShpfyProduct(ShopifyProduct, Item.SystemId, Shop.Code, ShopifyVariant); @@ -244,7 +244,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked and sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -590,7 +590,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var ShopWithDisabledLogging: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt."; + SkipRecordMgt: Codeunit "Shpfy Skip Record"; RecordID: RecordID; ShopifyId: BigInteger; TableId: Integer; From 506f35a8f15620e9e3a61b41036c9783fc8ac05a Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Fri, 25 Oct 2024 16:59:45 +0200 Subject: [PATCH 30/32] Tests fixes --- .../test/Logs/ShpfySkippedRecordLogTest.Codeunit.al | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index e85a16a03d..8bdad369b4 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -19,7 +19,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogEmptyCustomerEmail() var - Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; begin @@ -65,7 +64,6 @@ codeunit 139581 "Shpfy Skipped Record Log Test" [Test] procedure UnitTestLogProductItemBlocked() var - Item: Record Item; ShpfyItem: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; @@ -117,13 +115,12 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord.SetRange("Record ID", Item.RecordId); SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Shopify Product is archived.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Shopify product is archived.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] procedure UnitTestLogProductItemBlockedAndProductIsDraft() var - Item: Record Item; ShpfyProduct: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; @@ -153,7 +150,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" SkippedRecord.SetRange("Record ID", Item.RecordId); SkippedRecord.SetRange("Shopify Id", ShpfyProduct.Id); LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Shopify Product is in draft status.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Shopify product is in draft status.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -369,14 +366,13 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesInvoiceHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual(StrSubstNo('Shopify Customer template exists for customer no. %1 shop %2.', Customer."No.", ShopWithCustTemplates.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual(StrSubstNo('Shopify customer template exists for customer no. %1 shop %2.', Customer."No.", ShopWithCustTemplates.Code), SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] procedure UnitTestLogSalesInvoiceWithoutSalesLine() var SalesInvoiceHeader: Record "Sales Invoice Header"; - SalesInvoiceLine: Record "Sales Invoice Line"; Customer: Record Customer; SkippedRecord: Record "Shpfy Skipped Record"; PostedInvoiceExport: Codeunit "Shpfy Posted Invoice Export"; From 958bdbede4a672622dd9426ce804f044410b4d37 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 28 Oct 2024 09:22:44 +0100 Subject: [PATCH 31/32] PR fixes --- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 7 +- .../Codeunits/ShpfyCustomerExport.Codeunit.al | 6 +- .../ShpfyPostedInvoiceExport.Codeunit.al | 16 ++--- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 16 ++--- .../Logs/Pages/ShpfySkippedRecords.Page.al | 4 +- .../Codeunits/ShpfyProductExport.Codeunit.al | 14 ++-- .../ShpfyExportShipments.Codeunit.al | 10 +-- .../Reports/ShpfySyncShipmToShopify.Report.al | 6 +- .../ShpfySkippedRecordLogTest.Codeunit.al | 64 +++++++++---------- 9 files changed, 71 insertions(+), 72 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al index 2415447a1f..1146b1366e 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -1,6 +1,5 @@ namespace Microsoft.Integration.Shopify; -using Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; using Microsoft.Foundation.Company; using Microsoft.Foundation.Address; @@ -37,7 +36,7 @@ codeunit 30284 "Shpfy Company Export" Shop: Record "Shpfy Shop"; CompanyAPI: Codeunit "Shpfy Company API"; CatalogAPI: Codeunit "Shpfy Catalog API"; - ShpfySkipRecord: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; @@ -49,7 +48,7 @@ codeunit 30284 "Shpfy Company Export" EmptyEmailAddressLbl: Label 'Customer (Company) has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShpfySkipRecord.LogSkippedRecord(Customer.RecordId, 'Customer does not have an email address.', Shop); + SkippedRecord.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; @@ -189,7 +188,7 @@ codeunit 30284 "Shpfy Company Export" begin ShopifyCompany.Get(CompanyId); if ShopifyCompany."Customer SystemId" <> Customer.SystemId then begin - ShpfySkipRecord.LogSkippedRecord(ShopifyCompany.Id, Customer.RecordId, CompanyWithPhoneNoOrEmailExistsLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyCompany.Id, Customer.RecordId, CompanyWithPhoneNoOrEmailExistsLbl, Shop); exit; end; diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al index 3403047aee..803beab9cd 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCustomerExport.Codeunit.al @@ -39,7 +39,7 @@ codeunit 30116 "Shpfy Customer Export" var Shop: Record "Shpfy Shop"; CustomerApi: Codeunit "Shpfy Customer API"; - ShopifySkipRecord: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; CreateCustomers: Boolean; CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name'; @@ -91,7 +91,7 @@ codeunit 30116 "Shpfy Customer Export" EmptyEmailAddressLbl: Label 'Customer has no e-mail address.'; begin if Customer."E-Mail" = '' then begin - ShopifySkipRecord.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); + SkippedRecord.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop); exit; end; @@ -304,7 +304,7 @@ codeunit 30116 "Shpfy Customer Export" begin ShopifyCustomer.Get(CustomerID); if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin - ShopifySkipRecord.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop); exit; // An other customer with the same e-mail or phone is the source of it. end; diff --git a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al index 4aefa5c514..e45acfee0d 100644 --- a/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Invoicing/Codeunits/ShpfyPostedInvoiceExport.Codeunit.al @@ -17,7 +17,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" DraftOrdersAPI: Codeunit "Shpfy Draft Orders API"; FulfillmentAPI: Codeunit "Shpfy Fulfillment API"; JsonHelper: Codeunit "Shpfy Json Helper"; - SkipRecordMgt: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; trigger OnRun() begin @@ -102,23 +102,23 @@ codeunit 30362 "Shpfy Posted Invoice Export" if ShopifyCompany.IsEmpty() then begin ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No."); if ShopifyCustomer.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop); exit(false); end; end; if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop); exit(false); end; if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop); exit(false); end; if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop); exit(false); end; @@ -165,7 +165,7 @@ codeunit 30362 "Shpfy Posted Invoice Export" SalesInvoiceLine.SetRange("Document No.", SalesInvoiceHeader."No."); SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" "); if SalesInvoiceLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop); exit(false); end; @@ -176,12 +176,12 @@ codeunit 30362 "Shpfy Posted Invoice Export" if SalesInvoiceLine.FindSet() then repeat if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop); exit(false); end; if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then begin - SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop); exit(false); end; until SalesInvoiceLine.Next() = 0; diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al index 082d171178..9c0f4a5eaf 100644 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al @@ -3,7 +3,7 @@ namespace Microsoft.Integration.Shopify; /// /// Codeunit Shpfy Skip Record (ID 30313). /// -codeunit 30313 "Shpfy Skip Record" +codeunit 30313 "Shpfy Skipped Record" { Access = Internal; Permissions = tabledata "Shpfy Skipped Record" = rimd; @@ -18,16 +18,16 @@ codeunit 30313 "Shpfy Skip Record" /// Shop record. internal procedure LogSkippedRecord(ShopifyId: BigInteger; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") var - ShpfySkippedRecord: Record "Shpfy Skipped Record"; + SkippedRecord: Record "Shpfy Skipped Record"; begin if Shop."Logging Mode" = Enum::"Shpfy Logging Mode"::Disabled then exit; - ShpfySkippedRecord.Init(); - ShpfySkippedRecord.Validate("Shopify Id", ShopifyId); - ShpfySkippedRecord.Validate("Table ID", RecordId.TableNo()); - ShpfySkippedRecord.Validate("Record ID", RecordId); - ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason); - ShpfySkippedRecord.Insert(true); + SkippedRecord.Init(); + SkippedRecord.Validate("Shopify Id", ShopifyId); + SkippedRecord.Validate("Table ID", RecordId.TableNo()); + SkippedRecord.Validate("Record ID", RecordId); + SkippedRecord.Validate("Skipped Reason", SkippedReason); + SkippedRecord.Insert(true); end; /// diff --git a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al index 6914f2be15..ceeda2df49 100644 --- a/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al +++ b/Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al @@ -71,7 +71,7 @@ page 30166 "Shpfy Skipped Records" ApplicationArea = All; Caption = 'Delete Entries Older Than 7 Days'; Image = ClearLog; - ToolTip = 'Clear the list of log entries that are older than 7 days.'; + ToolTip = 'Clear the list of skipped records that are older than 7 days.'; trigger OnAction(); begin @@ -83,7 +83,7 @@ page 30166 "Shpfy Skipped Records" ApplicationArea = All; Caption = 'Delete All Entries'; Image = Delete; - ToolTip = 'Clear the list of all log entries.'; + ToolTip = 'Clear the list of all skipped records.'; trigger OnAction(); begin diff --git a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al index 36cab46a37..8214a617c9 100644 --- a/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Products/Codeunits/ShpfyProductExport.Codeunit.al @@ -59,7 +59,7 @@ codeunit 30178 "Shpfy Product Export" ProductEvents: Codeunit "Shpfy Product Events"; ProductPriceCalc: Codeunit "Shpfy Product Price Calc."; VariantApi: Codeunit "Shpfy Variant API"; - ShopifySkipRecord: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; OnlyUpdatePrice: Boolean; RecordCount: Integer; NullGuid: Guid; @@ -321,7 +321,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, '', ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", '', ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -358,7 +358,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, Item."Sales Unit of Measure", ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -405,7 +405,7 @@ codeunit 30178 "Shpfy Product Export" if (not Item.Blocked) and (not Item."Sales Blocked") then ProductPriceCalc.CalcPrice(Item, ItemVariant.Code, ItemUnitofMeasure.Code, ShopifyVariant."Unit Cost", ShopifyVariant.Price, ShopifyVariant."Compare at Price") else - ShopifySkipRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyVariant.Id, Item.RecordId, VariantPriceCalcSkippedLbl, Shop); if not OnlyUpdatePrice then begin ShopifyVariant."Available For Sales" := (not Item.Blocked) and (not Item."Sales Blocked"); ShopifyVariant.Barcode := CopyStr(GetBarcode(Item."No.", ItemVariant.Code, ItemUnitofMeasure.Code), 1, MaxStrLen(ShopifyVariant.Barcode)); @@ -560,17 +560,17 @@ codeunit 30178 "Shpfy Product Export" case Shop."Action for Removed Products" of Shop."Action for Removed Products"::StatusToArchived: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Archived) then begin - ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsArchivedLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsArchivedLbl, Shop); exit; end; Shop."Action for Removed Products"::StatusToDraft: if Item.Blocked and (ShopifyProduct.Status = ShopifyProduct.Status::Draft) then begin - ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsDraftLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsDraftLbl, Shop); exit; end; Shop."Action for Removed Products"::DoNothing: if Item.Blocked then begin - ShopifySkipRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsBlockedLbl, Shop); + SkippedRecord.LogSkippedRecord(ShopifyProduct.Id, Item.RecordId, ItemIsBlockedLbl, Shop); exit; end; end; diff --git a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al index 0e3e76fff5..d81e737815 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Shipping/Codeunits/ShpfyExportShipments.Codeunit.al @@ -40,12 +40,12 @@ codeunit 30190 "Shpfy Export Shipments" ShopifyOrderHeader: Record "Shpfy Order Header"; OrderFulfillments: Codeunit "Shpfy Order Fulfillments"; JsonHelper: Codeunit "Shpfy Json Helper"; - SkipRecordMgt: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; JFulfillment: JsonToken; JResponse: JsonToken; FulfillmentOrderRequest: Text; - NoCorespondingFulfilmentLinesLbl: Label 'No corresponding fulfillment lines found.'; - NoFullfilmentCreatedInShopifyLbl: Label 'Fullfilment was not created in Shopify.'; + NoCorrespondingFulfillmentLinesLbl: Label 'No corresponding fulfillment lines found.'; + NoFulfillmentCreatedInShopifyLbl: Label 'Fulfillment was not created in Shopify.'; begin if ShopifyOrderHeader.Get(SalesShipmentHeader."Shpfy Order Id") then begin ShopifyCommunicationMgt.SetShop(ShopifyOrderHeader."Shop Code"); @@ -57,11 +57,11 @@ codeunit 30190 "Shpfy Export Shipments" if (JFulfillment.IsObject) then SalesShipmentHeader."Shpfy Fulfillment Id" := OrderFulfillments.ImportFulfillment(SalesShipmentHeader."Shpfy Order Id", JFulfillment) else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoFullfilmentCreatedInShopifyLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoFulfillmentCreatedInShopifyLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; end else begin - SkipRecordMgt.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoCorespondingFulfilmentLinesLbl, Shop); + SkippedRecord.LogSkippedRecord(SalesShipmentHeader."Shpfy Order Id", SalesShipmentHeader.RecordId, NoCorrespondingFulfillmentLinesLbl, Shop); SalesShipmentHeader."Shpfy Fulfillment Id" := -1; end; SalesShipmentHeader.Modify(true); diff --git a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al index 672f9b8bed..13764c784b 100644 --- a/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al +++ b/Apps/W1/Shopify/app/src/Shipping/Reports/ShpfySyncShipmToShopify.Report.al @@ -31,7 +31,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShopifyOrderHeader: Record "Shpfy Order Header"; ShipmentLine: Record "Sales Shipment Line"; Shop: Record "Shpfy Shop"; - SkipRecordMgt: Codeunit "Shpfy Skip Record"; + SkippedRecord: Codeunit "Shpfy Skipped Record"; NoLinesApplicableLbl: Label 'No lines applicable for fulfillment.'; ShopifyOrderNotExistsLbl: Label 'Shopify order %1 does not exist.', Comment = '%1 = Shopify Order Id'; begin @@ -39,7 +39,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" ShipmentLine.SetRange(Type, ShipmentLine.Type::"Item"); ShipmentLine.SetFilter(Quantity, '>0'); if ShipmentLine.IsEmpty() then begin - SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, NoLinesApplicableLbl, Shop); + SkippedRecord.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, NoLinesApplicableLbl, Shop); "Shpfy Fulfillment Id" := -2; Modify(); end else @@ -48,7 +48,7 @@ report 30109 "Shpfy Sync Shipm. to Shopify" FulfillmentOrdersAPI.GetShopifyFulfillmentOrdersFromShopifyOrder(Shop, "Sales Shipment Header"."Shpfy Order Id"); ExportShipments.CreateShopifyFulfillment("Sales Shipment Header"); end else - SkipRecordMgt.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, StrSubstNo(ShopifyOrderNotExistsLbl, "Sales Shipment Header"."Shpfy Order Id"), Shop); + SkippedRecord.LogSkippedRecord("Sales Shipment Header"."Shpfy Order Id", "Sales Shipment Header".RecordId, StrSubstNo(ShopifyOrderNotExistsLbl, "Sales Shipment Header"."Shpfy Order Id"), Shop); end; } } diff --git a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al index 8bdad369b4..783d41bb29 100644 --- a/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Logs/ShpfySkippedRecordLogTest.Codeunit.al @@ -125,7 +125,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShpfyProduct: Record "Shpfy Product"; SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; - ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin // [SCENARIO] Log skipped record when product item is blocked and product is draft Initialize(); @@ -140,11 +140,11 @@ codeunit 139581 "Shpfy Skipped Record Log Test" CreateShopifyProductWithStatus(Item, ShpfyProduct, Enum::"Shpfy Product Status"::Draft); // [WHEN] Invoke Shopify Product Export - BindSubscription(ShpfySkippedRecordLogSub); + BindSubscription(SkippedRecordLogSub); ProductExport.SetShop(Shop); Shop.SetRange("Code", Shop.Code); ProductExport.Run(Shop); - UnbindSubscription(ShpfySkippedRecordLogSub); + UnbindSubscription(SkippedRecordLogSub); // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", Item.RecordId); @@ -160,7 +160,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyProduct: Record "Shpfy Product"; ShopifyVariant: Record "Shpfy Variant"; ItemunitOfMeasure: Record "Item Unit of Measure"; - ShpfySkippedRecord: Record "Shpfy Skipped Record"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; begin // [SCENARIO] Skip shopify variant price calculation using item unit of measure for variant with blocked item. @@ -177,10 +177,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemUnitOfMeasure); // [THEN] Related log record is created in shopify skipped record table. - ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); - ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); - LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + SkippedRecord.SetRange("Record ID", Item.RecordId); + SkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -190,7 +190,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyProduct: Record "Shpfy Product"; ShopifyVariant: Record "Shpfy Variant"; ItemVariant: Record "Item Variant"; - ShpfySkippedRecord: Record "Shpfy Skipped Record"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; begin // [SCENARIO] Skip shopify variant price calculation using item variant for variant with blocked item. @@ -207,10 +207,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemVariant); // [THEN] Related log record is created in shopify skipped record table. - ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); - ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); - LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + SkippedRecord.SetRange("Record ID", Item.RecordId); + SkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -221,7 +221,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyVariant: Record "Shpfy Variant"; ItemUnitOfMeasure: Record "Item Unit of Measure"; ItemVariant: Record "Item Variant"; - ShpfySkippedRecord: Record "Shpfy Skipped Record"; + SkippedRecord: Record "Shpfy Skipped Record"; ProductExport: Codeunit "Shpfy Product Export"; begin // [SCENARIO] Skip shopify variant price calculation using item unit of measure and item variant for variant with blocked item. @@ -238,10 +238,10 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ProductExport.FillInProductVariantData(ShopifyVariant, Item, ItemVariant, ItemUnitOfMeasure); // [THEN] Related log record is created in shopify skipped record table. - ShpfySkippedRecord.SetRange("Record ID", Item.RecordId); - ShpfySkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); - LibraryAssert.IsTrue(ShpfySkippedRecord.FindFirst(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', ShpfySkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + SkippedRecord.SetRange("Record ID", Item.RecordId); + SkippedRecord.SetRange("Shopify Id", ShopifyVariant.Id); + LibraryAssert.IsTrue(SkippedRecord.FindFirst(), 'Skipped record is not created'); + LibraryAssert.AreEqual('Variant price is not synchronized because the item is blocked or sales blocked.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -578,7 +578,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" // [THEN] Related record is created in shopify skipped record table. SkippedRecord.SetRange("Record ID", SalesShipmentHeader.RecordId); LibraryAssert.IsTrue(SkippedRecord.FindLast(), 'Skipped record is not created'); - LibraryAssert.AreEqual('Fullfilment was not created in Shopify.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); + LibraryAssert.AreEqual('Fulfillment was not created in Shopify.', SkippedRecord."Skipped Reason", 'Skipped reason is not as expected'); end; [Test] @@ -586,7 +586,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" var ShopWithDisabledLogging: Record "Shpfy Shop"; SkippedRecord: Record "Shpfy Skipped Record"; - SkipRecordMgt: Codeunit "Shpfy Skip Record"; + SkippedRecordCodeunit: Codeunit "Shpfy Skipped Record"; RecordID: RecordID; ShopifyId: BigInteger; TableId: Integer; @@ -600,7 +600,7 @@ codeunit 139581 "Shpfy Skipped Record Log Test" ShopifyId := Any.IntegerInRange(10000, 999999); // [WHEN] Invoke Skip Record Management - SkipRecordMgt.LogSkippedRecord(ShopifyId, RecordID, Any.AlphabeticText(250), ShopWithDisabledLogging); + SkippedRecordCodeunit.LogSkippedRecord(ShopifyId, RecordID, Any.AlphabeticText(250), ShopWithDisabledLogging); // [THEN] No record is created in shopify skipped record table. SkippedRecord.SetRange("Shopify Id", ShopifyId); @@ -761,12 +761,12 @@ codeunit 139581 "Shpfy Skipped Record Log Test" Item.Insert(false); end; - local procedure CreateShopifyCustomerWithRandomGuid(var ShpfyCustomer: Record "Shpfy Customer") + local procedure CreateShopifyCustomerWithRandomGuid(var ShopifyCustomer: Record "Shpfy Customer") var CustomerInitTest: Codeunit "Shpfy Customer Init Test"; begin - CustomerInitTest.CreateShopifyCustomer(ShpfyCustomer); - ShpfyCustomer."Customer SystemId" := CreateGuid(); + CustomerInitTest.CreateShopifyCustomer(ShopifyCustomer); + ShopifyCustomer."Customer SystemId" := CreateGuid(); end; local procedure SetActionForRemovedProducts(var Shop: Record "Shpfy Shop"; ShpfyRemoveProductAction: Enum Microsoft.Integration.Shopify."Shpfy Remove Product Action") @@ -800,17 +800,17 @@ codeunit 139581 "Shpfy Skipped Record Log Test" local procedure InvokeShopifyCustomerExport(var Customer: Record Customer; ShpfyCustomerId: BigInteger) var - ShpfyCustomerExport: Codeunit "Shpfy Customer Export"; - ShpfySkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; + CustomerExport: Codeunit "Shpfy Customer Export"; + SkippedRecordLogSub: Codeunit "Shpfy Skipped Record Log Sub."; begin - BindSubscription(ShpfySkippedRecordLogSub); + BindSubscription(SkippedRecordLogSub); if ShpfyCustomerId <> 0 then - ShpfySkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomerId); - ShpfyCustomerExport.SetShop(Shop); - ShpfyCustomerExport.SetCreateCustomers(true); + SkippedRecordLogSub.SetShopifyCustomerId(ShpfyCustomerId); + CustomerExport.SetShop(Shop); + CustomerExport.SetCreateCustomers(true); Customer.SetRange("No.", Customer."No."); - ShpfyCustomerExport.Run(Customer); - UnbindSubscription(ShpfySkippedRecordLogSub); + CustomerExport.Run(Customer); + UnbindSubscription(SkippedRecordLogSub); end; local procedure CreateShopWithCustomerTemplate(var ShopWithCustTemplates: Record "Shpfy Shop"; var ShopifyCustomerTemplate: Record "Shpfy Customer Template"; CustomerNo: Code[20]) From cfa6b3ba446a768f4793fa821d63b981544ffce9 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 15:13:15 +0100 Subject: [PATCH 32/32] rename codeunit --- .../Codeunits/ShpfySkippedRecord.Codeunit.al | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkippedRecord.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkippedRecord.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkippedRecord.Codeunit.al new file mode 100644 index 0000000000..9c0f4a5eaf --- /dev/null +++ b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkippedRecord.Codeunit.al @@ -0,0 +1,44 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Codeunit Shpfy Skip Record (ID 30313). +/// +codeunit 30313 "Shpfy Skipped Record" +{ + Access = Internal; + Permissions = tabledata "Shpfy Skipped Record" = rimd; + + /// + /// Creates log entry for skipped record. + /// + /// Related Shopify Id of the record. + /// Table Id of the record. + /// Record Id of the record. + /// Reason for skipping the record. + /// Shop record. + internal procedure LogSkippedRecord(ShopifyId: BigInteger; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") + var + SkippedRecord: Record "Shpfy Skipped Record"; + begin + if Shop."Logging Mode" = Enum::"Shpfy Logging Mode"::Disabled then + exit; + SkippedRecord.Init(); + SkippedRecord.Validate("Shopify Id", ShopifyId); + SkippedRecord.Validate("Table ID", RecordId.TableNo()); + SkippedRecord.Validate("Record ID", RecordId); + SkippedRecord.Validate("Skipped Reason", SkippedReason); + SkippedRecord.Insert(true); + end; + + /// + /// Creates log entry for skipped recordwith empty Shopify Id. + /// + /// Record Id of the record. + /// Reason for skipping the record. + /// Shop record. + internal procedure LogSkippedRecord(RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop") + begin + LogSkippedRecord(0, RecordId, SkippedReason, Shop); + end; + +}