From 299bb8228a2af7d74fb86f6c98eabc7052e706dc Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Mon, 30 Sep 2024 16:14:37 +0300 Subject: [PATCH 01/33] 1 task. Customer No. assignment for Shopify Catalogs during Customer as Company export --- .../app/src/Catalogs/Codeunits/ShpfyCatalogAPI.Codeunit.al | 4 +++- Apps/W1/Shopify/app/src/Catalogs/Pages/ShpfyCatalogs.Page.al | 2 +- .../src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Catalogs/Codeunits/ShpfyCatalogAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Catalogs/Codeunits/ShpfyCatalogAPI.Codeunit.al index f329bb41b..7ba2e40e1 100644 --- a/Apps/W1/Shopify/app/src/Catalogs/Codeunits/ShpfyCatalogAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Catalogs/Codeunits/ShpfyCatalogAPI.Codeunit.al @@ -1,6 +1,7 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Sales.Customer; /// /// Codeunit Shpfy Catalog API (ID 30290). @@ -15,7 +16,7 @@ codeunit 30290 "Shpfy Catalog API" JsonHelper: Codeunit "Shpfy Json Helper"; ShopifyCatalogURLLbl: Label 'https://admin.shopify.com/store/%1/catalogs/%2/editor', Comment = '%1 - Shop Name, %2 - Catalog Id', Locked = true; - internal procedure CreateCatalog(ShopifyCompany: Record "Shpfy Company") + internal procedure CreateCatalog(ShopifyCompany: Record "Shpfy Company"; Customer: Record Customer) var Catalog: Record "Shpfy Catalog"; GraphQLType: Enum "Shpfy GraphQL Type"; @@ -32,6 +33,7 @@ codeunit 30290 "Shpfy Catalog API" Catalog."Shop Code" := Shop.Code; Catalog.Name := ShopifyCompany.Name; Catalog."Company SystemId" := ShopifyCompany.SystemId; + Catalog."Customer No." := Customer."No."; Catalog.Insert(); CreatePublication(Catalog); CreatePriceList(Catalog); diff --git a/Apps/W1/Shopify/app/src/Catalogs/Pages/ShpfyCatalogs.Page.al b/Apps/W1/Shopify/app/src/Catalogs/Pages/ShpfyCatalogs.Page.al index d0b0dd7db..7d203d999 100644 --- a/Apps/W1/Shopify/app/src/Catalogs/Pages/ShpfyCatalogs.Page.al +++ b/Apps/W1/Shopify/app/src/Catalogs/Pages/ShpfyCatalogs.Page.al @@ -28,7 +28,7 @@ page 30159 "Shpfy Catalogs" field("Customer No."; Rec."Customer No.") { ApplicationArea = All; - Visible = false; + Editable = false; ToolTip = 'Specifies the customer''s no. When Customer No. is Selected: Parameters like ''Customer Discount Group'', ''Customer Price Group'', and ''Allow Line Discount'' on the customer card take precedence over catalog settings'; } field(Name; Rec.Name) 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 cf6519934..859c1479c 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -59,7 +59,7 @@ codeunit 30284 "Shpfy Company Export" ShopifyCompany.Insert(); if Shop."Auto Create Catalog" then - CatalogAPI.CreateCatalog(ShopifyCompany); + CatalogAPI.CreateCatalog(ShopifyCompany, Customer); CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; CompanyLocation.Insert(); From b9b646224805eaf9b042fed0831e5f07884540ca Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Thu, 3 Oct 2024 15:10:30 +0300 Subject: [PATCH 02/33] 2 task. Import Multiple Company locations to Business Central. Additional action to open Company Locations --- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 52 +++++++----- .../Pages/ShpfyCompLocations.Page.al | 82 +++++++++++++++++++ .../Companies/Pages/ShpfyCompanies.Page.al | 12 +++ .../Tables/ShpfyCompanyLocation.Table.al | 5 ++ .../Codeunits/ShpfyGQLCompany.Codeunit.al | 2 +- 5 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 6d5a83e72..e9c880096 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -29,6 +29,7 @@ codeunit 30286 "Shpfy Company API" if JResponse.SelectToken('$.data.companyCreate.company', JItem) then if JItem.IsObject then ShopifyCompany.Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'id')); + // JZA: Task2 - Task is only for Company location import. Exports won't work with for all locations if JsonHelper.GetJsonArray(JResponse, JLocations, 'data.companyCreate.company.locations.edges') then if JLocations.Count = 1 then if JLocations.Get(0, JItem) then begin @@ -298,6 +299,7 @@ codeunit 30286 "Shpfy Company API" JItem: JsonToken; OutStream: OutStream; PhoneNo: Text; + IsDefaultCompanyLocation: Boolean; begin UpdatedAt := JsonHelper.GetValueAsDateTime(JCompany, 'updatedAt'); if UpdatedAt <= ShopifyCompany."Updated At" then @@ -317,31 +319,37 @@ codeunit 30286 "Shpfy Company API" Clear(ShopifyCompany.Note); ShopifyCompany.Modify(); + IsDefaultCompanyLocation := true; if JsonHelper.GetJsonArray(JCompany, JLocations, 'locations.edges') then - if JLocations.Count = 1 then - if JLocations.Get(0, JItem) then begin - ShopifyCompany."Location Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.id')); + foreach JItem in JLocations do begin + ShopifyCompany."Location Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.id')); - CompanyLocation.SetRange(Id, ShopifyCompany."Location Id"); - if not CompanyLocation.FindFirst() then begin - CompanyLocation.Id := ShopifyCompany."Location Id"; - CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; - CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); - CompanyLocation.Insert(); - end; + CompanyLocation.SetRange(Id, ShopifyCompany."Location Id"); + if not CompanyLocation.FindFirst() then begin + CompanyLocation.Id := ShopifyCompany."Location Id"; + CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; + CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); + CompanyLocation.Insert(); + end; - CompanyLocation.Address := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address1', MaxStrLen(CompanyLocation.Address)), 1, MaxStrLen(CompanyLocation.Address)); - CompanyLocation."Address 2" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address2', MaxStrLen(CompanyLocation."Address 2")), 1, MaxStrLen(CompanyLocation."Address 2")); - CompanyLocation.Zip := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.zip', MaxStrLen(CompanyLocation.Zip)), 1, MaxStrLen(CompanyLocation.Zip)); - CompanyLocation.City := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.city', MaxStrLen(CompanyLocation.City)), 1, MaxStrLen(CompanyLocation.City)); - CompanyLocation."Country/Region Code" := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.countryCode', MaxStrLen(CompanyLocation."Country/Region Code")), 1, MaxStrLen(CompanyLocation."Country/Region Code")); - CompanyLocation."Province Code" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.zoneCode', MaxStrLen(CompanyLocation."Province Code")), 1, MaxStrLen(CompanyLocation."Province Code")); - CompanyLocation."Province Name" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.province', MaxStrLen(CompanyLocation."Province Name")), 1, MaxStrLen(CompanyLocation."Province Name")); - PhoneNo := JsonHelper.GetValueAsText(JItem, 'node.billingAddress.phone'); - PhoneNo := CopyStr(DelChr(PhoneNo, '=', DelChr(PhoneNo, '=', '1234567890/+ .()')), 1, MaxStrLen(CompanyLocation."Phone No.")); - CompanyLocation."Phone No." := CopyStr(PhoneNo, 1, MaxStrLen(CompanyLocation."Phone No.")); - CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); - CompanyLocation.Modify(); + CompanyLocation.Address := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address1', MaxStrLen(CompanyLocation.Address)), 1, MaxStrLen(CompanyLocation.Address)); + CompanyLocation."Address 2" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address2', MaxStrLen(CompanyLocation."Address 2")), 1, MaxStrLen(CompanyLocation."Address 2")); + CompanyLocation.Zip := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.zip', MaxStrLen(CompanyLocation.Zip)), 1, MaxStrLen(CompanyLocation.Zip)); + CompanyLocation.City := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.city', MaxStrLen(CompanyLocation.City)), 1, MaxStrLen(CompanyLocation.City)); + CompanyLocation."Country/Region Code" := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.countryCode', MaxStrLen(CompanyLocation."Country/Region Code")), 1, MaxStrLen(CompanyLocation."Country/Region Code")); + CompanyLocation."Province Code" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.zoneCode', MaxStrLen(CompanyLocation."Province Code")), 1, MaxStrLen(CompanyLocation."Province Code")); + CompanyLocation."Province Name" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.province', MaxStrLen(CompanyLocation."Province Name")), 1, MaxStrLen(CompanyLocation."Province Name")); + PhoneNo := JsonHelper.GetValueAsText(JItem, 'node.billingAddress.phone'); + PhoneNo := CopyStr(DelChr(PhoneNo, '=', DelChr(PhoneNo, '=', '1234567890/+ .()')), 1, MaxStrLen(CompanyLocation."Phone No.")); + CompanyLocation."Phone No." := CopyStr(PhoneNo, 1, MaxStrLen(CompanyLocation."Phone No.")); + CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); + CompanyLocation.Default := false; + if IsDefaultCompanyLocation then begin + CompanyLocation.Default := IsDefaultCompanyLocation; + IsDefaultCompanyLocation := false; end; + CompanyLocation.Modify(); + // end; + end; end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al new file mode 100644 index 000000000..b8beb06e2 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al @@ -0,0 +1,82 @@ +namespace Microsoft.Integration.Shopify; + +using Microsoft.Sales.Customer; + +/// +/// Page Shpfy Company Locations (ID 30165). +/// +page 30165 "Shpfy Comp. Locations" +{ + ApplicationArea = All; + Caption = 'Shopify Company Locations'; + Editable = false; + InsertAllowed = false; + DeleteAllowed = false; + ModifyAllowed = false; + PageType = List; + SourceTable = "Shpfy Company Location"; + UsageCategory = None; + + layout + { + area(content) + { + repeater(General) + { + field(Id; Rec.Id) + { + ToolTip = 'Specifies the unique identifier for the company location in Shopify.'; + } + field("Company SystemId"; Rec."Company SystemId") + { + ToolTip = 'Specifies the unique identifier for the company in Shopify.'; + } + field("Default"; Rec."Default") + { + ToolTip = 'Specifies whether the location is the default location for the company.'; + } + field(Address; Rec.Address) + { + ToolTip = 'Specifies the address of the company location.'; + } + field("Address 2"; Rec."Address 2") + { + ToolTip = 'Specifies the second address line of the company location.'; + } + field(Zip; Rec.Zip) + { + ToolTip = 'Specifies the postal code of the company location.'; + } + field(City; Rec.City) + { + ToolTip = 'Specifies the city of the company location.'; + } + field("Country/Region Code"; Rec."Country/Region Code") + { + ToolTip = 'Specifies the country/region code of the company location.'; + } + field("Phone No."; Rec."Phone No.") + { + ToolTip = 'Specifies the phone number of the company location.'; + } + field(Name; Rec.Name) + { + ToolTip = 'Specifies the name of the company location.'; + } + field("Province Code"; Rec."Province Code") + { + ToolTip = 'Specifies the province code of the company location.'; + } + field("Province Name"; Rec."Province Name") + { + ToolTip = 'Specifies the province name of the company location.'; + } + field("Tax Registration Id"; Rec."Tax Registration Id") + { + ToolTip = 'Specifies the tax registration identifier of the company location.'; + } + } + } + } + +} diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al index 39fd16175..24e04c5e8 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanies.Page.al @@ -118,6 +118,18 @@ page 30156 "Shpfy Companies" RunPageLink = "Company SystemId" = field(SystemId); ToolTip = 'View a list of Shopify catalogs for the company.'; } + action(ShopifyLocations) + { + ApplicationArea = All; + Caption = 'Shopify Locations'; + Image = Warehouse; + Promoted = true; + PromotedOnly = true; + PromotedCategory = Category4; + RunObject = Page "Shpfy Comp. Locations"; + RunPageLink = "Company SystemId" = field(SystemId); + ToolTip = 'View a list of Shopify company locations.'; + } } area(Processing) diff --git a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al index f94a8a2f3..608cf67e7 100644 --- a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al +++ b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al @@ -73,6 +73,11 @@ table 30151 "Shpfy Company Location" Caption = 'Tax Registration Id'; DataClassification = CustomerContent; } + field(13; "Default"; Boolean) + { + Caption = 'Default'; + DataClassification = CustomerContent; + } } keys { diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al index e6a5806e2..1c2192951 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:1, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:20, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); end; /// From bf343d5c097a14b3f10468a3d8b7cfff47409ffd Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Thu, 3 Oct 2024 15:38:00 +0300 Subject: [PATCH 03/33] 2 task. Import Multiple Company locations to Business Central. Improvements --- .../Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index e9c880096..724d5af23 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -300,6 +300,7 @@ codeunit 30286 "Shpfy Company API" OutStream: OutStream; PhoneNo: Text; IsDefaultCompanyLocation: Boolean; + CompanyLocationId: BigInteger; begin UpdatedAt := JsonHelper.GetValueAsDateTime(JCompany, 'updatedAt'); if UpdatedAt <= ShopifyCompany."Updated At" then @@ -322,11 +323,13 @@ codeunit 30286 "Shpfy Company API" IsDefaultCompanyLocation := true; if JsonHelper.GetJsonArray(JCompany, JLocations, 'locations.edges') then foreach JItem in JLocations do begin - ShopifyCompany."Location Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.id')); + CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.id')); + if IsDefaultCompanyLocation then + ShopifyCompany."Location Id" := CompanyLocationId; - CompanyLocation.SetRange(Id, ShopifyCompany."Location Id"); + CompanyLocation.SetRange(Id, CompanyLocationId); if not CompanyLocation.FindFirst() then begin - CompanyLocation.Id := ShopifyCompany."Location Id"; + CompanyLocation.Id := CompanyLocationId; CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); CompanyLocation.Insert(); @@ -343,7 +346,6 @@ codeunit 30286 "Shpfy Company API" PhoneNo := CopyStr(DelChr(PhoneNo, '=', DelChr(PhoneNo, '=', '1234567890/+ .()')), 1, MaxStrLen(CompanyLocation."Phone No.")); CompanyLocation."Phone No." := CopyStr(PhoneNo, 1, MaxStrLen(CompanyLocation."Phone No.")); CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); - CompanyLocation.Default := false; if IsDefaultCompanyLocation then begin CompanyLocation.Default := IsDefaultCompanyLocation; IsDefaultCompanyLocation := false; From 00b9c651ee0fa26adb3ae6e758b9a518796fd1b2 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Mon, 7 Oct 2024 09:40:33 +0300 Subject: [PATCH 04/33] 3 task. Tax ID export/mapping --- .../app/src/Base/Pages/ShpfyShopCard.Page.al | 6 ++ .../app/src/Base/Tables/ShpfyShop.Table.al | 6 ++ .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 47 ++++++++++++ .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 26 +++++++ .../Codeunits/ShpfyCompanyExport.Codeunit.al | 18 +++++ .../Codeunits/ShpfyCompanyMapping.Codeunit.al | 72 +++++++++++++------ .../Enums/ShpfyCompTaxIdMapping.Enum.al | 19 +++++ .../Enums/ShpfyCompanyMapping.Enum.al | 6 ++ 8 files changed, 179 insertions(+), 21 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al diff --git a/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al b/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al index f8cf3e6d6..f967b804e 100644 --- a/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al +++ b/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al @@ -425,6 +425,12 @@ page 30101 "Shpfy Shop Card" ApplicationArea = All; ToolTip = 'Specifies how to map companies.'; } + //JZA: Task 3 Tax ID + field("Shpfy Comp.Tax Id Mapping"; Rec."Shpfy Comp. Tax Id Mapping") + { + ApplicationArea = All; + ToolTip = 'Specifies how to map Shopify Tax ID.'; + } field("Auto Create Unknown Companies"; Rec."Auto Create Unknown Companies") { ApplicationArea = All; diff --git a/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al b/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al index ef7807eb4..0717e006e 100644 --- a/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al +++ b/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al @@ -788,6 +788,12 @@ table 30102 "Shpfy Shop" Caption = 'Weight Unit'; DataClassification = CustomerContent; } + //JZA: Task 3 Tax ID + field(130; "Shpfy Comp. Tax Id Mapping"; Enum "Shpfy Comp. Tax Id Mapping") + { + Caption = 'Company Tax Id Mapping'; + DataClassification = CustomerContent; + } field(200; "Shop Id"; Integer) { DataClassification = SystemMetadata; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al new file mode 100644 index 000000000..94e5b00a9 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -0,0 +1,47 @@ +namespace Microsoft.Integration.Shopify; +//JZA: Task 3 Tax ID +/// +/// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. +/// +codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" +{ + Access = Internal; + + internal procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] + var + ShopifyCompany: Record "Shpfy Company"; + begin + ShopifyCompany.SetAutoCalcFields("Customer No."); + if ShopifyCompany.Get(CompanyId) then begin + if not IsNullGuid(ShopifyCompany."Customer SystemId") then begin + ShopifyCompany.CalcFields("Customer No."); + if ShopifyCompany."Customer No." = '' then begin + Clear(ShopifyCompany."Customer SystemId"); + ShopifyCompany.Modify(); + end else + exit(ShopifyCompany."Customer No."); + end; + exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); + end else + exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); + exit(''); + end; + + local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] + var + ShopifyCompany: Record "Shpfy Company"; + TempCompany: Record "Shpfy Company" temporary; + CompanyImport: Codeunit "Shpfy Company Import"; + begin + CompanyImport.SetShop(ShopCode); + CompanyImport.SetAllowCreate(AllowCreate); + CompanyImport.SetTemplateCode(TemplateCode); + TempCompany.Id := CompanyId; + TempCompany.Insert(); + CompanyImport.Run(TempCompany); + CompanyImport.GetCompany(ShopifyCompany); + if ShopifyCompany.Find() then + ShopifyCompany.CalcFields("Customer No."); + exit(ShopifyCompany."Customer No."); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 724d5af23..e59794bee 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -69,6 +69,11 @@ codeunit 30286 "Shpfy Company API" GraphQuery := CreateGraphQueryUpdateLocation(CompanyLocation); if GraphQuery <> '' then JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); + + //JZA: Task 3 Tax ID + GraphQuery := CreateGraphQueryUpdateLocationTaxId(CompanyLocation); + if GraphQuery <> '' then + JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); end; internal procedure SetShop(ShopifyShop: Record "Shpfy Shop") @@ -109,6 +114,8 @@ codeunit 30286 "Shpfy Company API" AddFieldToGraphQuery(GraphQuery, 'name', CompanyLocation.Name); if CompanyLocation."Phone No." <> '' then AddFieldToGraphQuery(GraphQuery, 'phone', CompanyLocation."Phone No."); + if CompanyLocation."Tax Registration Id" <> '' then + AddFieldToGraphQuery(GraphQuery, 'taxRegistrationId', CompanyLocation."Tax Registration Id"); GraphQuery.Append('shippingAddress: {'); AddFieldToGraphQuery(GraphQuery, 'address1', CompanyLocation.Address); if CompanyLocation."Address 2" <> '' then @@ -217,6 +224,25 @@ codeunit 30286 "Shpfy Company API" end; end; + internal procedure CreateGraphQueryUpdateLocationTaxId(var CompanyLocation: Record "Shpfy Company Location"): Text + var + xCompanyLocation: Record "Shpfy Company Location"; + HasChange: Boolean; + GraphQuery: TextBuilder; + CompanyLocationIdTxt: Label 'gid://shopify/CompanyLocation/%1', Comment = '%1 = Company Location Id', Locked = true; + begin + xCompanyLocation.Get(CompanyLocation.Id); + GraphQuery.Append('{"query":"mutation {companyLocationCreateTaxRegistration(locationId: \"' + StrSubstNo(CompanyLocationIdTxt, CompanyLocation.Id) + '\", '); + if CompanyLocation."Tax Registration Id" <> xCompanyLocation."Tax Registration Id" then + HasChange := AddFieldToGraphQuery(GraphQuery, 'taxId', CompanyLocation."Tax Registration Id"); + GraphQuery.Remove(GraphQuery.Length - 1, 2); + + if HasChange then begin + GraphQuery.Append(') {companyLocation {id, name, taxRegistrationId}, userErrors {field, message}}}"}'); + exit(GraphQuery.ToText()); + end; + end; + internal procedure RetrieveShopifyCompanyIds(var CompanyIds: Dictionary of [BigInteger, DateTime]) var Id: BigInteger; 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 859c1479c..f46a6c52f 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -142,12 +142,29 @@ codeunit 30284 "Shpfy Company Export" CompanyLocation."Phone No." := Customer."Phone No."; + //JZA: Task 3 Tax ID + CompanyLocation."Tax Registration Id" := GetTaxRegistrationIdFromCustomer(Customer); + if HasDiff(ShopifyCompany, TempShopifyCompany) or HasDiff(CompanyLocation, TempCompanyLocation) then begin ShopifyCompany."Last Updated by BC" := CurrentDateTime; exit(true); end; end; + //JZA: Task 3 Tax ID + local procedure GetTaxRegistrationIdFromCustomer(Customer: Record Customer): Text + begin + case Shop."Shpfy Comp. Tax Id Mapping" of + Shop."Shpfy Comp. Tax Id Mapping"::RegistrationNo: + exit(Customer."Registration Number"); + Shop."Shpfy Comp. Tax Id Mapping"::VATRegistrationNo: + exit(Customer."VAT Registration No."); + else + exit(''); + //JZA: "Shpfy Comp. Tax Id Mapping" enum is extended publisher is needed + end; + end; + local procedure HasDiff(RecAsVariant: Variant; xRecAsVariant: Variant): Boolean var RecordRef: RecordRef; @@ -186,6 +203,7 @@ codeunit 30284 "Shpfy Company Export" exit; CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); + CompanyLocation.SetRange(Default, true); CompanyLocation.FindFirst(); if FillInShopifyCompany(Customer, ShopifyCompany, CompanyLocation) then begin diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al index f75e33981..c5fa2c966 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al @@ -24,6 +24,7 @@ codeunit 30303 "Shpfy Company Mapping" var Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; + CompanyLocation: Record "Shpfy Company Location"; CustomerMapping: Codeunit "Shpfy Customer Mapping"; PhoneFilter: Text; begin @@ -35,28 +36,11 @@ codeunit 30303 "Shpfy Company Mapping" ShopifyCompany.Modify(); end; + //JZA: Task 3 Tax ID if IsNullGuid(ShopifyCompany."Customer SystemId") then begin - if TempShopifyCustomer.Email <> '' then begin - Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - if TempShopifyCustomer."Phone No." <> '' then begin - PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); - if PhoneFilter <> '' then begin - Clear(Customer); - Customer.SetFilter("Phone No.", PhoneFilter); + if Shop."Company Mapping Type" = Shop."Company Mapping Type"::"By Email/Phone" then begin + if TempShopifyCustomer.Email <> '' then begin + Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); if Customer.FindFirst() then begin ShopifyCompany."Customer SystemId" := Customer.SystemId; @@ -71,6 +55,52 @@ codeunit 30303 "Shpfy Company Mapping" exit(true); end; end; + if TempShopifyCustomer."Phone No." <> '' then begin + PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); + if PhoneFilter <> '' then begin + Clear(Customer); + Customer.SetFilter("Phone No.", PhoneFilter); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + end; + end; + if Shop."Company Mapping Type" = Shop."Company Mapping Type"::"By Tax Id" then begin + if ShopifyCompany."Location Id" <> 0 then begin + CompanyLocation.Get(ShopifyCompany."Location Id"); + if CompanyLocation."Tax Registration Id" <> '' then begin + Clear(Customer); + if Shop."Shpfy Comp. Tax Id Mapping" = Shop."Shpfy Comp. Tax Id Mapping"::RegistrationNo then + Customer.SetRange("Registration Number", CompanyLocation."Tax Registration Id"); + if Shop."Shpfy Comp. Tax Id Mapping" = Shop."Shpfy Comp. Tax Id Mapping"::VATRegistrationNo then + Customer.SetRange("VAT Registration No.", CompanyLocation."Tax Registration Id"); + //JZA: "Shpfy Comp. Tax Id Mapping" enum is extended publisher is needed + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + end; end; end; end; diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al new file mode 100644 index 000000000..bcb73c9c8 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al @@ -0,0 +1,19 @@ +namespace Microsoft.Integration.Shopify; +//JZA: Task 3 Tax ID +/// +/// Enum Shopify Company Tax Id Mapping (ID 30165). +/// +enum 30165 "Shpfy Comp. Tax Id Mapping" +{ + Caption = 'Shopify Company Tax Id Mapping'; + Extensible = true; + + value(0; RegistrationNo) + { + Caption = 'Registration No.'; + } + value(1; VATRegistrationNo) + { + Caption = 'VAT Registration No.'; + } +} diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index b82b3bdd8..c9bfa6e63 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -13,6 +13,12 @@ enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping" Caption = 'By Email/Phone'; Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; } + //JZA: Task 3 Tax ID + value(1; "By Tax Id") + { + Caption = 'By Tax Id'; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id"; + } value(2; DefaultCompany) { Caption = 'Always take the default Company'; From 51cae4497ea5d8c82c529b95e317d20333911ef8 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Mon, 7 Oct 2024 11:54:58 +0300 Subject: [PATCH 05/33] 5 task. Assign External ID during Csutomer as Company export --- .../src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index e59794bee..a8bd157ec 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -24,7 +24,8 @@ codeunit 30286 "Shpfy Company API" CompanyContactId: BigInteger; CompanyContactRoles: Dictionary of [Text, BigInteger]; begin - GraphQuery := CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation); + //JZA: Task 5 - External ID + GraphQuery := CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); if JResponse.SelectToken('$.data.companyCreate.company', JItem) then if JItem.IsObject then @@ -102,13 +103,17 @@ codeunit 30286 "Shpfy Company API" exit(true); end; - internal procedure CreateCompanyGraphQLQuery(var ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"): Text + internal procedure CreateCompanyGraphQLQuery(var ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; ShopifyCustomer: Record "Shpfy Customer"): Text var GraphQuery: TextBuilder; begin GraphQuery.Append('{"query":"mutation {companyCreate(input: {company: {'); if ShopifyCompany.Name <> '' then AddFieldToGraphQuery(GraphQuery, 'name', ShopifyCompany.Name); + //JZA: Task 5 - External ID + ShopifyCustomer.CalcFields("Customer No."); + if ShopifyCustomer."Customer No." <> '' then + AddFieldToGraphQuery(GraphQuery, 'externalId', ShopifyCustomer."Customer No."); GraphQuery.Remove(GraphQuery.Length - 1, 2); GraphQuery.Append('}, companyLocation: {billingSameAsShipping: true,'); AddFieldToGraphQuery(GraphQuery, 'name', CompanyLocation.Name); From 8cbb2457599ab7ba53dd85cf242cb54996ca4c63 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Tue, 8 Oct 2024 09:30:35 +0300 Subject: [PATCH 06/33] Set Company Location as default on Shopify Company creation --- .../app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al | 1 + 1 file changed, 1 insertion(+) 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 f46a6c52f..805cdbc15 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -61,6 +61,7 @@ codeunit 30284 "Shpfy Company Export" if Shop."Auto Create Catalog" then CatalogAPI.CreateCatalog(ShopifyCompany, Customer); + CompanyLocation.Default := true; CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; CompanyLocation.Insert(); end; From ee27f393d4bf7f4896eb08e39e1329a5796cda6c Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Tue, 8 Oct 2024 10:40:27 +0300 Subject: [PATCH 07/33] Get Tax Registration Number moved to implementation codeunits --- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 18 +++--------------- .../ShpfyTaxRegistrationNo.Codeunit.al | 12 ++++++++++++ .../ShpfyVATTaxRegistrationNo.Codeunit.al | 12 ++++++++++++ .../Enums/ShpfyCompTaxIdMapping.Enum.al | 8 +++++--- .../Interfaces/ShpfyITaxIdMapping.Interface.al | 8 ++++++++ 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al 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 805cdbc15..554b573cb 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -88,6 +88,7 @@ codeunit 30284 "Shpfy Company Export" TaxArea: Record "Shpfy Tax Area"; TempShopifyCompany: Record "Shpfy Company" temporary; TempCompanyLocation: Record "Shpfy Company Location" temporary; + ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; CountyCodeTooLongErr: Text; begin TempShopifyCompany := ShopifyCompany; @@ -144,7 +145,8 @@ codeunit 30284 "Shpfy Company Export" CompanyLocation."Phone No." := Customer."Phone No."; //JZA: Task 3 Tax ID - CompanyLocation."Tax Registration Id" := GetTaxRegistrationIdFromCustomer(Customer); + ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; + CompanyLocation."Tax Registration Id" := ShpfyTaxRegistrationIdMapping.GetTaxRegistrationId(Customer); if HasDiff(ShopifyCompany, TempShopifyCompany) or HasDiff(CompanyLocation, TempCompanyLocation) then begin ShopifyCompany."Last Updated by BC" := CurrentDateTime; @@ -152,20 +154,6 @@ codeunit 30284 "Shpfy Company Export" end; end; - //JZA: Task 3 Tax ID - local procedure GetTaxRegistrationIdFromCustomer(Customer: Record Customer): Text - begin - case Shop."Shpfy Comp. Tax Id Mapping" of - Shop."Shpfy Comp. Tax Id Mapping"::RegistrationNo: - exit(Customer."Registration Number"); - Shop."Shpfy Comp. Tax Id Mapping"::VATRegistrationNo: - exit(Customer."VAT Registration No."); - else - exit(''); - //JZA: "Shpfy Comp. Tax Id Mapping" enum is extended publisher is needed - end; - end; - local procedure HasDiff(RecAsVariant: Variant; xRecAsVariant: Variant): Boolean var RecordRef: RecordRef; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al new file mode 100644 index 000000000..2ce89d176 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al @@ -0,0 +1,12 @@ +namespace Microsoft.Integration.Shopify; + +using Microsoft.Sales.Customer; + +codeunit 30367 "Shpfy Tax Registration No." implements "Shpfy Tax Registration Id Mapping" +{ + procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + begin + exit(Customer."Registration Number"); + end; +} + diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al new file mode 100644 index 000000000..307c219b6 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al @@ -0,0 +1,12 @@ +namespace Microsoft.Integration.Shopify; + +using Microsoft.Sales.Customer; + +codeunit 30368 "Shpfy VAT Tax Registration No." implements "Shpfy Tax Registration Id Mapping" +{ + procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + begin + exit(Customer."VAT Registration No."); + end; +} + diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al index bcb73c9c8..c678725b3 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al @@ -3,17 +3,19 @@ namespace Microsoft.Integration.Shopify; /// /// Enum Shopify Company Tax Id Mapping (ID 30165). /// -enum 30165 "Shpfy Comp. Tax Id Mapping" +enum 30165 "Shpfy Comp. Tax Id Mapping" implements "Shpfy Tax Registration Id Mapping" { Caption = 'Shopify Company Tax Id Mapping'; Extensible = true; - value(0; RegistrationNo) + value(0; "Registration No.") { Caption = 'Registration No.'; + Implementation = "Shpfy Tax Registration Id Mapping" = "Shpfy Tax Registration No."; } - value(1; VATRegistrationNo) + value(1; "VAT Registration No.") { Caption = 'VAT Registration No.'; + Implementation = "Shpfy Tax Registration Id Mapping" = "Shpfy VAT Tax Registration No."; } } diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al new file mode 100644 index 000000000..01e5eb874 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al @@ -0,0 +1,8 @@ +namespace Microsoft.Integration.Shopify; + +using Microsoft.Sales.Customer; + +interface "Shpfy Tax Registration Id Mapping" +{ + procedure GetTaxRegistrationId(var Customer: Record Customer): Text; +} \ No newline at end of file From accc09abae0799d66ea9cee64a9d0e9bc3213fbd Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Tue, 8 Oct 2024 12:44:45 +0300 Subject: [PATCH 08/33] Moved Company Mapping to implementation codeunits --- .../ShpfyCompByDefaultComp.Codeunit.al | 34 ++++++++ .../ShpfyCompByEmailPhone.Codeunit.al | 57 +++++++++++++ .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 46 +++++++++- .../Codeunits/ShpfyCompanyImport.Codeunit.al | 1 + .../Codeunits/ShpfyCompanyMapping.Codeunit.al | 85 +------------------ .../ShpfyTaxRegistrationNo.Codeunit.al | 5 ++ .../ShpfyVATTaxRegistrationNo.Codeunit.al | 5 ++ .../ShpfyICompanyMapping.Interface.al | 2 + ...pfyITaxRegistrationIdMapping.Interface.al} | 2 + 9 files changed, 154 insertions(+), 83 deletions(-) rename Apps/W1/Shopify/app/src/Companies/Interfaces/{ShpfyITaxIdMapping.Interface.al => ShpfyITaxRegistrationIdMapping.Interface.al} (60%) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al index 8466a6ab8..1cff66bec 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al @@ -1,5 +1,7 @@ namespace Microsoft.Integration.Shopify; +using Microsoft.Sales.Customer; + /// /// Codeunit Shpfy Comp. By Default Comp. (ID 30305) implements Interface Shpfy ICompany Mapping. /// @@ -15,4 +17,36 @@ codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping Shop.Get(ShopCode); exit(Shop."Default Company No."); end; + + internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + Shop: Record "Shpfy Shop"; + begin + if not IsNullGuid(ShopifyCompany."Customer SystemId") then + if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then + exit(true) + else begin + Clear(ShopifyCompany."Customer SystemId"); + ShopifyCompany.Modify(); + end; + + if IsNullGuid(ShopifyCompany."Customer SystemId") then begin + Shop.Get(ShopifyCompany."Shop Code"); + if Customer.Get(Shop."Default Company No.") then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al index 0b9085453..97bd62d09 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al @@ -1,5 +1,7 @@ namespace Microsoft.Integration.Shopify; +using Microsoft.Sales.Customer; + /// /// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. /// @@ -27,6 +29,61 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" exit(''); end; + internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + CustomerMapping: Codeunit "Shpfy Customer Mapping"; + PhoneFilter: Text; + begin + if not IsNullGuid(ShopifyCompany."Customer SystemId") then + if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then + exit(true) + else begin + Clear(ShopifyCompany."Customer SystemId"); + ShopifyCompany.Modify(); + end; + + if IsNullGuid(ShopifyCompany."Customer SystemId") then begin + if TempShopifyCustomer.Email <> '' then begin + Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + if TempShopifyCustomer."Phone No." <> '' then begin + PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); + if PhoneFilter <> '' then begin + Clear(Customer); + Customer.SetFilter("Phone No.", PhoneFilter); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + end; + end; + end; + local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] var ShopifyCompany: Record "Shpfy Company"; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index 94e5b00a9..59fb5c9cc 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -1,5 +1,7 @@ namespace Microsoft.Integration.Shopify; -//JZA: Task 3 Tax ID + +using Microsoft.Sales.Customer; + /// /// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. /// @@ -27,6 +29,48 @@ codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" exit(''); end; + internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + Shop: Record "Shpfy Shop"; + CompanyLocation: Record "Shpfy Company Location"; + ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + begin + if not IsNullGuid(ShopifyCompany."Customer SystemId") then + if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then + exit(true) + else begin + Clear(ShopifyCompany."Customer SystemId"); + ShopifyCompany.Modify(); + end; + + if IsNullGuid(ShopifyCompany."Customer SystemId") then begin + if ShopifyCompany."Location Id" <> 0 then begin + CompanyLocation.Get(ShopifyCompany."Location Id"); + if CompanyLocation."Tax Registration Id" <> '' then begin + Clear(Customer); + Shop.Get(ShopifyCompany."Shop Code"); + ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; + ShpfyTaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(); + exit(true); + end; + end; + end; + end; + end; + local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] var ShopifyCompany: Record "Shpfy Company"; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al index ac661a69c..f95e2fe19 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al @@ -68,6 +68,7 @@ codeunit 30301 "Shpfy Company Import" begin Shop := ShopifyShop; CompanyApi.SetShop(Shop); + CompanyMapping.SetShop(Shop); end; internal procedure SetShop(ShopCode: Code[20]) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al index c5fa2c966..1e485c814 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al @@ -1,7 +1,5 @@ namespace Microsoft.Integration.Shopify; -using Microsoft.Sales.Customer; - /// /// Codeunit Shpfy Company Mapping (ID 30303). /// @@ -22,87 +20,10 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; var - Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; - CompanyLocation: Record "Shpfy Company Location"; - CustomerMapping: Codeunit "Shpfy Customer Mapping"; - PhoneFilter: Text; + IMapping: Interface "Shpfy ICompany Mapping"; begin - if not IsNullGuid(ShopifyCompany."Customer SystemId") then - if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then - exit(true) - else begin - Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); - end; - - //JZA: Task 3 Tax ID - if IsNullGuid(ShopifyCompany."Customer SystemId") then begin - if Shop."Company Mapping Type" = Shop."Company Mapping Type"::"By Email/Phone" then begin - if TempShopifyCustomer.Email <> '' then begin - Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - if TempShopifyCustomer."Phone No." <> '' then begin - PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); - if PhoneFilter <> '' then begin - Clear(Customer); - Customer.SetFilter("Phone No.", PhoneFilter); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - end; - end; - if Shop."Company Mapping Type" = Shop."Company Mapping Type"::"By Tax Id" then begin - if ShopifyCompany."Location Id" <> 0 then begin - CompanyLocation.Get(ShopifyCompany."Location Id"); - if CompanyLocation."Tax Registration Id" <> '' then begin - Clear(Customer); - if Shop."Shpfy Comp. Tax Id Mapping" = Shop."Shpfy Comp. Tax Id Mapping"::RegistrationNo then - Customer.SetRange("Registration Number", CompanyLocation."Tax Registration Id"); - if Shop."Shpfy Comp. Tax Id Mapping" = Shop."Shpfy Comp. Tax Id Mapping"::VATRegistrationNo then - Customer.SetRange("VAT Registration No.", CompanyLocation."Tax Registration Id"); - //JZA: "Shpfy Comp. Tax Id Mapping" enum is extended publisher is needed - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - end; - end; - end; + IMapping := Shop."Company Mapping Type"; + exit(IMapping.FindMapping(ShopifyCompany, TempShopifyCustomer)); end; internal procedure SetShop(Code: Code[20]) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al index 2ce89d176..35829972e 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al @@ -8,5 +8,10 @@ codeunit 30367 "Shpfy Tax Registration No." implements "Shpfy Tax Registration I begin exit(Customer."Registration Number"); end; + + procedure SetMappingFiltersForCustomers(var Customer: Record Customer; CompanyLocation: Record "Shpfy Company Location") + begin + Customer.SetRange("Registration Number", CompanyLocation."Tax Registration Id"); + end; } diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al index 307c219b6..9ab5b0101 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al @@ -8,5 +8,10 @@ codeunit 30368 "Shpfy VAT Tax Registration No." implements "Shpfy Tax Registrati begin exit(Customer."VAT Registration No."); end; + + procedure SetMappingFiltersForCustomers(var Customer: Record Customer; CompanyLocation: Record "Shpfy Company Location") + begin + Customer.SetRange("VAT Registration No.", CompanyLocation."Tax Registration Id"); + end; } diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al index a1a0f16cf..5a4ccefb5 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al @@ -6,4 +6,6 @@ namespace Microsoft.Integration.Shopify; interface "Shpfy ICompany Mapping" { procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] + + procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al similarity index 60% rename from Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al rename to Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al index 01e5eb874..67a1554df 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxIdMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al @@ -5,4 +5,6 @@ using Microsoft.Sales.Customer; interface "Shpfy Tax Registration Id Mapping" { procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + + procedure SetMappingFiltersForCustomers(var Customer: Record Customer; CompanyLocation: Record "Shpfy Company Location"); } \ No newline at end of file From 2e90b5d5d3d00d05a690f4fae4cb433431a66117 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Wed, 9 Oct 2024 08:45:03 +0300 Subject: [PATCH 09/33] Implemented Export and Import for Company Location Payment Terms --- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 31 +++++++++++++++++++ .../Codeunits/ShpfyCompanyExport.Codeunit.al | 16 ++++++++++ .../Pages/ShpfyCompLocations.Page.al | 4 +++ .../Tables/ShpfyCompanyLocation.Table.al | 5 +++ .../Codeunits/ShpfyUpdateCustomer.Codeunit.al | 13 ++++++++ .../Codeunits/ShpfyGQLCompany.Codeunit.al | 2 +- 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index a8bd157ec..298a2d399 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -75,6 +75,10 @@ codeunit 30286 "Shpfy Company API" GraphQuery := CreateGraphQueryUpdateLocationTaxId(CompanyLocation); if GraphQuery <> '' then JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); + + GraphQuery := CreateGraphQueryUpdateCompanyLocationPaymentTerms(CompanyLocation); + if GraphQuery <> '' then + JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); end; internal procedure SetShop(ShopifyShop: Record "Shpfy Shop") @@ -106,6 +110,7 @@ codeunit 30286 "Shpfy Company API" internal procedure CreateCompanyGraphQLQuery(var ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; ShopifyCustomer: Record "Shpfy Customer"): Text var GraphQuery: TextBuilder; + PaymentTermsTemplateIdTxt: Label 'gid://shopify/PaymentTermsTemplate/%1', Comment = '%1 = Payment Terms Template Id', Locked = true; begin GraphQuery.Append('{"query":"mutation {companyCreate(input: {company: {'); if ShopifyCompany.Name <> '' then @@ -135,6 +140,10 @@ codeunit 30286 "Shpfy Company API" AddFieldToGraphQuery(GraphQuery, 'countryCode', CompanyLocation."Country/Region Code", false); if CompanyLocation."Province Code" <> '' then AddFieldToGraphQuery(GraphQuery, 'zoneCode', CompanyLocation."Province Code"); + if CompanyLocation."Shpfy Payment Terms Id" <> 0 then begin + GraphQuery.Append('}, buyerExperienceConfiguration: {'); + AddFieldToGraphQuery(GraphQuery, 'paymentTermsTemplateId', StrSubstNo(PaymentTermsTemplateIdTxt, CompanyLocation."Shpfy Payment Terms Id")); + end; GraphQuery.Remove(GraphQuery.Length - 1, 2); GraphQuery.Append('}}}) {company {id, name, locations(first: 1) {edges {node {id, name}}}, contactRoles(first:10) {edges {node {id,name}}}}, userErrors {field, message}}}"}'); exit(GraphQuery.ToText()); @@ -248,6 +257,27 @@ codeunit 30286 "Shpfy Company API" end; end; + internal procedure CreateGraphQueryUpdateCompanyLocationPaymentTerms(var CompanyLocation: Record "Shpfy Company Location"): Text + var + xCompanyLocation: Record "Shpfy Company Location"; + HasChange: Boolean; + GraphQuery: TextBuilder; + CompanyLocationIdTxt: Label 'gid://shopify/CompanyLocation/%1', Comment = '%1 = Company Location Id', Locked = true; + PaymentTermsTemplateIdTxt: Label 'gid://shopify/PaymentTermsTemplate/%1', Comment = '%1 = Payment Terms Template Id', Locked = true; + begin + xCompanyLocation.Get(CompanyLocation.Id); + GraphQuery.Append('{"query":"mutation {companyLocationUpdate(companyLocationId: \"' + StrSubstNo(CompanyLocationIdTxt, CompanyLocation.Id) + '\", input: {'); + GraphQuery.Append('buyerExperienceConfiguration: {'); + if CompanyLocation."Shpfy Payment Terms Id" <> xCompanyLocation."Shpfy Payment Terms Id" then + HasChange := AddFieldToGraphQuery(GraphQuery, 'paymentTermsTemplateId', StrSubstNo(PaymentTermsTemplateIdTxt, CompanyLocation."Shpfy Payment Terms Id")); + GraphQuery.Remove(GraphQuery.Length - 1, 2); + + if HasChange then begin + GraphQuery.Append('}}) {companyLocation {id, name}, userErrors {field, message}}}"}'); + exit(GraphQuery.ToText()); + end; + end; + internal procedure RetrieveShopifyCompanyIds(var CompanyIds: Dictionary of [BigInteger, DateTime]) var Id: BigInteger; @@ -377,6 +407,7 @@ codeunit 30286 "Shpfy Company API" PhoneNo := CopyStr(DelChr(PhoneNo, '=', DelChr(PhoneNo, '=', '1234567890/+ .()')), 1, MaxStrLen(CompanyLocation."Phone No.")); CompanyLocation."Phone No." := CopyStr(PhoneNo, 1, MaxStrLen(CompanyLocation."Phone No.")); CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); + CompanyLocation."Shpfy Payment Terms Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.buyerExperienceConfiguration.paymentTermsTemplate.id')); if IsDefaultCompanyLocation then begin CompanyLocation.Default := IsDefaultCompanyLocation; IsDefaultCompanyLocation := false; 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 554b573cb..f43499194 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -90,6 +90,7 @@ codeunit 30284 "Shpfy Company Export" TempCompanyLocation: Record "Shpfy Company Location" temporary; ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; CountyCodeTooLongErr: Text; + ShpfyPaymentTermsId: BigInteger; begin TempShopifyCompany := ShopifyCompany; TempCompanyLocation := CompanyLocation; @@ -148,6 +149,9 @@ codeunit 30284 "Shpfy Company Export" ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; CompanyLocation."Tax Registration Id" := ShpfyTaxRegistrationIdMapping.GetTaxRegistrationId(Customer); + if GetShpfyPaymentTermsIdFromCustomer(Customer, ShpfyPaymentTermsId) then + CompanyLocation."Shpfy Payment Terms Id" := ShpfyPaymentTermsId; + if HasDiff(ShopifyCompany, TempShopifyCompany) or HasDiff(CompanyLocation, TempCompanyLocation) then begin ShopifyCompany."Last Updated by BC" := CurrentDateTime; exit(true); @@ -206,4 +210,16 @@ codeunit 30284 "Shpfy Company Export" begin CreateCustomers := NewCustomers; end; + + local procedure GetShpfyPaymentTermsIdFromCustomer(Customer: Record Customer; var ShpfyPaymentTermsId: BigInteger): Boolean + var + ShpfyPaymentTerms: Record "Shpfy Payment Terms"; + begin + ShpfyPaymentTerms.SetRange("Shop Code", Shop.Code); + ShpfyPaymentTerms.SetRange("Payment Terms Code", Customer."Payment Terms Code"); + if ShpfyPaymentTerms.FindFirst() then begin + ShpfyPaymentTermsId := ShpfyPaymentTerms.Id; + exit(true); + end; + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al index b8beb06e2..e6f9073c4 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al @@ -75,6 +75,10 @@ page 30165 "Shpfy Comp. Locations" { ToolTip = 'Specifies the tax registration identifier of the company location.'; } + field("Shpfy Payment Terms Id"; Rec."Shpfy Payment Terms Id") + { + ToolTip = 'Specifies the Shopify Payment Terms Id which is mapped with Customer''s Payment Terms.'; + } } } } diff --git a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al index 608cf67e7..1211b7b6f 100644 --- a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al +++ b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al @@ -78,6 +78,11 @@ table 30151 "Shpfy Company Location" Caption = 'Default'; DataClassification = CustomerContent; } + field(14; "Shpfy Payment Terms Id"; BigInteger) + { + Caption = 'Shpfy Payment Terms Id'; + DataClassification = CustomerContent; + } } keys { diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al index 1f862702c..fd7090ec6 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al @@ -165,6 +165,9 @@ codeunit 30124 "Shpfy Update Customer" Customer.Validate("VAT Bus. Posting Group", ShopifyTaxArea."VAT Bus. Posting Group"); end; + if CompanyLocation."Shpfy Payment Terms Id" <> 0 then + Customer.Validate("Payment Terms Code", GetPaymentTermsCodeFromShopifyPaymentTermsId(CompanyLocation."Shpfy Payment Terms Id")); + Customer.Modify(); end; @@ -186,4 +189,14 @@ codeunit 30124 "Shpfy Update Customer" begin Shop := ShopifyShop; end; + + local procedure GetPaymentTermsCodeFromShopifyPaymentTermsId(ShpfyPaymentTermsId: BigInteger): Code[10] + var + ShpfyPaymentTerms: Record "Shpfy Payment Terms"; + begin + ShpfyPaymentTerms.SetRange("Shop Code", Shop.Code); + ShpfyPaymentTerms.SetRange(Id, ShpfyPaymentTermsId); + if ShpfyPaymentTerms.FindFirst() then + exit(ShpfyPaymentTerms."Payment Terms Code"); + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al index 1c2192951..a4e7cda2b 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:20, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:20, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} buyerExperienceConfiguration {paymentTermsTemplate {id}} taxRegistrationId}}}}}"}'); end; /// From 7916a9e0d2e3572ecbc5ca5e7b1e14946e5847e1 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Wed, 9 Oct 2024 10:11:41 +0300 Subject: [PATCH 10/33] Re-implemented logic to get Graph queries to Interfces --- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 51 +++++++------------ ...hpfyGQLCreateCompLocationTaxID.Codeunit.al | 27 ++++++++++ .../ShpfyGQLUpdateLocPmtTerms.Codeunit.al | 27 ++++++++++ .../GraphQL/Enums/ShpfyGraphQLType.Enum.al | 10 ++++ 4 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCreateCompLocationTaxID.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLUpdateLocPmtTerms.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 298a2d399..12e8ed735 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -71,14 +71,9 @@ codeunit 30286 "Shpfy Company API" if GraphQuery <> '' then JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); - //JZA: Task 3 Tax ID - GraphQuery := CreateGraphQueryUpdateLocationTaxId(CompanyLocation); - if GraphQuery <> '' then - JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); + CreateGraphQueryUpdateCompanyLocationTaxId(CompanyLocation); - GraphQuery := CreateGraphQueryUpdateCompanyLocationPaymentTerms(CompanyLocation); - if GraphQuery <> '' then - JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); + CreateGraphQueryUpdateCompanyLocationPaymentTerms(CompanyLocation); end; internal procedure SetShop(ShopifyShop: Record "Shpfy Shop") @@ -238,44 +233,36 @@ codeunit 30286 "Shpfy Company API" end; end; - internal procedure CreateGraphQueryUpdateLocationTaxId(var CompanyLocation: Record "Shpfy Company Location"): Text + internal procedure CreateGraphQueryUpdateCompanyLocationTaxId(var CompanyLocation: Record "Shpfy Company Location"): Text var xCompanyLocation: Record "Shpfy Company Location"; - HasChange: Boolean; - GraphQuery: TextBuilder; - CompanyLocationIdTxt: Label 'gid://shopify/CompanyLocation/%1', Comment = '%1 = Company Location Id', Locked = true; + CommunicationMgt: Codeunit "Shpfy Communication Mgt."; + GraphQLType: Enum "Shpfy GraphQL Type"; + Parameters: Dictionary of [Text, Text]; begin xCompanyLocation.Get(CompanyLocation.Id); - GraphQuery.Append('{"query":"mutation {companyLocationCreateTaxRegistration(locationId: \"' + StrSubstNo(CompanyLocationIdTxt, CompanyLocation.Id) + '\", '); - if CompanyLocation."Tax Registration Id" <> xCompanyLocation."Tax Registration Id" then - HasChange := AddFieldToGraphQuery(GraphQuery, 'taxId', CompanyLocation."Tax Registration Id"); - GraphQuery.Remove(GraphQuery.Length - 1, 2); + if CompanyLocation."Tax Registration Id" = xCompanyLocation."Tax Registration Id" then + exit; - if HasChange then begin - GraphQuery.Append(') {companyLocation {id, name, taxRegistrationId}, userErrors {field, message}}}"}'); - exit(GraphQuery.ToText()); - end; + Parameters.Add('LocationId', Format(CompanyLocation.Id)); + Parameters.Add('TaxId', Format(CompanyLocation."Tax Registration Id")); + CommunicationMgt.ExecuteGraphQL(GraphQLType::CreateCompanyLocationTaxId, Parameters); end; internal procedure CreateGraphQueryUpdateCompanyLocationPaymentTerms(var CompanyLocation: Record "Shpfy Company Location"): Text var xCompanyLocation: Record "Shpfy Company Location"; - HasChange: Boolean; - GraphQuery: TextBuilder; - CompanyLocationIdTxt: Label 'gid://shopify/CompanyLocation/%1', Comment = '%1 = Company Location Id', Locked = true; - PaymentTermsTemplateIdTxt: Label 'gid://shopify/PaymentTermsTemplate/%1', Comment = '%1 = Payment Terms Template Id', Locked = true; + CommunicationMgt: Codeunit "Shpfy Communication Mgt."; + GraphQLType: Enum "Shpfy GraphQL Type"; + Parameters: Dictionary of [Text, Text]; begin xCompanyLocation.Get(CompanyLocation.Id); - GraphQuery.Append('{"query":"mutation {companyLocationUpdate(companyLocationId: \"' + StrSubstNo(CompanyLocationIdTxt, CompanyLocation.Id) + '\", input: {'); - GraphQuery.Append('buyerExperienceConfiguration: {'); - if CompanyLocation."Shpfy Payment Terms Id" <> xCompanyLocation."Shpfy Payment Terms Id" then - HasChange := AddFieldToGraphQuery(GraphQuery, 'paymentTermsTemplateId', StrSubstNo(PaymentTermsTemplateIdTxt, CompanyLocation."Shpfy Payment Terms Id")); - GraphQuery.Remove(GraphQuery.Length - 1, 2); + if CompanyLocation."Shpfy Payment Terms Id" = xCompanyLocation."Shpfy Payment Terms Id" then + exit; - if HasChange then begin - GraphQuery.Append('}}) {companyLocation {id, name}, userErrors {field, message}}}"}'); - exit(GraphQuery.ToText()); - end; + Parameters.Add('LocationId', Format(CompanyLocation.Id)); + Parameters.Add('PaymentTermsId', Format(CompanyLocation."Shpfy Payment Terms Id")); + CommunicationMgt.ExecuteGraphQL(GraphQLType::UpdateCompanyLocationPaymentTerms, Parameters); end; internal procedure RetrieveShopifyCompanyIds(var CompanyIds: Dictionary of [BigInteger, DateTime]) diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCreateCompLocationTaxID.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCreateCompLocationTaxID.Codeunit.al new file mode 100644 index 000000000..dfe7c5efa --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCreateCompLocationTaxID.Codeunit.al @@ -0,0 +1,27 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Codeunit Shpfy GQL CreateCompLocTaxId (ID 30369) implements Interface Shpfy IGraphQL. +/// +codeunit 30369 "Shpfy GQL CreateCompLocTaxId" implements "Shpfy IGraphQL" +{ + Access = Internal; + + /// + /// GetGraphQL. + /// + /// Return value of type Text. + internal procedure GetGraphQL(): Text + begin + exit('{"query":"mutation {companyLocationCreateTaxRegistration(locationId: \"gid://shopify/CompanyLocation/{{LocationId}}\", taxId: \"{{TaxId}}\") {companyLocation {id, name, taxRegistrationId}, userErrors {field, message}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + internal procedure GetExpectedCost(): Integer + begin + exit(4); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLUpdateLocPmtTerms.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLUpdateLocPmtTerms.Codeunit.al new file mode 100644 index 000000000..2298fa6c7 --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLUpdateLocPmtTerms.Codeunit.al @@ -0,0 +1,27 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Codeunit Shpfy GQL UpdateLocPmtTerms (ID 30370) implements Interface Shpfy IGraphQL. +/// +codeunit 30370 "Shpfy GQL UpdateLocPmtTerms" implements "Shpfy IGraphQL" +{ + Access = Internal; + + /// + /// GetGraphQL. + /// + /// Return value of type Text. + internal procedure GetGraphQL(): Text + begin + exit('{"query":"mutation {companyLocationUpdate(companyLocationId: \"gid://shopify/CompanyLocation/{{LocationId}}\", input: {buyerExperienceConfiguration: {paymentTermsTemplateId: \"gid://shopify/PaymentTermsTemplate/{{PaymentTermsId}}\"}}) {companyLocation {id, name}, userErrors {field, message}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + internal procedure GetExpectedCost(): Integer + begin + exit(4); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al index dab96ed8a..8d6fed24c 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al @@ -490,4 +490,14 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL" Caption = 'Get Product Image'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL GetProductImage"; } + value(98; CreateCompanyLocationTaxId) + { + Caption = 'Create Company Location Tax Id'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL CreateCompLocTaxId"; + } + value(99; UpdateCompanyLocationPaymentTerms) + { + Caption = 'Update Company Location Payment Terms'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL UpdateLocPmtTerms"; + } } From a3491c03b2bbeb8fb4f9b063b4878d330732ac3b Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Wed, 9 Oct 2024 10:58:04 +0300 Subject: [PATCH 11/33] Fixes after PR review --- .../Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al | 3 +-- .../Shopify/app/src/Base/Tables/ShpfyShop.Table.al | 1 - .../Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al | 2 +- .../Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al | 3 --- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 2 -- .../Codeunits/ShpfyTaxRegistrationNo.Codeunit.al | 6 ++++-- .../Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al | 6 ++++-- .../Companies/Enums/ShpfyCompTaxIdMapping.Enum.al | 4 ++-- .../src/Companies/Enums/ShpfyCompanyMapping.Enum.al | 1 - .../ShpfyITaxRegistrationIdMapping.Interface.al | 3 +++ .../app/src/Companies/Pages/ShpfyCompanyCard.Page.al | 12 ++++++++++++ 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al b/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al index f967b804e..57edc747d 100644 --- a/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al +++ b/Apps/W1/Shopify/app/src/Base/Pages/ShpfyShopCard.Page.al @@ -425,11 +425,10 @@ page 30101 "Shpfy Shop Card" ApplicationArea = All; ToolTip = 'Specifies how to map companies.'; } - //JZA: Task 3 Tax ID field("Shpfy Comp.Tax Id Mapping"; Rec."Shpfy Comp. Tax Id Mapping") { ApplicationArea = All; - ToolTip = 'Specifies how to map Shopify Tax ID.'; + ToolTip = 'Specifies how to map Shopify Tax ID with Business Central.'; } field("Auto Create Unknown Companies"; Rec."Auto Create Unknown Companies") { diff --git a/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al b/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al index 0717e006e..b0e7981ca 100644 --- a/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al +++ b/Apps/W1/Shopify/app/src/Base/Tables/ShpfyShop.Table.al @@ -788,7 +788,6 @@ table 30102 "Shpfy Shop" Caption = 'Weight Unit'; DataClassification = CustomerContent; } - //JZA: Task 3 Tax ID field(130; "Shpfy Comp. Tax Id Mapping"; Enum "Shpfy Comp. Tax Id Mapping") { Caption = 'Company Tax Id Mapping'; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index 59fb5c9cc..86f0d0651 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -3,7 +3,7 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; /// -/// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. +/// Codeunit Shpfy Comp. By Tax Id (ID 30366) implements Interface Shpfy ICompany Mapping. /// codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" { diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 12e8ed735..a1c8ffb76 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -24,13 +24,11 @@ codeunit 30286 "Shpfy Company API" CompanyContactId: BigInteger; CompanyContactRoles: Dictionary of [Text, BigInteger]; begin - //JZA: Task 5 - External ID GraphQuery := CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); if JResponse.SelectToken('$.data.companyCreate.company', JItem) then if JItem.IsObject then ShopifyCompany.Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'id')); - // JZA: Task2 - Task is only for Company location import. Exports won't work with for all locations if JsonHelper.GetJsonArray(JResponse, JLocations, 'data.companyCreate.company.locations.edges') then if JLocations.Count = 1 then if JLocations.Get(0, JItem) then begin @@ -110,7 +108,6 @@ codeunit 30286 "Shpfy Company API" GraphQuery.Append('{"query":"mutation {companyCreate(input: {company: {'); if ShopifyCompany.Name <> '' then AddFieldToGraphQuery(GraphQuery, 'name', ShopifyCompany.Name); - //JZA: Task 5 - External ID ShopifyCustomer.CalcFields("Customer No."); if ShopifyCustomer."Customer No." <> '' then AddFieldToGraphQuery(GraphQuery, 'externalId', ShopifyCustomer."Customer No."); 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 f43499194..221ab9dc2 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -145,7 +145,6 @@ codeunit 30284 "Shpfy Company Export" CompanyLocation."Phone No." := Customer."Phone No."; - //JZA: Task 3 Tax ID ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; CompanyLocation."Tax Registration Id" := ShpfyTaxRegistrationIdMapping.GetTaxRegistrationId(Customer); @@ -196,7 +195,6 @@ codeunit 30284 "Shpfy Company Export" exit; CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); - CompanyLocation.SetRange(Default, true); CompanyLocation.FindFirst(); if FillInShopifyCompany(Customer, ShopifyCompany, CompanyLocation) then begin diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al index 35829972e..786f27ffb 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al @@ -2,6 +2,9 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; +/// +/// Codeunit Shpfy Tax Registration No. (ID 30367) implements Interface Shpfy Tax Registration Id Mapping. +/// codeunit 30367 "Shpfy Tax Registration No." implements "Shpfy Tax Registration Id Mapping" { procedure GetTaxRegistrationId(var Customer: Record Customer): Text; @@ -13,5 +16,4 @@ codeunit 30367 "Shpfy Tax Registration No." implements "Shpfy Tax Registration I begin Customer.SetRange("Registration Number", CompanyLocation."Tax Registration Id"); end; -} - +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al index 9ab5b0101..0a5bc8a3a 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al @@ -2,6 +2,9 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; +/// +/// Codeunit Shpfy VAT Tax Registration No. (ID 30368) implements Interface Shpfy Tax Registration Id Mapping. +/// codeunit 30368 "Shpfy VAT Tax Registration No." implements "Shpfy Tax Registration Id Mapping" { procedure GetTaxRegistrationId(var Customer: Record Customer): Text; @@ -13,5 +16,4 @@ codeunit 30368 "Shpfy VAT Tax Registration No." implements "Shpfy Tax Registrati begin Customer.SetRange("VAT Registration No.", CompanyLocation."Tax Registration Id"); end; -} - +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al index c678725b3..5faa7a851 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompTaxIdMapping.Enum.al @@ -1,7 +1,7 @@ namespace Microsoft.Integration.Shopify; -//JZA: Task 3 Tax ID + /// -/// Enum Shopify Company Tax Id Mapping (ID 30165). +/// Enum Shopify Company Tax Id Mapping (ID 30165) implements Interface Shpfy Tax Registration Id Mapping. /// enum 30165 "Shpfy Comp. Tax Id Mapping" implements "Shpfy Tax Registration Id Mapping" { diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index c9bfa6e63..dea750060 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -13,7 +13,6 @@ enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping" Caption = 'By Email/Phone'; Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; } - //JZA: Task 3 Tax ID value(1; "By Tax Id") { Caption = 'By Tax Id'; diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al index 67a1554df..ce39e235d 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al @@ -2,6 +2,9 @@ namespace Microsoft.Integration.Shopify; using Microsoft.Sales.Customer; +/// +/// Interface "Shpfy Tax Registration Id Mapping" +/// interface "Shpfy Tax Registration Id Mapping" { procedure GetTaxRegistrationId(var Customer: Record Customer): Text; diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al index 8980b7073..80d5470e7 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompanyCard.Page.al @@ -163,6 +163,18 @@ page 30157 "Shpfy Company Card" RunPageLink = "Company SystemId" = field(SystemId); ToolTip = 'View a list of Shopify catalogs for the company.'; } + action(ShopifyLocations) + { + ApplicationArea = All; + Caption = 'Shopify Locations'; + Image = Warehouse; + Promoted = true; + PromotedOnly = true; + PromotedCategory = Category4; + RunObject = Page "Shpfy Comp. Locations"; + RunPageLink = "Company SystemId" = field(SystemId); + ToolTip = 'View a list of Shopify company locations.'; + } } } From 8ca4d533126cbc83ba7d625667542547a8f76069 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Thu, 17 Oct 2024 12:06:09 +0300 Subject: [PATCH 12/33] Changes after PR review --- .../ShpfyCompByDefaultComp.Codeunit.al | 6 +- .../ShpfyCompByEmailPhone.Codeunit.al | 100 ++++++++++-------- .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 63 ++++++----- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 59 ++++++----- .../ShpfyTaxRegistrationNo.Codeunit.al | 4 +- .../ShpfyVATTaxRegistrationNo.Codeunit.al | 4 +- .../Enums/ShpfyCompanyMapping.Enum.al | 11 +- ...hpfyTaxRegistrationIdMapping.Interface.al} | 2 +- .../Pages/ShpfyCompLocations.Page.al | 75 +++---------- .../Tables/ShpfyCompanyLocation.Table.al | 14 +++ 10 files changed, 167 insertions(+), 171 deletions(-) rename Apps/W1/Shopify/app/src/Companies/Interfaces/{ShpfyITaxRegistrationIdMapping.Interface.al => ShpfyTaxRegistrationIdMapping.Interface.al} (96%) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al index 1cff66bec..2efaaa994 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al @@ -29,7 +29,7 @@ codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping exit(true) else begin Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); end; if IsNullGuid(ShopifyCompany."Customer SystemId") then begin @@ -40,11 +40,11 @@ codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin ShopifyCustomer.Copy(TempShopifyCustomer); ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); + ShopifyCustomer.Insert(true); end; ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); exit(true); end; end; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al index 97bd62d09..ec1849fe9 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al @@ -13,74 +13,38 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" var ShopifyCompany: Record "Shpfy Company"; begin - ShopifyCompany.SetAutoCalcFields("Customer No."); if ShopifyCompany.Get(CompanyId) then begin if not IsNullGuid(ShopifyCompany."Customer SystemId") then begin ShopifyCompany.CalcFields("Customer No."); if ShopifyCompany."Customer No." = '' then begin Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); end else exit(ShopifyCompany."Customer No."); end; exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); end else exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); - exit(''); end; internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean var Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; - CustomerMapping: Codeunit "Shpfy Customer Mapping"; - PhoneFilter: Text; begin if not IsNullGuid(ShopifyCompany."Customer SystemId") then if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then exit(true) else begin Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); end; if IsNullGuid(ShopifyCompany."Customer SystemId") then begin - if TempShopifyCustomer.Email <> '' then begin - Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; + if TempShopifyCustomer.Email <> '' then + exit(FindByEmail(ShopifyCompany, TempShopifyCustomer)); - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - if TempShopifyCustomer."Phone No." <> '' then begin - PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); - if PhoneFilter <> '' then begin - Clear(Customer); - Customer.SetFilter("Phone No.", PhoneFilter); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; - end; + if TempShopifyCustomer."Phone No." <> '' then + exit(FindByPhoneNo(ShopifyCompany, TempShopifyCustomer)); end; end; @@ -94,11 +58,61 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" CompanyImport.SetAllowCreate(AllowCreate); CompanyImport.SetTemplateCode(TemplateCode); TempCompany.Id := CompanyId; - TempCompany.Insert(); + TempCompany.Insert(false); + CompanyImport.Run(TempCompany); CompanyImport.GetCompany(ShopifyCompany); if ShopifyCompany.Find() then ShopifyCompany.CalcFields("Customer No."); + exit(ShopifyCompany."Customer No."); end; + + local procedure FindByEmail(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + begin + Customer.SetFilter("E-Mail", '@' + TempShopifyCustomer.Email); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(true); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(true); + exit(true); + end; + end; + + local procedure FindByPhoneNo(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + CustomerMapping: Codeunit "Shpfy Customer Mapping"; + PhoneFilter: Text; + begin + PhoneFilter := CustomerMapping.CreatePhoneFilter(TempShopifyCustomer."Phone No."); + if PhoneFilter <> '' then begin + Clear(Customer); + Customer.SetFilter("Phone No.", PhoneFilter); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(true); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(true); + exit(true); + end; + end; + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index 86f0d0651..43ade17b2 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -13,62 +13,39 @@ codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" var ShopifyCompany: Record "Shpfy Company"; begin - ShopifyCompany.SetAutoCalcFields("Customer No."); if ShopifyCompany.Get(CompanyId) then begin if not IsNullGuid(ShopifyCompany."Customer SystemId") then begin ShopifyCompany.CalcFields("Customer No."); if ShopifyCompany."Customer No." = '' then begin Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); end else exit(ShopifyCompany."Customer No."); end; exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); end else exit(CreateCompany(CompanyId, ShopCode, TemplateCode, AllowCreate)); - exit(''); end; internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean var Customer: Record Customer; - ShopifyCustomer: Record "Shpfy Customer"; - Shop: Record "Shpfy Shop"; CompanyLocation: Record "Shpfy Company Location"; - ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; begin if not IsNullGuid(ShopifyCompany."Customer SystemId") then if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then exit(true) else begin Clear(ShopifyCompany."Customer SystemId"); - ShopifyCompany.Modify(); + ShopifyCompany.Modify(true); end; - if IsNullGuid(ShopifyCompany."Customer SystemId") then begin + if IsNullGuid(ShopifyCompany."Customer SystemId") then if ShopifyCompany."Location Id" <> 0 then begin CompanyLocation.Get(ShopifyCompany."Location Id"); - if CompanyLocation."Tax Registration Id" <> '' then begin - Clear(Customer); - Shop.Get(ShopifyCompany."Shop Code"); - ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; - ShpfyTaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); - if Customer.FindFirst() then begin - ShopifyCompany."Customer SystemId" := Customer.SystemId; - - if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin - ShopifyCustomer.Copy(TempShopifyCustomer); - ShopifyCustomer."Customer SystemId" := Customer.SystemId; - ShopifyCustomer.Insert(); - end; - - ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; - ShopifyCompany.Modify(); - exit(true); - end; - end; + if CompanyLocation."Tax Registration Id" <> '' then + exit(FindByTaxRegistrationId(ShopifyCompany, TempShopifyCustomer, CompanyLocation)); end; - end; end; local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] @@ -81,11 +58,39 @@ codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" CompanyImport.SetAllowCreate(AllowCreate); CompanyImport.SetTemplateCode(TemplateCode); TempCompany.Id := CompanyId; - TempCompany.Insert(); + TempCompany.Insert(false); + CompanyImport.Run(TempCompany); CompanyImport.GetCompany(ShopifyCompany); if ShopifyCompany.Find() then ShopifyCompany.CalcFields("Customer No."); + exit(ShopifyCompany."Customer No."); end; + + local procedure FindByTaxRegistrationId(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary; CompanyLocation: Record "Shpfy Company Location"): Boolean + var + Customer: Record Customer; + ShopifyCustomer: Record "Shpfy Customer"; + Shop: Record "Shpfy Shop"; + ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + begin + Clear(Customer); + Shop.Get(ShopifyCompany."Shop Code"); + ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; + ShpfyTaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); + if Customer.FindFirst() then begin + ShopifyCompany."Customer SystemId" := Customer.SystemId; + + if not ShopifyCustomer.Get(TempShopifyCustomer.Id) then begin + ShopifyCustomer.Copy(TempShopifyCustomer); + ShopifyCustomer."Customer SystemId" := Customer.SystemId; + ShopifyCustomer.Insert(true); + end; + + ShopifyCompany."Main Contact Customer Id" := ShopifyCustomer.Id; + ShopifyCompany.Modify(true); + exit(true); + end; + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index a1c8ffb76..635bb5dff 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -69,9 +69,9 @@ codeunit 30286 "Shpfy Company API" if GraphQuery <> '' then JResponse := CommunicationMgt.ExecuteGraphQL(GraphQuery); - CreateGraphQueryUpdateCompanyLocationTaxId(CompanyLocation); + UpdateCompanyLocationTaxId(CompanyLocation); - CreateGraphQueryUpdateCompanyLocationPaymentTerms(CompanyLocation); + UpdateCompanyLocationPaymentTerms(CompanyLocation); end; internal procedure SetShop(ShopifyShop: Record "Shpfy Shop") @@ -230,10 +230,9 @@ codeunit 30286 "Shpfy Company API" end; end; - internal procedure CreateGraphQueryUpdateCompanyLocationTaxId(var CompanyLocation: Record "Shpfy Company Location"): Text + internal procedure UpdateCompanyLocationTaxId(var CompanyLocation: Record "Shpfy Company Location") var xCompanyLocation: Record "Shpfy Company Location"; - CommunicationMgt: Codeunit "Shpfy Communication Mgt."; GraphQLType: Enum "Shpfy GraphQL Type"; Parameters: Dictionary of [Text, Text]; begin @@ -246,10 +245,9 @@ codeunit 30286 "Shpfy Company API" CommunicationMgt.ExecuteGraphQL(GraphQLType::CreateCompanyLocationTaxId, Parameters); end; - internal procedure CreateGraphQueryUpdateCompanyLocationPaymentTerms(var CompanyLocation: Record "Shpfy Company Location"): Text + internal procedure UpdateCompanyLocationPaymentTerms(var CompanyLocation: Record "Shpfy Company Location") var xCompanyLocation: Record "Shpfy Company Location"; - CommunicationMgt: Codeunit "Shpfy Communication Mgt."; GraphQLType: Enum "Shpfy GraphQL Type"; Parameters: Dictionary of [Text, Text]; begin @@ -338,14 +336,8 @@ codeunit 30286 "Shpfy Company API" internal procedure UpdateShopifyCompanyFields(var ShopifyCompany: Record "Shpfy Company"; JCompany: JsonObject) Result: Boolean var - CompanyLocation: Record "Shpfy Company Location"; UpdatedAt: DateTime; - JLocations: JsonArray; - JItem: JsonToken; OutStream: OutStream; - PhoneNo: Text; - IsDefaultCompanyLocation: Boolean; - CompanyLocationId: BigInteger; begin UpdatedAt := JsonHelper.GetValueAsDateTime(JCompany, 'updatedAt'); if UpdatedAt <= ShopifyCompany."Updated At" then @@ -365,10 +357,22 @@ codeunit 30286 "Shpfy Company API" Clear(ShopifyCompany.Note); ShopifyCompany.Modify(); + UpdateShopifyCompanyLocationFields(ShopifyCompany, JCompany); + end; + + local procedure UpdateShopifyCompanyLocationFields(var ShopifyCompany: Record "Shpfy Company"; var JCompany: JsonObject) + var + CompanyLocation: Record "Shpfy Company Location"; + JLocations: JsonArray; + JLocation: JsonToken; + PhoneNo: Text; + IsDefaultCompanyLocation: Boolean; + CompanyLocationId: BigInteger; + begin IsDefaultCompanyLocation := true; if JsonHelper.GetJsonArray(JCompany, JLocations, 'locations.edges') then - foreach JItem in JLocations do begin - CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.id')); + foreach JLocation in JLocations do begin + CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLocation, 'node.id')); if IsDefaultCompanyLocation then ShopifyCompany."Location Id" := CompanyLocationId; @@ -376,28 +380,29 @@ codeunit 30286 "Shpfy Company API" if not CompanyLocation.FindFirst() then begin CompanyLocation.Id := CompanyLocationId; CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; - CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); + CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); CompanyLocation.Insert(); end; - CompanyLocation.Address := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address1', MaxStrLen(CompanyLocation.Address)), 1, MaxStrLen(CompanyLocation.Address)); - CompanyLocation."Address 2" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.address2', MaxStrLen(CompanyLocation."Address 2")), 1, MaxStrLen(CompanyLocation."Address 2")); - CompanyLocation.Zip := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.zip', MaxStrLen(CompanyLocation.Zip)), 1, MaxStrLen(CompanyLocation.Zip)); - CompanyLocation.City := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.city', MaxStrLen(CompanyLocation.City)), 1, MaxStrLen(CompanyLocation.City)); - CompanyLocation."Country/Region Code" := CopyStr(JsonHelper.GetValueAsCode(JItem, 'node.billingAddress.countryCode', MaxStrLen(CompanyLocation."Country/Region Code")), 1, MaxStrLen(CompanyLocation."Country/Region Code")); - CompanyLocation."Province Code" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.zoneCode', MaxStrLen(CompanyLocation."Province Code")), 1, MaxStrLen(CompanyLocation."Province Code")); - CompanyLocation."Province Name" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.billingAddress.province', MaxStrLen(CompanyLocation."Province Name")), 1, MaxStrLen(CompanyLocation."Province Name")); - PhoneNo := JsonHelper.GetValueAsText(JItem, 'node.billingAddress.phone'); + CompanyLocation.Address := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.address1', MaxStrLen(CompanyLocation.Address)), 1, MaxStrLen(CompanyLocation.Address)); + CompanyLocation."Address 2" := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.address2', MaxStrLen(CompanyLocation."Address 2")), 1, MaxStrLen(CompanyLocation."Address 2")); + CompanyLocation.Zip := CopyStr(JsonHelper.GetValueAsCode(JLocation, 'node.billingAddress.zip', MaxStrLen(CompanyLocation.Zip)), 1, MaxStrLen(CompanyLocation.Zip)); + CompanyLocation.City := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.city', MaxStrLen(CompanyLocation.City)), 1, MaxStrLen(CompanyLocation.City)); + CompanyLocation."Country/Region Code" := CopyStr(JsonHelper.GetValueAsCode(JLocation, 'node.billingAddress.countryCode', MaxStrLen(CompanyLocation."Country/Region Code")), 1, MaxStrLen(CompanyLocation."Country/Region Code")); + CompanyLocation."Province Code" := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.zoneCode', MaxStrLen(CompanyLocation."Province Code")), 1, MaxStrLen(CompanyLocation."Province Code")); + CompanyLocation."Province Name" := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.province', MaxStrLen(CompanyLocation."Province Name")), 1, MaxStrLen(CompanyLocation."Province Name")); + PhoneNo := JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.phone'); PhoneNo := CopyStr(DelChr(PhoneNo, '=', DelChr(PhoneNo, '=', '1234567890/+ .()')), 1, MaxStrLen(CompanyLocation."Phone No.")); CompanyLocation."Phone No." := CopyStr(PhoneNo, 1, MaxStrLen(CompanyLocation."Phone No.")); - CompanyLocation."Tax Registration Id" := CopyStr(JsonHelper.GetValueAsText(JItem, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")), 1, MaxStrLen(CompanyLocation."Tax Registration Id")); - CompanyLocation."Shpfy Payment Terms Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JItem, 'node.buyerExperienceConfiguration.paymentTermsTemplate.id')); +#pragma warning disable AA0139 + CompanyLocation."Tax Registration Id" := JsonHelper.GetValueAsText(JLocation, 'node.taxRegistrationId', MaxStrLen(CompanyLocation."Tax Registration Id")); +#pragma warning restore AA0139 + CompanyLocation."Shpfy Payment Terms Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLocation, 'node.buyerExperienceConfiguration.paymentTermsTemplate.id')); if IsDefaultCompanyLocation then begin CompanyLocation.Default := IsDefaultCompanyLocation; IsDefaultCompanyLocation := false; end; - CompanyLocation.Modify(); - // end; + CompanyLocation.Modify(true); end; end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al index 786f27ffb..edacba5ba 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyTaxRegistrationNo.Codeunit.al @@ -7,7 +7,9 @@ using Microsoft.Sales.Customer; /// codeunit 30367 "Shpfy Tax Registration No." implements "Shpfy Tax Registration Id Mapping" { - procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + Access = Internal; + + procedure GetTaxRegistrationId(var Customer: Record Customer): Text[150]; begin exit(Customer."Registration Number"); end; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al index 0a5bc8a3a..c7ad6fa42 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyVATTaxRegistrationNo.Codeunit.al @@ -7,7 +7,9 @@ using Microsoft.Sales.Customer; /// codeunit 30368 "Shpfy VAT Tax Registration No." implements "Shpfy Tax Registration Id Mapping" { - procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + Access = Internal; + + procedure GetTaxRegistrationId(var Customer: Record Customer): Text[150]; begin exit(Customer."VAT Registration No."); end; diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index dea750060..84360d868 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -13,15 +13,14 @@ enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping" Caption = 'By Email/Phone'; Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; } - value(1; "By Tax Id") - { - Caption = 'By Tax Id'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id"; - } value(2; DefaultCompany) { Caption = 'Always take the default Company'; Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Default Comp."; } - + value(3; "By Tax Id") + { + Caption = 'By Tax Id'; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id"; + } } diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyTaxRegistrationIdMapping.Interface.al similarity index 96% rename from Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al rename to Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyTaxRegistrationIdMapping.Interface.al index ce39e235d..bb6800b84 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyITaxRegistrationIdMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyTaxRegistrationIdMapping.Interface.al @@ -7,7 +7,7 @@ using Microsoft.Sales.Customer; /// interface "Shpfy Tax Registration Id Mapping" { - procedure GetTaxRegistrationId(var Customer: Record Customer): Text; + procedure GetTaxRegistrationId(var Customer: Record Customer): Text[150]; procedure SetMappingFiltersForCustomers(var Customer: Record Customer; CompanyLocation: Record "Shpfy Company Location"); } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al index e6f9073c4..5bde451bd 100644 --- a/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al +++ b/Apps/W1/Shopify/app/src/Companies/Pages/ShpfyCompLocations.Page.al @@ -1,7 +1,5 @@ namespace Microsoft.Integration.Shopify; -using Microsoft.Sales.Customer; - /// /// Page Shpfy Company Locations (ID 30165). /// @@ -23,64 +21,21 @@ page 30165 "Shpfy Comp. Locations" { repeater(General) { - field(Id; Rec.Id) - { - ToolTip = 'Specifies the unique identifier for the company location in Shopify.'; - } - field("Company SystemId"; Rec."Company SystemId") - { - ToolTip = 'Specifies the unique identifier for the company in Shopify.'; - } - field("Default"; Rec."Default") - { - ToolTip = 'Specifies whether the location is the default location for the company.'; - } - field(Address; Rec.Address) - { - ToolTip = 'Specifies the address of the company location.'; - } - field("Address 2"; Rec."Address 2") - { - ToolTip = 'Specifies the second address line of the company location.'; - } - field(Zip; Rec.Zip) - { - ToolTip = 'Specifies the postal code of the company location.'; - } - field(City; Rec.City) - { - ToolTip = 'Specifies the city of the company location.'; - } - field("Country/Region Code"; Rec."Country/Region Code") - { - ToolTip = 'Specifies the country/region code of the company location.'; - } - field("Phone No."; Rec."Phone No.") - { - ToolTip = 'Specifies the phone number of the company location.'; - } - field(Name; Rec.Name) - { - ToolTip = 'Specifies the name of the company location.'; - } - field("Province Code"; Rec."Province Code") - { - ToolTip = 'Specifies the province code of the company location.'; - } - field("Province Name"; Rec."Province Name") - { - ToolTip = 'Specifies the province name of the company location.'; - } - field("Tax Registration Id"; Rec."Tax Registration Id") - { - ToolTip = 'Specifies the tax registration identifier of the company location.'; - } - field("Shpfy Payment Terms Id"; Rec."Shpfy Payment Terms Id") - { - ToolTip = 'Specifies the Shopify Payment Terms Id which is mapped with Customer''s Payment Terms.'; - } + field(Id; Rec.Id) { } + field("Company SystemId"; Rec."Company SystemId") { } + field("Default"; Rec."Default") { } + field(Address; Rec.Address) { } + field("Address 2"; Rec."Address 2") { } + field(Zip; Rec.Zip) { } + field(City; Rec.City) { } + field("Country/Region Code"; Rec."Country/Region Code") { } + field("Phone No."; Rec."Phone No.") { } + field(Name; Rec.Name) { } + field("Province Code"; Rec."Province Code") { } + field("Province Name"; Rec."Province Name") { } + field("Tax Registration Id"; Rec."Tax Registration Id") { } + field("Shpfy Payment Terms Id"; Rec."Shpfy Payment Terms Id") { } } } } - -} +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al index 1211b7b6f..769bef712 100644 --- a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al +++ b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al @@ -15,73 +15,87 @@ table 30151 "Shpfy Company Location" Caption = 'Id'; DataClassification = SystemMetadata; Editable = false; + ToolTip = 'Specifies the unique identifier for the company location in Shopify.'; } field(2; "Company SystemId"; Guid) { Caption = 'Company SystemId'; DataClassification = SystemMetadata; Editable = false; + ToolTip = 'Specifies the unique identifier for the company in Shopify.'; } field(3; Address; Text[100]) { Caption = 'Address'; DataClassification = CustomerContent; + ToolTip = 'Specifies the address of the company location.'; } field(4; "Address 2"; Text[100]) { Caption = 'Address 2'; DataClassification = CustomerContent; + ToolTip = 'Specifies the second address line of the company location.'; } field(5; Zip; Code[20]) { Caption = 'Zip'; DataClassification = CustomerContent; + ToolTip = 'Specifies the postal code of the company location.'; } field(6; City; Text[50]) { Caption = 'City'; DataClassification = CustomerContent; + ToolTip = 'Specifies the city of the company location.'; } field(7; "Country/Region Code"; Code[2]) { Caption = 'Country/Region Code'; DataClassification = CustomerContent; + ToolTip = 'Specifies the country/region code of the company location.'; } field(8; "Phone No."; Text[30]) { Caption = 'Phone No.'; DataClassification = CustomerContent; + ToolTip = 'Specifies the phone number of the company location.'; } field(9; Name; Text[100]) { Caption = 'Name'; DataClassification = CustomerContent; Editable = false; + ToolTip = 'Specifies the name of the company location.'; } field(10; "Province Code"; Code[2]) { Caption = 'Province'; DataClassification = CustomerContent; + ToolTip = 'Specifies the province code of the company location.'; } field(11; "Province Name"; Text[50]) { Caption = 'Province Name'; DataClassification = CustomerContent; + ToolTip = 'Specifies the province name of the company location.'; } field(12; "Tax Registration Id"; Text[150]) { Caption = 'Tax Registration Id'; DataClassification = CustomerContent; + ToolTip = 'Specifies the tax registration identifier of the company location.'; } field(13; "Default"; Boolean) { Caption = 'Default'; DataClassification = CustomerContent; + ToolTip = 'Specifies whether the location is the default location for the company.'; } field(14; "Shpfy Payment Terms Id"; BigInteger) { Caption = 'Shpfy Payment Terms Id'; DataClassification = CustomerContent; + ToolTip = 'Specifies the Shopify Payment Terms Id which is mapped with Customer''s Payment Terms.'; } } keys From 17c2f517c5e1bd57399e66a63db33139021d476e Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Thu, 17 Oct 2024 21:30:01 +0300 Subject: [PATCH 13/33] Created new interface to avoid destructive change. Created pagination for Company Locations --- .../ShpfyCompByDefaultComp.Codeunit.al | 3 +- .../ShpfyCompByEmailPhone.Codeunit.al | 6 ++-- .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 2 +- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 36 ++++++++++++++++--- .../Codeunits/ShpfyCompanyMapping.Codeunit.al | 4 +-- .../Enums/ShpfyCompanyMapping.Enum.al | 9 ++--- .../ShpfyICompanyMapping.Interface.al | 2 -- .../ShpfyICustomerCompanyMapping.Interface.al | 11 ++++++ .../ShpfyGQLCompLocations.Codeunit.al | 24 +++++++++++++ .../Codeunits/ShpfyGQLCompany.Codeunit.al | 2 +- .../ShpfyGQLNextCompLocations.Codeunit.al | 24 +++++++++++++ .../GraphQL/Enums/ShpfyGraphQLType.Enum.al | 10 ++++++ 12 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompLocations.Codeunit.al create mode 100644 Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLNextCompLocations.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al index 2efaaa994..e520397b0 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit Shpfy Comp. By Default Comp. (ID 30305) implements Interface Shpfy ICompany Mapping. /// -codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping" +codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" { Access = Internal; @@ -22,7 +22,6 @@ codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping var Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; - Shop: Record "Shpfy Shop"; begin if not IsNullGuid(ShopifyCompany."Customer SystemId") then if Customer.GetBySystemId(ShopifyCompany."Customer SystemId") then diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al index ec1849fe9..8bc5b2b23 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. /// -codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" +codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" { Access = Internal; @@ -68,7 +68,7 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" exit(ShopifyCompany."Customer No."); end; - local procedure FindByEmail(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + local procedure FindByEmail(var ShopifyCompany: Record "Shpfy Company"; TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean var Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; @@ -89,7 +89,7 @@ codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping" end; end; - local procedure FindByPhoneNo(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean + local procedure FindByPhoneNo(var ShopifyCompany: Record "Shpfy Company"; TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean var Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index 43ade17b2..6d9dbe654 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit Shpfy Comp. By Tax Id (ID 30366) implements Interface Shpfy ICompany Mapping. /// -codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping" +codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 635bb5dff..36dc6f7b1 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -357,21 +357,45 @@ codeunit 30286 "Shpfy Company API" Clear(ShopifyCompany.Note); ShopifyCompany.Modify(); - UpdateShopifyCompanyLocationFields(ShopifyCompany, JCompany); + UpdateShopifyCompanyLocation(ShopifyCompany); end; - local procedure UpdateShopifyCompanyLocationFields(var ShopifyCompany: Record "Shpfy Company"; var JCompany: JsonObject) + local procedure UpdateShopifyCompanyLocation(var ShopifyCompany: Record "Shpfy Company") + var + GraphQLType: Enum "Shpfy GraphQL Type"; + Parameters: Dictionary of [Text, Text]; + JResponse: JsonToken; + Cursor: Text; + IsDefaultCompanyLocation: Boolean; + begin + GraphQLType := "Shpfy GraphQL Type"::GetCompanyLocations; + Parameters.Add('CompanyId', Format(ShopifyCompany.Id)); + IsDefaultCompanyLocation := true; + repeat + JResponse := CommunicationMgt.ExecuteGraphQL(GraphQLType, Parameters); + if JResponse.IsObject() then + if ExtractShopifyCompanyLocations(ShopifyCompany, JResponse.AsObject(), Cursor, IsDefaultCompanyLocation) then begin + if Parameters.ContainsKey('After') then + Parameters.Set('After', Cursor) + else + Parameters.Add('After', Cursor); + GraphQLType := "Shpfy GraphQL Type"::GetNextCompanyLocations; + end else + break; + until not JsonHelper.GetValueAsBoolean(JResponse, 'data.companyLocations.pageInfo.hasNextPage'); + end; + + local procedure ExtractShopifyCompanyLocations(var ShopifyCompany: Record "Shpfy Company"; JResponse: JsonObject; var Cursor: Text; var IsDefaultCompanyLocation: Boolean): Boolean var CompanyLocation: Record "Shpfy Company Location"; JLocations: JsonArray; JLocation: JsonToken; PhoneNo: Text; - IsDefaultCompanyLocation: Boolean; CompanyLocationId: BigInteger; begin - IsDefaultCompanyLocation := true; - if JsonHelper.GetJsonArray(JCompany, JLocations, 'locations.edges') then + if JsonHelper.GetJsonArray(JResponse, JLocations, 'data.companyLocations.edges') then begin foreach JLocation in JLocations do begin + Cursor := JsonHelper.GetValueAsText(JLocation.AsObject(), 'cursor'); CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLocation, 'node.id')); if IsDefaultCompanyLocation then ShopifyCompany."Location Id" := CompanyLocationId; @@ -404,5 +428,7 @@ codeunit 30286 "Shpfy Company API" end; CompanyLocation.Modify(true); end; + exit(true); + end; end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al index 1e485c814..390a5a413 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al @@ -12,7 +12,7 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure DoMapping(CompanyId: BigInteger; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] var - IMapping: Interface "Shpfy ICompany Mapping"; + IMapping: Interface "Shpfy ICustomer/Company Mapping"; begin IMapping := Shop."Company Mapping Type"; exit(IMapping.DoMapping(CompanyId, Shop.Code, TemplateCode, AllowCreate)); @@ -20,7 +20,7 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; var - IMapping: Interface "Shpfy ICompany Mapping"; + IMapping: Interface "Shpfy ICustomer/Company Mapping"; begin IMapping := Shop."Company Mapping Type"; exit(IMapping.FindMapping(ShopifyCompany, TempShopifyCustomer)); diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index 84360d868..cac0b2462 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -3,24 +3,25 @@ namespace Microsoft.Integration.Shopify; /// /// Enum Shpfy Company Mapping (ID 30151) implements Interface Shpfy ICompany Mapping. /// -enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping" +enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" { Caption = 'Shopify Company Mapping'; Extensible = true; + DefaultImplementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; value(0; "By Email/Phone") { Caption = 'By Email/Phone'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; + Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Email/Phone"; } value(2; DefaultCompany) { Caption = 'Always take the default Company'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Default Comp."; + Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Default Comp."; } value(3; "By Tax Id") { Caption = 'By Tax Id'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id"; + Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Tax Id"; } } diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al index 5a4ccefb5..a1a0f16cf 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICompanyMapping.Interface.al @@ -6,6 +6,4 @@ namespace Microsoft.Integration.Shopify; interface "Shpfy ICompany Mapping" { procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] - - procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; } \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al new file mode 100644 index 000000000..491eb2022 --- /dev/null +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al @@ -0,0 +1,11 @@ +namespace Microsoft.Integration.Shopify; + +/// +/// Interface "Shpfy ICustomer/Company Mapping." +/// +interface "Shpfy ICustomer/Company Mapping" +{ + procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] + + procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompLocations.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompLocations.Codeunit.al new file mode 100644 index 000000000..ff618a4fd --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompLocations.Codeunit.al @@ -0,0 +1,24 @@ +namespace Microsoft.Integration.Shopify; + +codeunit 30168 "Shpfy GQL CompLocations" implements "Shpfy IGraphQL" +{ + Access = Internal; + + /// + /// GetGraphQL. + /// + /// Return value of type Text. + internal procedure GetGraphQL(): Text + begin + exit('{"query": "{companyLocations(first:20, query: \"company_id:''{{CompanyId}}''\") {pageInfo { hasNextPage } edges { cursor node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} buyerExperienceConfiguration {paymentTermsTemplate {id}} taxRegistrationId}}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + internal procedure GetExpectedCost(): Integer + begin + exit(24); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al index a4e7cda2b..e6a5806e2 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:20, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} buyerExperienceConfiguration {paymentTermsTemplate {id}} taxRegistrationId}}}}}"}'); + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:1, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); end; /// diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLNextCompLocations.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLNextCompLocations.Codeunit.al new file mode 100644 index 000000000..33da54462 --- /dev/null +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLNextCompLocations.Codeunit.al @@ -0,0 +1,24 @@ +namespace Microsoft.Integration.Shopify; + +codeunit 30215 "Shpfy GQL NextCompLocations" implements "Shpfy IGraphQL" +{ + Access = Internal; + + /// + /// GetGraphQL. + /// + /// Return value of type Text. + internal procedure GetGraphQL(): Text + begin + exit('{"query": "{companyLocations(first:20, after:\"{{After}}\", query: \"company_id:''{{CompanyId}}''\") {pageInfo { hasNextPage } edges { cursor node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} buyerExperienceConfiguration {paymentTermsTemplate {id}} taxRegistrationId}}}}"}'); + end; + + /// + /// GetExpectedCost. + /// + /// Return value of type Integer. + internal procedure GetExpectedCost(): Integer + begin + exit(24); + end; +} diff --git a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al index 8d6fed24c..cbd55db53 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Enums/ShpfyGraphQLType.Enum.al @@ -500,4 +500,14 @@ enum 30111 "Shpfy GraphQL Type" implements "Shpfy IGraphQL" Caption = 'Update Company Location Payment Terms'; Implementation = "Shpfy IGraphQL" = "Shpfy GQL UpdateLocPmtTerms"; } + value(100; GetCompanyLocations) + { + Caption = 'Company Locations'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL CompLocations"; + } + value(101; GetNextCompanyLocations) + { + Caption = 'Next Get Company Locations'; + Implementation = "Shpfy IGraphQL" = "Shpfy GQL NextCompLocations"; + } } From df637865284e6bf3142b700ca4c8e62e6d2ae868 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Fri, 18 Oct 2024 09:59:07 +0300 Subject: [PATCH 14/33] Removed locations from GetCompany graphQL --- .../app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al index e6a5806e2..baf6ed876 100644 --- a/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al +++ b/Apps/W1/Shopify/app/src/GraphQL/Codeunits/ShpfyGQLCompany.Codeunit.al @@ -13,7 +13,7 @@ codeunit 30302 "Shpfy GQL Company" implements "Shpfy IGraphQL" /// Return value of type Text. internal procedure GetGraphQL(): Text begin - exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}} locations(first:1, sortKey: CREATED_AT ) {edges { node { id name billingAddress {address1 address2 city countryCode phone province zip zoneCode} taxRegistrationId}}}}}"}'); + exit('{"query":"{company(id: \"gid://shopify/Company/{{CompanyId}}\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}}}}"}'); end; /// From c7f8822f4bd66c703959b884a4b1ad323ff007eb Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Mon, 21 Oct 2024 18:00:03 +0300 Subject: [PATCH 15/33] Extending the compnay mapping interface --- .../Codeunits/ShpfyCompByDefaultComp.Codeunit.al | 2 +- .../Codeunits/ShpfyCompByEmailPhone.Codeunit.al | 2 +- .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 2 +- .../Codeunits/ShpfyCompanyMapping.Codeunit.al | 10 +++++++--- .../src/Companies/Enums/ShpfyCompanyMapping.Enum.al | 13 ++++++++----- ...ace.al => ShpfyIFindCompanyMapping.Interface.al} | 4 +--- 6 files changed, 19 insertions(+), 14 deletions(-) rename Apps/W1/Shopify/app/src/Companies/Interfaces/{ShpfyICustomerCompanyMapping.Interface.al => ShpfyIFindCompanyMapping.Interface.al} (60%) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al index e520397b0..5262bc698 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByDefaultComp.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit Shpfy Comp. By Default Comp. (ID 30305) implements Interface Shpfy ICompany Mapping. /// -codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" +codeunit 30305 "Shpfy Comp. By Default Comp." implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al index 8bc5b2b23..9a65e4a13 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByEmailPhone.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit ShoShpfypify Comp. By Email/Phone (ID 30304) implements Interface Shpfy ICompany Mapping. /// -codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" +codeunit 30304 "Shpfy Comp. By Email/Phone" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index 6d9dbe654..cd75259a8 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -5,7 +5,7 @@ using Microsoft.Sales.Customer; /// /// Codeunit Shpfy Comp. By Tax Id (ID 30366) implements Interface Shpfy ICompany Mapping. /// -codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" +codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping" { Access = Internal; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al index 390a5a413..c33129139 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al @@ -12,7 +12,7 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure DoMapping(CompanyId: BigInteger; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] var - IMapping: Interface "Shpfy ICustomer/Company Mapping"; + IMapping: Interface "Shpfy ICompany Mapping"; begin IMapping := Shop."Company Mapping Type"; exit(IMapping.DoMapping(CompanyId, Shop.Code, TemplateCode, AllowCreate)); @@ -20,10 +20,14 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; var - IMapping: Interface "Shpfy ICustomer/Company Mapping"; + ShpfyCompByEmailPhone: Codeunit "Shpfy Comp. By Email/Phone"; + IMapping: Interface "Shpfy ICompany Mapping"; begin IMapping := Shop."Company Mapping Type"; - exit(IMapping.FindMapping(ShopifyCompany, TempShopifyCustomer)); + if IMapping is "Shpfy IFind Company Mapping" then + exit((IMapping as "Shpfy IFind Company Mapping").FindMapping(ShopifyCompany, TempShopifyCustomer)) + else + ShpfyCompByEmailPhone.FindMapping(ShopifyCompany, TempShopifyCustomer); end; internal procedure SetShop(Code: Code[20]) diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index cac0b2462..21a312737 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -3,25 +3,28 @@ namespace Microsoft.Integration.Shopify; /// /// Enum Shpfy Company Mapping (ID 30151) implements Interface Shpfy ICompany Mapping. /// -enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping", "Shpfy ICustomer/Company Mapping" +enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping" { Caption = 'Shopify Company Mapping'; Extensible = true; - DefaultImplementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; + DefaultImplementation = "Shpfy IFind Company Mapping" = "Shpfy Comp. By Email/Phone"; value(0; "By Email/Phone") { Caption = 'By Email/Phone'; - Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Email/Phone"; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone", + "Shpfy IFind Company Mapping" = "Shpfy Comp. By Email/Phone"; } value(2; DefaultCompany) { Caption = 'Always take the default Company'; - Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Default Comp."; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Default Comp.", + "Shpfy IFind Company Mapping" = "Shpfy Comp. By Default Comp."; } value(3; "By Tax Id") { Caption = 'By Tax Id'; - Implementation = "Shpfy ICustomer/Company Mapping" = "Shpfy Comp. By Tax Id"; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id", + "Shpfy IFind Company Mapping" = "Shpfy Comp. By Tax Id"; } } diff --git a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyIFindCompanyMapping.Interface.al similarity index 60% rename from Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al rename to Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyIFindCompanyMapping.Interface.al index 491eb2022..8a433d051 100644 --- a/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyICustomerCompanyMapping.Interface.al +++ b/Apps/W1/Shopify/app/src/Companies/Interfaces/ShpfyIFindCompanyMapping.Interface.al @@ -3,9 +3,7 @@ namespace Microsoft.Integration.Shopify; /// /// Interface "Shpfy ICustomer/Company Mapping." /// -interface "Shpfy ICustomer/Company Mapping" +interface "Shpfy IFind Company Mapping" extends "Shpfy ICompany Mapping" { - procedure DoMapping(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] - procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean } \ No newline at end of file From 497976be3331183741cca3045cc0f3f2958ca8d9 Mon Sep 17 00:00:00 2001 From: justaszaksauskas Date: Mon, 21 Oct 2024 18:09:17 +0300 Subject: [PATCH 16/33] removed implemenetions from enum for new interface --- .../src/Companies/Enums/ShpfyCompanyMapping.Enum.al | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al index 21a312737..84360d868 100644 --- a/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al +++ b/Apps/W1/Shopify/app/src/Companies/Enums/ShpfyCompanyMapping.Enum.al @@ -3,28 +3,24 @@ namespace Microsoft.Integration.Shopify; /// /// Enum Shpfy Company Mapping (ID 30151) implements Interface Shpfy ICompany Mapping. /// -enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping", "Shpfy IFind Company Mapping" +enum 30151 "Shpfy Company Mapping" implements "Shpfy ICompany Mapping" { Caption = 'Shopify Company Mapping'; Extensible = true; - DefaultImplementation = "Shpfy IFind Company Mapping" = "Shpfy Comp. By Email/Phone"; value(0; "By Email/Phone") { Caption = 'By Email/Phone'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone", - "Shpfy IFind Company Mapping" = "Shpfy Comp. By Email/Phone"; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Email/Phone"; } value(2; DefaultCompany) { Caption = 'Always take the default Company'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Default Comp.", - "Shpfy IFind Company Mapping" = "Shpfy Comp. By Default Comp."; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Default Comp."; } value(3; "By Tax Id") { Caption = 'By Tax Id'; - Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id", - "Shpfy IFind Company Mapping" = "Shpfy Comp. By Tax Id"; + Implementation = "Shpfy ICompany Mapping" = "Shpfy Comp. By Tax Id"; } } From 64b60e64d7f50d695bb8909fc6c127534f2433f4 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 16:31:02 +0200 Subject: [PATCH 17/33] test commit --- .../W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al | 1 + 1 file changed, 1 insertion(+) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index 5f6a66858..ec021de98 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -97,4 +97,5 @@ codeunit 139638 "Shpfy Company Initialize" JResult.ReadFrom(StrSubstNo(ResultLbl, Name, CompanyContactId, CustomerId, CompanyLocationId)); exit(JResult); end; + } From 52426d15538c26abd3d6ce654411dc330c49fdd8 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 22 Oct 2024 16:37:28 +0200 Subject: [PATCH 18/33] remove empty line --- .../W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al | 1 - 1 file changed, 1 deletion(-) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index ec021de98..5f6a66858 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -97,5 +97,4 @@ codeunit 139638 "Shpfy Company Initialize" JResult.ReadFrom(StrSubstNo(ResultLbl, Name, CompanyContactId, CustomerId, CompanyLocationId)); exit(JResult); end; - } From e217b4d0275ae08230efb380c31d0541915f6c9f Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 28 Oct 2024 13:40:38 +0100 Subject: [PATCH 19/33] fix existing test, add test for catalog --- .../Codeunits/ShpfyCompanyAPI.Codeunit.al | 4 +- .../Codeunits/ShpfyCompanyImport.Codeunit.al | 2 + .../ShpfyCatalogAPISuscribers.Codeunit.al | 92 +++++++++++++++++++ .../Catalogs/ShpfyCatalogAPITest.Codeunit.al | 38 ++++++++ .../Companies/ShpfyCompanyAPITest.Codeunit.al | 3 +- 5 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 36dc6f7b1..d0b36d6fe 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -356,11 +356,9 @@ codeunit 30286 "Shpfy Company API" end else Clear(ShopifyCompany.Note); ShopifyCompany.Modify(); - - UpdateShopifyCompanyLocation(ShopifyCompany); end; - local procedure UpdateShopifyCompanyLocation(var ShopifyCompany: Record "Shpfy Company") + internal procedure UpdateShopifyCompanyLocation(var ShopifyCompany: Record "Shpfy Company") var GraphQLType: Enum "Shpfy GraphQL Type"; Parameters: Dictionary of [Text, Text]; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al index f95e2fe19..5c7871aab 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyImport.Codeunit.al @@ -20,6 +20,8 @@ codeunit 30301 "Shpfy Company Import" exit; end; + CompanyApi.UpdateShopifyCompanyLocation(ShopifyCompany); + Commit(); if CompanyMapping.FindMapping(ShopifyCompany, TempShopifyCustomer) then begin if Shop."Shopify Can Update Companies" then begin diff --git a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al new file mode 100644 index 000000000..38ea6fb04 --- /dev/null +++ b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al @@ -0,0 +1,92 @@ +codeunit 139625 "Shpfy Catalog API Suscribers" +{ + EventSubscriberInstance = Manual; + + var + ShopifyCustomerId: BigInteger; + GQLQueryTxt: Text; + + [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; + GetCustomersGQLMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; + ModifyCustomerGQLStartTok: Label '{"query":"mutation {customerUpdate(input: {id: \"gid://shopify/Customer/', Locked = true; + GetCustomerMetafieldsGQLStartTok: Label '{"query":"{customer(id: \"gid://shopify/Customer/', Locked = true; + GetCustomerMetafieldsGQLEndTok: Label '\") { metafields(first: 50) {edges {node {legacyResourceId updatedAt}}}}}"}', Locked = true; + CreateMetafieldsGQLStartTok: Label '{"query": "mutation { metafieldsSet(metafields: ', 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 + case true of + GraphQlQuery.Contains(GetCustomersGQLMsg): + HttpResponseMessage := GetCustomersResult(); + GraphQlQuery.StartsWith(ModifyCustomerGQLStartTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(GetCustomerMetafieldsGQLStartTok) and GraphQlQuery.EndsWith(GetCustomerMetafieldsGQLEndTok): + HttpResponseMessage := GetEmptyResponse(); + GraphQlQuery.StartsWith(CreateMetafieldsGQLStartTok): + begin + HttpResponseMessage := GetEmptyResponse(); + GQLQueryTxt := GraphQlQuery; + end; + end; + end; + end; + end; + + 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 GetEmptyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{}'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure SetShopifyCustomerId(Id: BigInteger) + begin + ShopifyCustomerId := Id; + end; + + internal procedure GetGQLQuery(): Text + begin + exit(GQLQueryTxt); + end; + +} diff --git a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al index f50c1017d..f0cb9f08e 100644 --- a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al @@ -61,4 +61,42 @@ codeunit 139645 "Shpfy Catalog API Test" LibraryAssert.IsTrue(Result, 'ExtractShopifyCatalogPrices'); LibraryAssert.RecordIsNotEmpty(TempCatalogPrice); end; + + [Test] + procedure UnitTestCreateCatalog() + var + Shop: Record "Shpfy Shop"; + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CatalogAPI: Codeunit "Shpfy Catalog API"; + ShopifyInitializeTest: Codeunit "Shpfy Initialize Test"; + Catalog: Record "Shpfy Catalog"; + LibrarySales: Codeunit "Library - Sales"; + begin + // [SCENARIO] Create a catalog for a company. + + // [GIVEN] Shop + Shop := ShopifyInitializeTest.CreateShop(); + // [GIVEN] Customer + LibrarySales.CreateCustomer(Customer); + // [GIVEN] A company record. + CreateCompany(ShopifyCompany, Customer.SystemId); + + // [WHEN] Invoke CatalogAPI.CreateCatalog + CatalogAPI.CreateCatalog(ShopifyCompany, Customer); + + // [THEN] A catalog is created. + Catalog.SetRange("Company SystemId", ShopifyCompany.SystemId); + LibraryAssert.RecordIsNotEmpty(Catalog); + LibraryAssert.AreEqual(Customer."No.", Catalog."Customer No.", 'Customer No. is not transfered to catalog'); + end; + + local procedure CreateCompany(var ShopifyCompany: Record "Shpfy Company"; CustomerSystemId: Guid) + var + ShopifyCompanyInitialize: Codeunit "Shpfy Company Initialize"; + begin + ShopifyCompanyInitialize.CreateShopifyCompany(ShopifyCompany); + ShopifyCompany."Customer SystemId" := CustomerSystemId; + ShopifyCompany.Modify(false); + end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index b5bb716fe..05cb8315c 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -13,6 +13,7 @@ codeunit 139637 "Shpfy Company API Test" var ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; + ShopifyCustomer: Record "Shpfy Customer"; CompanyAPI: Codeunit "Shpfy Company API"; GraphQL: Text; begin @@ -25,7 +26,7 @@ codeunit 139637 "Shpfy Company API Test" // [GIVEN] ShpfyCompanyLocation // [WHEN] Invoke CompanyAPI.CreateCompanyGraphQLQuery - GraphQL := CompanyAPI.CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation); + GraphQL := CompanyAPI.CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); // [THEN] CompanyInitialize.CreateCompanyGraphQLResult() = GraphQL. LibraryAssert.AreEqual(CompanyInitialize.CreateCompanyGraphQLResult(), GraphQL, 'CreateCompanyGraphQuery'); From ca3dd8cd21336cd9277eca8f3635940bb9d2720c Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Mon, 28 Oct 2024 14:36:45 +0100 Subject: [PATCH 20/33] Task 1 test --- .../ShpfyCatalogAPISuscribers.Codeunit.al | 49 ++++++------------- .../Catalogs/ShpfyCatalogAPITest.Codeunit.al | 9 ++-- .../Companies/ShpfyCompanyAPITest.Codeunit.al | 1 - 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al index 38ea6fb04..ff5aad686 100644 --- a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al +++ b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al @@ -1,9 +1,9 @@ -codeunit 139625 "Shpfy Catalog API Suscribers" +codeunit 139625 "Shpfy Catalog API Subscribers" { EventSubscriberInstance = Manual; var - ShopifyCustomerId: BigInteger; + ShopifyCatalogId: BigInteger; GQLQueryTxt: Text; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] @@ -18,22 +18,13 @@ codeunit 139625 "Shpfy Catalog API Suscribers" 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; - GetCustomersGQLMsg: Label '{"query":"{customers(first:100){pageInfo{endCursor hasNextPage} nodes{ legacyResourceId }}}"}', Locked = true; - ModifyCustomerGQLStartTok: Label '{"query":"mutation {customerUpdate(input: {id: \"gid://shopify/Customer/', Locked = true; - GetCustomerMetafieldsGQLStartTok: Label '{"query":"{customer(id: \"gid://shopify/Customer/', Locked = true; - GetCustomerMetafieldsGQLEndTok: Label '\") { metafields(first: 50) {edges {node {legacyResourceId updatedAt}}}}}"}', Locked = true; - CreateMetafieldsGQLStartTok: Label '{"query": "mutation { metafieldsSet(metafields: ', Locked = true; + CreateCatalogGQLStartTok: Label '{"query": "mutation { catalogCreate(input: {title: ', Locked = true; + CreatePublicationGQLStartTok: Label '{"query": "mutation { publicationCreate(input: {autoPublish: true, catalogId:', Locked = true; + CreatePriceListGQLStartTok: Label '{"query": "mutation { priceListCreate(input: {name: ', Locked = true; GraphQLCmdTxt: Label '/graphql.json', Locked = true; begin case HttpRequestMessage.Method of @@ -43,28 +34,24 @@ codeunit 139625 "Shpfy Catalog API Suscribers" if Uri.EndsWith(GraphQLCmdTxt) then if HttpRequestMessage.Content.ReadAs(GraphQlQuery) then case true of - GraphQlQuery.Contains(GetCustomersGQLMsg): - HttpResponseMessage := GetCustomersResult(); - GraphQlQuery.StartsWith(ModifyCustomerGQLStartTok): + GraphQlQuery.StartsWith(CreateCatalogGQLStartTok): + HttpResponseMessage := GetCatalogResult(); + GraphQlQuery.StartsWith(CreatePublicationGQLStartTok): HttpResponseMessage := GetEmptyResponse(); - GraphQlQuery.StartsWith(GetCustomerMetafieldsGQLStartTok) and GraphQlQuery.EndsWith(GetCustomerMetafieldsGQLEndTok): + GraphQlQuery.StartsWith(CreatePriceListGQLStartTok): HttpResponseMessage := GetEmptyResponse(); - GraphQlQuery.StartsWith(CreateMetafieldsGQLStartTok): - begin - HttpResponseMessage := GetEmptyResponse(); - GQLQueryTxt := GraphQlQuery; - end; end; end; end; end; - local procedure GetCustomersResult(): HttpResponseMessage + local procedure GetCatalogResult(): HttpResponseMessage var + Any: Codeunit Any; 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 } } } }'; + Body := StrSubstNo('{"data": {"catalogCreate": {"catalog": {"id": %1}}}}', Any.IntegerInRange(100000, 999999)); HttpResponseMessage.Content.WriteFrom(Body); exit(HttpResponseMessage); end; @@ -79,14 +66,8 @@ codeunit 139625 "Shpfy Catalog API Suscribers" exit(HttpResponseMessage); end; - internal procedure SetShopifyCustomerId(Id: BigInteger) + internal procedure SetShopifyCatalogId(Id: BigInteger) begin - ShopifyCustomerId := Id; + ShopifyCatalogId := Id; end; - - internal procedure GetGQLQuery(): Text - begin - exit(GQLQueryTxt); - end; - -} +} \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al index f0cb9f08e..bee1cb27a 100644 --- a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPITest.Codeunit.al @@ -68,9 +68,10 @@ codeunit 139645 "Shpfy Catalog API Test" Shop: Record "Shpfy Shop"; Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; + Catalog: Record "Shpfy Catalog"; CatalogAPI: Codeunit "Shpfy Catalog API"; ShopifyInitializeTest: Codeunit "Shpfy Initialize Test"; - Catalog: Record "Shpfy Catalog"; + CatalogAPISubscribers: Codeunit "Shpfy Catalog API Subscribers"; LibrarySales: Codeunit "Library - Sales"; begin // [SCENARIO] Create a catalog for a company. @@ -83,12 +84,14 @@ codeunit 139645 "Shpfy Catalog API Test" CreateCompany(ShopifyCompany, Customer.SystemId); // [WHEN] Invoke CatalogAPI.CreateCatalog + BindSubscription(CatalogAPISubscribers); CatalogAPI.CreateCatalog(ShopifyCompany, Customer); + UnbindSubscription(CatalogAPISubscribers); // [THEN] A catalog is created. Catalog.SetRange("Company SystemId", ShopifyCompany.SystemId); - LibraryAssert.RecordIsNotEmpty(Catalog); - LibraryAssert.AreEqual(Customer."No.", Catalog."Customer No.", 'Customer No. is not transfered to catalog'); + Catalog.FindFirst(); + LibraryAssert.AreEqual(Customer."No.", Catalog."Customer No.", 'Customer No. is not transferred to catalog'); end; local procedure CreateCompany(var ShopifyCompany: Record "Shpfy Company"; CustomerSystemId: Guid) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 05cb8315c..740bd80bb 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -141,6 +141,5 @@ codeunit 139637 "Shpfy Company API Test" LibraryAssert.AreEqual(ShopifyCompany.Name, Name, 'Name'); LibraryAssert.AreEqual(ShopifyCompany."Main Contact Id", CompanyContactId, 'Company Contact Id'); LibraryAssert.AreEqual(ShopifyCompany."Main Contact Customer Id", CustomerId, 'Customer Id'); - LibraryAssert.AreEqual(ShopifyCompany."Location Id", CompanyLocationId, 'Company Location Id'); end; } From b779120a8a3d65494962ee4c505c4403bf779ea6 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 29 Oct 2024 13:24:30 +0100 Subject: [PATCH 21/33] add find mapping tests --- .../ShpfyCatalogAPISuscribers.Codeunit.al | 9 - .../ShpfyCompanyMappingTest.Codeunit.al | 481 ++++++++++++++++++ .../ShpfyTaxIdMappingTest.Codeunit.al | 150 ++++++ 3 files changed, 631 insertions(+), 9 deletions(-) create mode 100644 Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al create mode 100644 Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al diff --git a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al index ff5aad686..e677d4d66 100644 --- a/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al +++ b/Apps/W1/Shopify/test/Catalogs/ShpfyCatalogAPISuscribers.Codeunit.al @@ -2,10 +2,6 @@ codeunit 139625 "Shpfy Catalog API Subscribers" { EventSubscriberInstance = Manual; - var - ShopifyCatalogId: BigInteger; - GQLQueryTxt: Text; - [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] local procedure OnClientSend(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) begin @@ -65,9 +61,4 @@ codeunit 139625 "Shpfy Catalog API Subscribers" HttpResponseMessage.Content.WriteFrom(Body); exit(HttpResponseMessage); end; - - internal procedure SetShopifyCatalogId(Id: BigInteger) - begin - ShopifyCatalogId := Id; - end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al new file mode 100644 index 000000000..3d7c45c1b --- /dev/null +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al @@ -0,0 +1,481 @@ +codeunit 139627 "Shpfy Company Mapping Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + Shop: Record "Shpfy Shop"; + LibraryAssert: Codeunit "Library Assert"; + Any: Codeunit Any; + ShopifyInitializeTest: Codeunit "Shpfy Initialize Test"; + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; + + [Test] + procedure UnitTestFindMappingByDefaultCompanyMapping() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + FindMappingResult: Boolean; + begin + // [SCENARIO] FindMapping using DefaultCompanyMapping + Initialize(); + + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shop with Company Mapping Type as Default Company Mapping + SetDefaultCompanyMapping(Customer); + // [GIVEN] Shopify Company with customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, Customer.SystemId); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + end; + + [Test] + procedure UnitTestDoMappingByDefaultCompanyMappingWithRandomGuid() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + ShopifyCustomer: Record "Shpfy Customer"; + FindMappingResult: Boolean; + begin + // [SCENARIO] DoMapping using DefaultCompanyMapping with random guid for Shopify Company Customer System Id + Initialize(); + + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shop with Company Mapping Type as Default Company Mapping + SetDefaultCompanyMapping(Customer); + // [GIVEN] Shopify Company with random guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, CreateGuid()); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, 0); + + // [WHEN] FindMapping is invoked + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] FindMapping result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Shopify Customer is created + LibraryAssert.IsTrue(ShopifyCustomer.Get(TempShopifyCustomer.Id), 'Shopify Customer was not created.'); + // [THEN] Shopify Customer has the same customer system id as the Customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCustomer."Customer SystemId", 'Customer system Id not transferred to shopify customer.'); + // [THEN] Shopify Company has the same customer system id as the Customer record + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + // [THEN] Shopify Company main contact customer id is the same as the Shopify Customer id + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Main Contact Customer Id different than customer id.'); + end; + + [Test] + procedure UnitTestDoMappingByDefaultCompanyMappingWithEmptyGuid() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + ShopifyCustomer: Record "Shpfy Customer"; + FindMappingResult: Boolean; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using DefaultCompanyMapping with empty guid for Shopify Company Customer System Id + Initialize(); + + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shop with Company Mapping Type as Default Company Mapping + SetDefaultCompanyMapping(Customer); + // [GIVEN] Shopify Company with empty guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, 0); + + // [WHEN] FindMapping is invoked + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] FindMapping result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Shopify Customer is created + LibraryAssert.IsTrue(ShopifyCustomer.Get(TempShopifyCustomer.Id), 'Shopify Customer was not created.'); + // [THEN] Shopify Customer has the same customer system id as the Customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCustomer."Customer SystemId", 'Customer system Id not transferred to shopify customer.'); + // [THEN] Shopify Company has the same customer system id as the Customer record + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + // [THEN] Shopify Company main contact customer id is the same as the Shopify Customer id + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Main Contact Customer Id different than customer id.'); + end; + + [Test] + procedure UnitTestDoMappingByDefaultCompanyMappingWithExistingShopifyCustomer() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + ShopifyCustomer: Record "Shpfy Customer"; + ShopifyCustomerId: BigInteger; + FindMappingResult: Boolean; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using DefaultCompanyMapping with existing Shopify Customer + Initialize(); + + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shop with Company Mapping Type as Default Company Mapping + SetDefaultCompanyMapping(Customer); + // [GIVEN] Shopify Company with customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + // [GIVEN] Shopify Customer + ShopifyCustomerId := Any.IntegerInRange(10000, 99999); + CreateShopifyCustomer(ShopifyCustomer, ShopifyCustomerId); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, ShopifyCustomerId); + + // [WHEN] FindMapping is invoked + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] FindMapping result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Main Contact Customer Id is the same as the Shopify Customer id + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(ShopifyCustomerId, ShopifyCompany."Main Contact Customer Id", 'Main contact customer Id different than customer id.'); + // [THEN] Shopify company customer system id is the same as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + end; + + [Test] + procedure UnitTestDoMappingByDefaultCompanyMapping() + var + Customer: Record Customer; + ShopifyCompanyId: BigInteger; + DoMappingResult: Code[20]; + begin + // [SCENARIO] DoMapping using DefaultCompanyMapping + Initialize(); + + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shop with Company Mapping Type as Default Company Mapping + SetDefaultCompanyMapping(Customer); + // [GIVEN] Shopify Company Id + ShopifyCompanyId := Any.IntegerInRange(10000, 99999); + + // [WHEN] DoMapping is called + InvokeDoMapping(ShopifyCompanyId, DoMappingResult); + + // [THEN] The result is the same as the Customer No. field of the Customer record + LibraryAssert.AreEqual(Customer."No.", DoMappingResult, 'Mapping result is different than default company no.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxId() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + FindMappingResult: Boolean; + begin + // [SCENARIO] DoMapping using By Tax Id + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shopify Company with customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, Customer.SystemId); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxIdWithRegistrationNo() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + ShopifyCustomer: Record "Shpfy Customer"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + FindMappingResult: Boolean; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using By Tax Id with Registration No. + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Shop with Tax Registration Id Mapping as Registration No. + SetCompTaxIdMapping(Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."); + // [GIVEN] Customer with Registration No. + CreateCustomerWithRegistrationNo(Customer); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, 0); + // [GIVEN] Shopify Company with empty guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + // [GIVEN] Company Location with Tax Registration Id + CreateCompanyLocationWithTaxId(ShopifyCompany, Customer."Registration Number"); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Shopify customer is created + LibraryAssert.IsTrue(ShopifyCustomer.Get(TempShopifyCustomer.Id), 'Shopify Customer was not created.'); + // [THEN] Shopify customer has the same customer system id as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCustomer."Customer SystemId", 'Customer system Id not transferred to shopify customer.'); + // [THEN] Shopify company has the same customer system id as the customer record + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Customer system Id not transferred to shopify company.'); + // [THEN] Shopify company customer system id is the same as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxIdWithRegistrationNoAndRandomCustomerSysId() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + ShopifyCustomer: Record "Shpfy Customer"; + FindMappingResult: Boolean; + begin + // [SCENARIO] DoMapping using By Tax Id with Registration No. and random customer system id + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Shop with Tax Registration Id Mapping as Registration No. + SetCompTaxIdMapping(Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."); + // [GIVEN] Customer with Registration No. + CreateCustomerWithRegistrationNo(Customer); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, 0); + // [GIVEN] Shopify Company with random guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, CreateGuid()); + // [GIVEN] Company Location with Tax Registration Id + CreateCompanyLocationWithTaxId(ShopifyCompany, Customer."Registration Number"); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Shopify customer is created + LibraryAssert.IsTrue(ShopifyCustomer.Get(TempShopifyCustomer.Id), 'Shopify Customer was not created.'); + // [THEN] Shopify customer has the same customer system id as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCustomer."Customer SystemId", 'Customer system Id not transferred to shopify customer.'); + // [THEN] Shopify company has the same customer system id as the customer record + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Customer system Id not transferred to shopify company.'); + // [THEN] Shopify company customer system id is the same as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxIdWithRegistrationNoAndExistingShopifyCustomer() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + ShopifyCustomer: Record "Shpfy Customer"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + FindMappingResult: Boolean; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using By Tax Id with Registration No. and existing Shopify Customer + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Shop with Tax Registration Id Mapping as Registration No. + SetCompTaxIdMapping(Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."); + // [GIVEN] Customer with Registration No. + CreateCustomerWithRegistrationNo(Customer); + // [GIVEN] Shopify Customer + CreateShopifyCustomer(ShopifyCustomer, 0); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, ShopifyCustomer.Id); + // [GIVEN] Shopify Company with empty guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + // [GIVEN] Company Location with Tax Registration Id + CreateCompanyLocationWithTaxId(ShopifyCompany, Customer."Registration Number"); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Main Contact Customer Id is the same as the Shopify Customer id + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Main contact customer Id different than customer id.'); + // [THEN] Shopify company customer system id is the same as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxIdWithVATRegistrationNo() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + ShopifyCustomer: Record "Shpfy Customer"; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + FindMappingResult: Boolean; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using By Tax Id with VAT Registration No. + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Shop with Tax Registration Id Mapping as VAT Registration No. + SetCompTaxIdMapping(Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."); + // [GIVEN] Customer with VAT Registration No. + CreateCustomerWithRegistrationNo(Customer); + // [GIVEN] Shopify Company + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + // [GIVEN] Company Location with Tax Registration Id + CreateCompanyLocationWithTaxId(ShopifyCompany, Customer."VAT Registration No."); + // [GIVEN] Shopify Customer + CreateShopifyCustomer(ShopifyCustomer, 0); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer, ShopifyCustomer.Id); + + // [WHEN] FindMapping is called + InvokeFindMapping(ShopifyCompany, TempShopifyCustomer, FindMappingResult); + + // [THEN] The result is true + LibraryAssert.IsTrue(FindMappingResult, 'Mapping was not found.'); + // [THEN] Shopify company main contact customer id is the same as the Shopify Customer id + ShopifyCompany.Get(ShopifyCompany.Id); + LibraryAssert.AreEqual(ShopifyCustomer.Id, ShopifyCompany."Main Contact Customer Id", 'Main contact customer Id different than customer id.'); + // [THEN] Shopify company customer system id is the same as the customer record + LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); + end; + + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + + if IsInitialized then + exit; + + Shop := ShopifyInitializeTest.CreateShop(); + + IsInitialized := true; + Commit(); + end; + + local procedure CreateShopifyCompanyWithCustomerSysId(var ShopifyCompany: Record "Shpfy Company"; CustomerSystemId: Guid) + begin + ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); + ShopifyCompany."Shop Code" := Shop."Code"; + ShopifyCompany."Customer SystemId" := CustomerSystemId; + ShopifyCompany.Insert(false); + end; + + local procedure CreateCustomer(var Customer: Record Customer) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer.Insert(false); + end; + + local procedure SetDefaultCompanyMapping(var Customer: Record Customer) + begin + Shop."Company Mapping Type" := Enum::"Shpfy Company Mapping"::DefaultCompany; + Shop."Default Company No." := Customer."No."; + Shop.Modify(false); + end; + + local procedure CreateTempShopifyCustomer(var TempShopifyCustomer: Record "Shpfy Customer" temporary; Id: BigInteger) + begin + TempShopifyCustomer.Init(); + if Id <> 0 then + TempShopifyCustomer.Id := Id + else + TempShopifyCustomer.Id := Any.IntegerInRange(10000, 99999); + TempShopifyCustomer.Insert(false); + end; + + local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; Id: BigInteger) + begin + ShopifyCustomer.Init(); + if Id <> 0 then + ShopifyCustomer.Id := Id + else + ShopifyCustomer.Id := Any.IntegerInRange(10000, 99999); + ShopifyCustomer.Insert(false); + end; + + local procedure InvokeFindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary; var FindMappingResult: Boolean) + var + CompanyMapping: Codeunit "Shpfy Company Mapping"; + begin + CompanyMapping.SetShop(ShopifyCompany."Shop Code"); + FindMappingResult := CompanyMapping.FindMapping(ShopifyCompany, TempShopifyCustomer); + end; + + local procedure InvokeDoMapping(CompanyId: BigInteger; var DoMappingResult: Code[20]) + var + CompanyMapping: Codeunit "Shpfy Company Mapping"; + begin + CompanyMapping.SetShop(Shop); + DoMappingResult := CompanyMapping.DoMapping(CompanyId, '', false) + end; + + local procedure SetMappingByTaxId() + begin + Shop."Company Mapping Type" := Enum::"Shpfy Company Mapping"::"By Tax Id"; + Shop.Modify(false); + end; + + local procedure CreateCustomerWithRegistrationNo(var Customer: Record Customer) + begin + CreateCustomer(Customer); + Customer."Registration Number" := Any.AlphanumericText(20); + Customer.Modify(false); + end; + + local procedure CreateCompanyLocationWithTaxId(var ShopifyCompany: Record "Shpfy Company"; TaxId: Text[150]) + var + CompanyLocation: Record "Shpfy Company Location"; + begin + CompanyLocation.Init(); + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; + CompanyLocation."Tax Registration Id" := TaxId; + CompanyLocation.Insert(false); + + ShopifyCompany."Location Id" := CompanyLocation.Id; + ShopifyCompany.Modify(false); + end; + + local procedure CreateCustomerWithVATRegistrationNo(var Customer: Record Customer) + begin + CreateCustomer(Customer); + Customer."VAT Registration No." := Any.AlphanumericText(20); + Customer.Modify(false); + end; + + local procedure SetCompTaxIdMapping(ShpfyCompTaxIdMapping: Enum Microsoft.Integration.Shopify."Shpfy Comp. Tax Id Mapping") + begin + Shop."Shpfy Comp. Tax Id Mapping" := ShpfyCompTaxIdMapping; + Shop.Modify(false); + end; + +} diff --git a/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al new file mode 100644 index 000000000..5ee859353 --- /dev/null +++ b/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al @@ -0,0 +1,150 @@ +codeunit 139628 "Shpfy Tax Id Mapping Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + Any: Codeunit Any; + LibraryAssert: Codeunit "Library Assert"; + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; + + [Test] + procedure UnitTestGetTaxRegistrationIdForRegistrationNo() + var + Customer: Record Customer; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + RegistrationNo: Text[50]; + RegistrationNoResult: Text[50]; + begin + // [SCENARIO] GetTaxRegistrationId for Tax Registration No. implementation of mapping + Initialize(); + + // [GIVEN] Customer record with Tax Registration No. + RegistrationNo := Any.AlphanumericText(50); + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Registration Number" := RegistrationNo; + Customer.Insert(false); + // [GIVEN] TaxRegistrationIdMapping interface is "Registration No." + TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."; + + // [WHEN] GetTaxRegistrationId is called + RegistrationNoResult := TaxRegistrationIdMapping.GetTaxRegistrationId(Customer); + + // [THEN] The result is the same as the Registration No. field of the Customer record + LibraryAssert.AreEqual(RegistrationNo, RegistrationNoResult, 'Registration No.'); + end; + + [Test] + procedure UnitTestGetTaxRegistrationIdForVATRegistrationNo() + var + Customer: Record Customer; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + VATRegistrationNo: Text[20]; + VATRegistrationNoResult: Text[50]; + begin + // [SCENARIO] GetTaxRegistrationId for VAT Registration No. implementation of mapping + Initialize(); + + // [GIVEN] Customer record with VAT Registration No. + VATRegistrationNo := Any.AlphanumericText(20); + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."VAT Registration No." := VATRegistrationNo; + Customer.Insert(false); + // [GIVEN] TaxRegistrationIdMapping interface is "VAT Registration No." + TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."; + + // [WHEN] GetTaxRegistrationId is called + VATRegistrationNoResult := TaxRegistrationIdMapping.GetTaxRegistrationId(Customer); + + // [THEN] The result is the same as the VAT Registration No. field of the Customer record + LibraryAssert.AreEqual(VATRegistrationNo, VATRegistrationNoResult, 'VAT Registration No.'); + end; + + [Test] + procedure UnitTestSetMappingFiltersForCustomersWithRegistrationNo() + var + Customer: Record Customer; + CompanyLocation: Record "Shpfy Company Location"; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + RegistrationNo: Text[50]; + begin + // [SCENARIO] SetMappingFiltersForCustomers for Tax Registration Id implementation of mapping + Initialize(); + + // [GIVEN] Registration No. + RegistrationNo := Any.AlphanumericText(50); + // [GIVEN] Customer record with Registration No. + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Registration Number" := RegistrationNo; + Customer.Insert(false); + // [GIVEN] CompanyLocation record with Tax Registration Id + CompanyLocation.Init(); + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Tax Registration Id" := RegistrationNo; + CompanyLocation.Insert(false); + // [GIVEN] TaxRegistrationIdMapping interface is "Registration No." + TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."; + + // [WHEN] SetMappingFiltersForCustomers is called + TaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); + + // [THEN] The range of the Customer record is set to the Tax Registration Id of the CompanyLocation record + LibraryAssert.AreEqual(RegistrationNo, Customer.GetFilter("Registration Number"), 'Registration No. filter is not set correctly.'); + end; + + [Test] + procedure UnitTestSetMappingFiltersForCustomersWithVATRegistrationNo() + var + Customer: Record Customer; + CompanyLocation: Record "Shpfy Company Location"; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + VATRegistrationNo: Text[20]; + begin + // [SCENARIO] SetMappingFiltersForCustomers for VAT Registration No. implementation of mapping + Initialize(); + + // [GIVEN] VAT Registration No. + VATRegistrationNo := Any.AlphanumericText(20); + // [GIVEN] Customer record with VAT Registration No. + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."VAT Registration No." := VATRegistrationNo; + Customer.Insert(false); + // [GIVEN] CompanyLocation record with Tax Registration Id + CompanyLocation.Init(); + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Tax Registration Id" := VATRegistrationNo; + CompanyLocation.Insert(false); + // [GIVEN] TaxRegistrationIdMapping interface is "VAT Registration No." + TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."; + + // [WHEN] SetMappingFiltersForCustomers is called + TaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); + + // [THEN] The range of the Customer record is set to the Tax Registration Id of the CompanyLocation record + LibraryAssert.AreEqual(VATRegistrationNo, Customer.GetFilter("VAT Registration No."), 'VAT Registration No. filter is not set correctly.'); + end; + + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + + if IsInitialized then + exit; + + IsInitialized := true; + + Commit(); + end; + + +} From 2ba709b1e7b33f159b14b605bbaf0f7e7dcf059b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 29 Oct 2024 18:04:06 +0100 Subject: [PATCH 22/33] add tests --- .../ShpfyCompanyExportTest.Codeunit.al | 85 ++++++++++++++++++- .../ShpfyCompanyMappingSubs.Codeunit.al | 56 ++++++++++++ .../ShpfyCompanyMappingTest.Codeunit.al | 74 +++++++++++++--- 3 files changed, 202 insertions(+), 13 deletions(-) create mode 100644 Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingSubs.Codeunit.al diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al index af85097dc..a9bfe312d 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al @@ -4,8 +4,17 @@ codeunit 139636 "Shpfy Company Export Test" TestPermissions = Disabled; var + Shop: Record "Shpfy Shop"; + InitializeTest: Codeunit "Shpfy Initialize Test"; + Any: Codeunit Any; LibraryAssert: Codeunit "Library Assert"; CompanyExport: Codeunit "Shpfy Company Export"; + IsInitialized: Boolean; + + trigger OnRun() + begin + IsInitialized := false; + end; [Test] procedure UnitTestFillInShopifyCustomerData() @@ -13,9 +22,8 @@ codeunit 139636 "Shpfy Company Export Test" Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; - Shop: Record "Shpfy Shop"; - InitializeTest: Codeunit "Shpfy Initialize Test"; Result: Boolean; + ShopifyPaymentTermsId: BigInteger; begin // [SCENARIO] Convert an existing company record to a "Shpfy Company" and "Shpfy Company Location" record. @@ -45,5 +53,78 @@ codeunit 139636 "Shpfy Company Export Test" LibraryAssert.AreEqual(Customer."Post Code", CompanyLocation.Zip, 'Post Code'); LibraryAssert.AreEqual(Customer.City, CompanyLocation.City, 'City'); LibraryAssert.AreEqual(Customer."Country/Region Code", CompanyLocation."Country/Region Code", 'Country'); + LibraryAssert.AreEqual(ShopifyPaymentTermsId, CompanyLocation."Shpfy Payment Terms Id", 'Payment Terms Id should be 0'); + end; + + [Test] + procedure UnitTestFillInShopifyCustomerDataWithLocationPaymentTerm() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + PaymentTermsCode: Code[10]; + ShopifyPaymentTermsId: BigInteger; + begin + // [SCENARIO] Export company with payment terms. + Initialize(); + + // [GIVEN] Payment terms + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Shopify payment terms + CreateShopifyPaymentTerms(PaymentTermsCode); + // [GIVEN] Customer record with payment terms + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Payment Terms Code" := PaymentTermsCode; + Customer.Insert(false); + // [GIVEN] Shopify Company + ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); + ShopifyCompany."Customer SystemId" := Customer.SystemId; + ShopifyCompany.Insert(false); + // [GIVEN] Company Location + CompanyLocation.Init(); + CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation.Insert(false); + + // [WHEN] Invoke FillInShopifyCompany + CompanyExport.FillInShopifyCompany(Customer, ShopifyCompany, CompanyLocation); + + // [THEN] The payment terms id is set in the company location record. + LibraryAssert.AreEqual(ShopifyPaymentTermsId, CompanyLocation."Shpfy Payment Terms Id", 'Payment Terms Id'); + end; + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + + if IsInitialized then + exit; + Shop := InitializeTest.CreateShop(); + + IsInitialized := true; + + Commit(); + end; + + local procedure CreatePaymentTerms(): Code[10] + var + PaymentTerms: Record "Payment Terms"; + begin + PaymentTerms.Init(); + PaymentTerms.Code := Any.AlphanumericText(10); + PaymentTerms.Insert(false); + end; + + local procedure CreateShopifyPaymentTerms(var PaymentTermsCode: Code[10]): BigInteger + var + ShopifyPaymentTerms: Record "Shpfy Payment Terms"; + begin + ShopifyPaymentTerms.Init(); + ShopifyPaymentTerms.Id := Any.IntegerInRange(10000, 99999); + ShopifyPaymentTerms."Payment Terms Code" := PaymentTermsCode; + ShopifyPaymentTerms.Insert(false); + exit(ShopifyPaymentTerms.Id); end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingSubs.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingSubs.Codeunit.al new file mode 100644 index 000000000..f464dc7d4 --- /dev/null +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingSubs.Codeunit.al @@ -0,0 +1,56 @@ +codeunit 139629 "Shpfy Company Mapping Subs." +{ + EventSubscriberInstance = Manual; + + var + CompanyImportExecuted: Boolean; + + [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; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + GetCompanyGQLStartTok: Label '{"query":"{company(id: \"gid://shopify/Company/', Locked = true; + GetCompanyGQLEndTok: Label '\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}}}}"}', 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.StartsWith(GetCompanyGQLStartTok) and GraphQlQuery.EndsWith(GetCompanyGQLEndTok) then begin + HttpResponseMessage := GetEmptyResponse(); + CompanyImportExecuted := true; + end; + end; + end; + end; + + local procedure GetEmptyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{}'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure GetCompanyImportExecuted(): Boolean + begin + exit(CompanyImportExecuted); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al index 3d7c45c1b..966358865 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al @@ -178,14 +178,14 @@ codeunit 139627 "Shpfy Company Mapping Test" end; [Test] - procedure UnitTestDoMappingByTaxId() + procedure UnitTestFindMappingByTaxId() var Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; TempShopifyCustomer: Record "Shpfy Customer" temporary; FindMappingResult: Boolean; begin - // [SCENARIO] DoMapping using By Tax Id + // [SCENARIO] FindMapping using By Tax Id Initialize(); // [GIVEN] Shop with Company Mapping Type as By Tax Id @@ -203,7 +203,7 @@ codeunit 139627 "Shpfy Company Mapping Test" end; [Test] - procedure UnitTestDoMappingByTaxIdWithRegistrationNo() + procedure UnitTestFindMappingByTaxIdWithRegistrationNo() var Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; @@ -212,7 +212,7 @@ codeunit 139627 "Shpfy Company Mapping Test" FindMappingResult: Boolean; EmptyGuid: Guid; begin - // [SCENARIO] DoMapping using By Tax Id with Registration No. + // [SCENARIO] FindMapping using By Tax Id with Registration No. Initialize(); // [GIVEN] Shop with Company Mapping Type as By Tax Id @@ -245,7 +245,7 @@ codeunit 139627 "Shpfy Company Mapping Test" end; [Test] - procedure UnitTestDoMappingByTaxIdWithRegistrationNoAndRandomCustomerSysId() + procedure UnitTestFindMappingByTaxIdWithRegistrationNoAndRandomCustomerSysId() var Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; @@ -253,7 +253,7 @@ codeunit 139627 "Shpfy Company Mapping Test" ShopifyCustomer: Record "Shpfy Customer"; FindMappingResult: Boolean; begin - // [SCENARIO] DoMapping using By Tax Id with Registration No. and random customer system id + // [SCENARIO] FindMapping using By Tax Id with Registration No. and random customer system id Initialize(); // [GIVEN] Shop with Company Mapping Type as By Tax Id @@ -286,7 +286,7 @@ codeunit 139627 "Shpfy Company Mapping Test" end; [Test] - procedure UnitTestDoMappingByTaxIdWithRegistrationNoAndExistingShopifyCustomer() + procedure UnitTestFindMappingByTaxIdWithRegistrationNoAndExistingShopifyCustomer() var Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; @@ -295,7 +295,7 @@ codeunit 139627 "Shpfy Company Mapping Test" FindMappingResult: Boolean; EmptyGuid: Guid; begin - // [SCENARIO] DoMapping using By Tax Id with Registration No. and existing Shopify Customer + // [SCENARIO] FindMapping using By Tax Id with Registration No. and existing Shopify Customer Initialize(); // [GIVEN] Shop with Company Mapping Type as By Tax Id @@ -326,7 +326,7 @@ codeunit 139627 "Shpfy Company Mapping Test" end; [Test] - procedure UnitTestDoMappingByTaxIdWithVATRegistrationNo() + procedure UnitTestFindMappingByTaxIdWithVATRegistrationNo() var Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; @@ -335,7 +335,7 @@ codeunit 139627 "Shpfy Company Mapping Test" FindMappingResult: Boolean; EmptyGuid: Guid; begin - // [SCENARIO] DoMapping using By Tax Id with VAT Registration No. + // [SCENARIO] FindMapping using By Tax Id with VAT Registration No. Initialize(); // [GIVEN] Shop with Company Mapping Type as By Tax Id @@ -343,7 +343,7 @@ codeunit 139627 "Shpfy Company Mapping Test" // [GIVEN] Shop with Tax Registration Id Mapping as VAT Registration No. SetCompTaxIdMapping(Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."); // [GIVEN] Customer with VAT Registration No. - CreateCustomerWithRegistrationNo(Customer); + CreateCustomerWithVATRegistrationNo(Customer); // [GIVEN] Shopify Company CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); // [GIVEN] Company Location with Tax Registration Id @@ -365,6 +365,58 @@ codeunit 139627 "Shpfy Company Mapping Test" LibraryAssert.AreEqual(Customer.SystemId, ShopifyCompany."Customer SystemId", 'Customer system Id not transferred to shopify company.'); end; + [Test] + procedure UnitTestDoMappingByTaxId() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + DoMappingResult: Code[20]; + begin + // [SCENARIO] DoMapping using By Tax Id mapping + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shopify Company with customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, Customer.SystemId); + + // [WHEN] DoMapping is called + InvokeDoMapping(ShopifyCompany.Id, DoMappingResult); + + // [THEN] The result is the same as the Customer No. field of the Customer record + LibraryAssert.AreEqual(Customer."No.", DoMappingResult, 'Mapping result is different than default company no.'); + end; + + [Test] + procedure UnitTestDoMappingByTaxIdWithEmptyGuid() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CompanyMappingSubs: Codeunit "Shpfy Company Mapping Subs."; + DoMappingResult: Code[20]; + EmptyGuid: Guid; + begin + // [SCENARIO] DoMapping using By Tax Id mapping with empty guid for Shopify Company Customer System Id + Initialize(); + + // [GIVEN] Shop with Company Mapping Type as By Tax Id + SetMappingByTaxId(); + // [GIVEN] Customer + CreateCustomer(Customer); + // [GIVEN] Shopify Company with empty guid for customer system id + CreateShopifyCompanyWithCustomerSysId(ShopifyCompany, EmptyGuid); + + // [WHEN] DoMapping is called + BindSubscription(CompanyMappingSubs); + InvokeDoMapping(ShopifyCompany.Id, DoMappingResult); + UnbindSubscription(CompanyMappingSubs); + + // [THEN] Company Import codeunit is executed + LibraryAssert.IsTrue(CompanyMappingSubs.GetCompanyImportExecuted(), 'Company Import codeunit was not executed.'); + end; + local procedure Initialize() begin From bc4d15d0decf0fe6ff5ffe2f38a9a42ced1775c7 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 12:57:16 +0100 Subject: [PATCH 23/33] Payment terms integration tests, fix create customer Payment terms mapping --- .../Codeunits/ShpfyCreateCustomer.Codeunit.al | 7 +- .../Codeunits/ShpfyUpdateCustomer.Codeunit.al | 2 +- .../Companies/ShpfyCompanyAPITest.Codeunit.al | 25 +++ .../ShpfyCompanyExportTest.Codeunit.al | 43 ++-- .../ShpfyCompanyImportSubs.Codeunit.al | 72 +++++++ .../ShpfyCompanyImportTest.Codeunit.al | 195 +++++++++++++++++- .../ShpfyCompanyInitialize.Codeunit.al | 36 ++++ 7 files changed, 361 insertions(+), 19 deletions(-) create mode 100644 Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCreateCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCreateCustomer.Codeunit.al index f9ea70b37..f4f661779 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCreateCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyCreateCustomer.Codeunit.al @@ -115,6 +115,7 @@ codeunit 30110 "Shpfy Create Customer" ShopifyTaxArea: Record "Shpfy Tax Area"; CustContUpdate: Codeunit "CustCont-Update"; CustomerTemplMgt: Codeunit "Customer Templ. Mgt."; + UpdateCustomer: Codeunit "Shpfy Update Customer"; ICounty: Interface "Shpfy ICounty"; CountryCode: Code[20]; CurrentTemplateCode: Code[20]; @@ -151,16 +152,18 @@ codeunit 30110 "Shpfy Create Customer" if CompanyLocation."Phone No." <> '' then Customer.Validate("Phone No.", CompanyLocation."Phone No."); - if ShopifyTaxArea.Get(CompanyLocation."Country/Region Code", CompanyLocation."Province Name") then begin if (ShopifyTaxArea."Tax Area Code" <> '') then begin Customer.Validate("Tax Area Code", ShopifyTaxArea."Tax Area Code"); Customer.Validate("Tax Liable", ShopifyTaxArea."Tax Liable"); end; if (ShopifyTaxArea."VAT Bus. Posting Group" <> '') then - Customer.Validate("VAT Bus. Posting Group", ShopifyTaxArea."VAT Bus. Posting Group"); + Customer.Validate("VAT Bus. Posting Group", ShopifyTaxArea."VAT Bus. Posting Group"); end; + if CompanyLocation."Shpfy Payment Terms Id" <> 0 then + Customer.Validate("Payment Terms Code", UpdateCustomer.GetPaymentTermsCodeFromShopifyPaymentTermsId(CompanyLocation."Shpfy Payment Terms Id")); + Customer.Modify(); ShopifyCustomer.Copy(TempShopifyCustomer); diff --git a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al index fd7090ec6..e7897f781 100644 --- a/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al @@ -190,7 +190,7 @@ codeunit 30124 "Shpfy Update Customer" Shop := ShopifyShop; end; - local procedure GetPaymentTermsCodeFromShopifyPaymentTermsId(ShpfyPaymentTermsId: BigInteger): Code[10] + internal procedure GetPaymentTermsCodeFromShopifyPaymentTermsId(ShpfyPaymentTermsId: BigInteger): Code[10] var ShpfyPaymentTerms: Record "Shpfy Payment Terms"; begin diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 740bd80bb..738b11a1a 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -142,4 +142,29 @@ codeunit 139637 "Shpfy Company API Test" LibraryAssert.AreEqual(ShopifyCompany."Main Contact Id", CompanyContactId, 'Company Contact Id'); LibraryAssert.AreEqual(ShopifyCompany."Main Contact Customer Id", CustomerId, 'Customer Id'); end; + + [Test] + procedure UnitTestCreateCompanyWithPaymentTerms() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + ShopifyCustomer: Record "Shpfy Customer"; + CompanyAPI: Codeunit "Shpfy Company API"; + GraphQL: Text; + begin + // [SCENARIO] Export company with payment terms. + + // [GIVEN] Shopify company + CompanyInitialize.CreateShopifyCompany(ShopifyCompany); + // [GIVEN] Shopify company location with payment terms id + CompanyLocation := CompanyInitialize.CreateShopifyCompanyLocation(ShopifyCompany); + CompanyLocation."Shpfy Payment Terms Id" := LibraryRandom.RandIntInRange(1000, 9999); + + // [WHEN] Invoke CompanyAPI.CreateCompanyGraphQLQuery + GraphQL := CompanyAPI.CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); + + // [THEN] The payment terms id is present in query. + LibraryAssert.IsTrue(GraphQL.Contains(StrSubstNo(CompanyInitialize.PaymentTermsGQLNode(), CompanyLocation."Shpfy Payment Terms Id")), 'Payment Terms Id'); + end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al index a9bfe312d..93561b92c 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyExportTest.Codeunit.al @@ -71,22 +71,13 @@ codeunit 139636 "Shpfy Company Export Test" // [GIVEN] Payment terms PaymentTermsCode := CreatePaymentTerms(); // [GIVEN] Shopify payment terms - CreateShopifyPaymentTerms(PaymentTermsCode); + ShopifyPaymentTermsId := CreateShopifyPaymentTerms(PaymentTermsCode); // [GIVEN] Customer record with payment terms - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer."Payment Terms Code" := PaymentTermsCode; - Customer.Insert(false); + CreateCustomer(Customer, PaymentTermsCode); // [GIVEN] Shopify Company - ShopifyCompany.Init(); - ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); - ShopifyCompany."Customer SystemId" := Customer.SystemId; - ShopifyCompany.Insert(false); + CreateCompany(ShopifyCompany, Customer.SystemId); // [GIVEN] Company Location - CompanyLocation.Init(); - CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; - CompanyLocation.Id := Any.IntegerInRange(10000, 99999); - CompanyLocation.Insert(false); + CreateCompanyLocation(CompanyLocation, ShopifyCompany.SystemId, ShopifyPaymentTermsId); // [WHEN] Invoke FillInShopifyCompany CompanyExport.FillInShopifyCompany(Customer, ShopifyCompany, CompanyLocation); @@ -115,6 +106,7 @@ codeunit 139636 "Shpfy Company Export Test" PaymentTerms.Init(); PaymentTerms.Code := Any.AlphanumericText(10); PaymentTerms.Insert(false); + exit(PaymentTerms.Code); end; local procedure CreateShopifyPaymentTerms(var PaymentTermsCode: Code[10]): BigInteger @@ -127,4 +119,29 @@ codeunit 139636 "Shpfy Company Export Test" ShopifyPaymentTerms.Insert(false); exit(ShopifyPaymentTerms.Id); end; + + local procedure CreateCustomer(var Customer: Record Customer; PaymentTermsCode: Code[10]) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Payment Terms Code" := PaymentTermsCode; + Customer.Insert(false); + end; + + local procedure CreateCompany(var ShopifyCompany: Record "Shpfy Company"; CustomerSystemId: Guid) + begin + ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); + ShopifyCompany."Customer SystemId" := CustomerSystemId; + ShopifyCompany.Insert(false); + end; + + local procedure CreateCompanyLocation(var CompanyLocation: Record "Shpfy Company Location"; ShopifyCompanySystemId: Guid; PaymentTermsId: BigInteger) + begin + CompanyLocation.Init(); + CompanyLocation."Company SystemId" := ShopifyCompanySystemId; + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Shpfy Payment Terms Id" := PaymentTermsId; + CompanyLocation.Insert(false); + end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al new file mode 100644 index 000000000..c809b9c63 --- /dev/null +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al @@ -0,0 +1,72 @@ +codeunit 139630 "Shpfy Company Import Subs." +{ + EventSubscriberInstance = Manual; + + var + CompanyImportExecuted: Boolean; + + [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; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + GetCompanyGQLStartTok: Label '{"query":"{company(id: \"gid://shopify/Company/', Locked = true; + GetCompanyGQLEndTok: Label '\") {name id note createdAt updatedAt mainContact { id customer { id firstName lastName email phone}}}}"}', Locked = true; + GetLocationsStartTok: Label '{"query": "{companyLocations(first:20, query: \"company_id:', 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 + case true of + GraphQlQuery.StartsWith(GetCompanyGQLStartTok) and GraphQlQuery.EndsWith(GetCompanyGQLEndTok): + HttpResponseMessage := GetCompanyResponse(); + GraphQlQuery.StartsWith(GetLocationsStartTok): + HttpResponseMessage := GetLocationsResponse(); + end; + end; + end; + end; + + local procedure GetCompanyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := StrSubstNo('{ "data": { "company" :{ "mainContact" : {}, "updatedAt" : "%1" } }}', Format(CurrentDateTime, 0, 9)); + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + local procedure GetLocationsResponse(): HttpResponseMessage + var + CompanyInitialize: Codeunit "Shpfy Company Initialize"; + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := CompanyInitialize.CreateLocationResponse(); + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure GetCompanyImportExecuted(): Boolean + begin + exit(CompanyImportExecuted); + end; + + +} \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al index 64afb0a08..1f627ed0d 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al @@ -4,7 +4,11 @@ codeunit 139647 "Shpfy Company Import Test" TestPermissions = Disabled; var + Shop: Record "Shpfy Shop"; LibraryAssert: Codeunit "Library Assert"; + Any: Codeunit Any; + InitializeTest: Codeunit "Shpfy Initialize Test"; + IsInitialized: Boolean; [Test] procedure UnitTestFindMappingBetweenCompanyAndCustomer() @@ -12,13 +16,11 @@ codeunit 139647 "Shpfy Company Import Test" Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; ShopifyCustomer: Record "Shpfy Customer"; - Shop: Record "Shpfy Shop"; - InitializeTest: Codeunit "Shpfy Initialize Test"; CompanyMapping: Codeunit "Shpfy Company Mapping"; Result: Boolean; begin // [SCENARIO] Importing a company record that is already mapped to a customer record via email. - Shop := InitializeTest.CreateShop(); + Initialize(); Shop."B2B Enabled" := true; // [GIVEN] Shop, Shopify company and Shopify customer @@ -36,4 +38,191 @@ codeunit 139647 "Shpfy Company Import Test" LibraryAssert.IsTrue(Result, 'Result'); LibraryAssert.AreEqual(ShopifyCompany."Customer SystemId", Customer.SystemId, 'Customer SystemId'); end; + + [Test] + procedure UnitTestImportCompanyWithLocation() + var + ShopifyCompany: Record "Shpfy Company"; + begin + // [SCENARIO] Importing a company with location with defined payment term. + Initialize(); + + // [GIVEN] Shopify company + ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); + ShopifyCompany."Shop Id" := Shop."Shop Id"; + ShopifyCompany."Created At" := CurrentDateTime() - 1; + ShopifyCompany.Insert(false); + + // [WHEN] Invoke CompanyImport + InvokeCompanyImport(ShopifyCompany); + + // [THEN] Location is created with the correct payment term and all other . + AssertShopifyCompanyLocationValues(ShopifyCompany); + end; + + [Test] + procedure UnitTestUpdateCustomerFromCompanyWithPaymentTerms() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + UpdateCustomer: Codeunit "Shpfy Update Customer"; + PaymentTermsCode: Code[10]; + ShopifyPaymentTermsId: BigInteger; + begin + // [SCENARIO] Update a customer from a company with location with defined payment term and existing payment terms in BC. + Initialize(); + + // [GIVEN] Payment terms + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Shopify payment terms + ShopifyPaymentTermsId := CreateShopifyPaymentTerms(PaymentTermsCode); + // [GIVEN] Customer record with payment terms + CreateCustomer(Customer, PaymentTermsCode); + // [GIVEN] Shopify Company + CreateCompany(ShopifyCompany, Customer.SystemId); + // [GIVEN] Company Location + CreateCompanyLocation(CompanyLocation, ShopifyCompany, ShopifyPaymentTermsId); + + // [WHEN] Invoke UpdateCustomerFromCompany + UpdateCustomer.UpdateCustomerFromCompany(ShopifyCompany); + + // [THEN] Customer record is updated with the correct payment terms. + Customer.GetBySystemId(Customer.SystemId); + LibraryAssert.AreEqual(Customer."Payment Terms Code", PaymentTermsCode, 'Payment Terms Code'); + end; + + [Test] + procedure UnitTestCreateCustomerFromCompanyWithPaymentTerms() + var + Customer: Record Customer; + TempShopifyCustomer: Record "Shpfy Customer" temporary; + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + CreateCustomer: Codeunit "Shpfy Create Customer"; + PaymentTermsCode: Code[10]; + ShopifyPaymentTermsId: BigInteger; + EmptyGuid: Guid; + begin + // [SCENARIO] Create a customer from a company with location with defined payment term. + Initialize(); + + // [GIVEN] Payment terms + PaymentTermsCode := CreatePaymentTerms(); + // [GIVEN] Shopify payment terms + ShopifyPaymentTermsId := CreateShopifyPaymentTerms(PaymentTermsCode); + // [GIVEN] Shopify Company + CreateCompany(ShopifyCompany, EmptyGuid); + // [GIVEN] Company Location + CreateCompanyLocation(CompanyLocation, ShopifyCompany, ShopifyPaymentTermsId); + // [GIVEN] TempShopifyCustomer + CreateTempShopifyCustomer(TempShopifyCustomer); + + // [WHEN] Invoke CreateCustomerFromCompany + CreateCustomer.SetShop(Shop); + CreateCustomer.SetTemplateCode(Shop."Customer Templ. Code"); + CreateCustomer.CreateCustomerFromCompany(ShopifyCompany, TempShopifyCustomer); + + // [THEN] Customer record is created with the correct payment terms. + Customer.GetBySystemId(ShopifyCompany."Customer SystemId"); + LibraryAssert.AreEqual(Customer."Payment Terms Code", PaymentTermsCode, 'Payment Terms Code'); + end; + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + if IsInitialized then + exit; + Shop := InitializeTest.CreateShop(); + IsInitialized := true; + + Commit(); + end; + + local procedure CreatePaymentTerms(): Code[10] + var + PaymentTerms: Record "Payment Terms"; + begin + PaymentTerms.Init(); + PaymentTerms.Code := Any.AlphanumericText(10); + PaymentTerms.Insert(false); + exit(PaymentTerms.Code); + end; + + local procedure CreateShopifyPaymentTerms(var PaymentTermsCode: Code[10]): BigInteger + var + ShopifyPaymentTerms: Record "Shpfy Payment Terms"; + begin + ShopifyPaymentTerms.Init(); + ShopifyPaymentTerms.Id := Any.IntegerInRange(10000, 99999); + ShopifyPaymentTerms."Payment Terms Code" := PaymentTermsCode; + ShopifyPaymentTerms.Insert(false); + exit(ShopifyPaymentTerms.Id); + end; + + local procedure CreateCustomer(var Customer: Record Customer; PaymentTermsCode: Code[10]) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Payment Terms Code" := PaymentTermsCode; + Customer.Insert(false); + end; + + local procedure CreateCompany(var ShopifyCompany: Record "Shpfy Company"; CustomerSystemId: Guid) + begin + ShopifyCompany.Init(); + ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); + ShopifyCompany."Customer SystemId" := CustomerSystemId; + ShopifyCompany.Insert(false); + end; + + local procedure CreateCompanyLocation(var CompanyLocation: Record "Shpfy Company Location"; var ShopifyCompany: Record "Shpfy Company"; PaymentTermsId: BigInteger) + begin + CompanyLocation.Init(); + CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Shpfy Payment Terms Id" := PaymentTermsId; + CompanyLocation.Insert(false); + + ShopifyCompany."Location Id" := CompanyLocation.Id; + ShopifyCompany.Modify(false); + end; + + local procedure CreateTempShopifyCustomer(var TempShopifyCustomer: Record "Shpfy Customer" temporary) + begin + TempShopifyCustomer.Init(); + TempShopifyCustomer.Id := Any.IntegerInRange(10000, 99999); + TempShopifyCustomer.Insert(false); + end; + + local procedure InvokeCompanyImport(var ShopifyCompany: Record "Shpfy Company") + var + CompanyImport: Codeunit "Shpfy Company Import"; + CompanyImportSubs: Codeunit "Shpfy Company Import Subs."; + begin + BindSubscription(CompanyImportSubs); + CompanyImport.SetShop(Shop); + ShopifyCompany.SetRange("Id", ShopifyCompany.Id); + CompanyImport.Run(ShopifyCompany); + UnbindSubscription(CompanyImportSubs); + end; + + local procedure AssertShopifyCompanyLocationValues(var ShopifyCompany: Record "Shpfy Company") + var + CompanyLocation: Record "Shpfy Company Location"; + begin + CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); + LibraryAssert.IsTrue(CompanyLocation.FindFirst(), 'Company location does not exist'); + LibraryAssert.IsTrue(CompanyLocation."Shpfy Payment Terms Id" <> 0, 'Payment Terms Id not imported'); + LibraryAssert.AreEqual('XYZ1234', CompanyLocation."Tax Registration Id", 'Tax Registration id not imported'); + LibraryAssert.AreEqual('Address', CompanyLocation.Address, 'Address not imported'); + LibraryAssert.AreEqual('Address 2', CompanyLocation."Address 2", 'Address 2 not imported'); + LibraryAssert.AreEqual('111', CompanyLocation."Phone No.", 'Phone No. not imported'); + LibraryAssert.AreEqual('1111', CompanyLocation.Zip, 'Zip not imported'); + LibraryAssert.AreEqual('City', CompanyLocation.City, 'City not imported'); + LibraryAssert.AreEqual('US', CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); + LibraryAssert.AreEqual('CA', CompanyLocation."Province Code", 'Province Code not imported'); + LibraryAssert.AreEqual('California', CompanyLocation."Province Name", 'Province Name not imported'); + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index 5f6a66858..93832609a 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -97,4 +97,40 @@ codeunit 139638 "Shpfy Company Initialize" JResult.ReadFrom(StrSubstNo(ResultLbl, Name, CompanyContactId, CustomerId, CompanyLocationId)); exit(JResult); end; + + internal procedure PaymentTermsGQLNode(): Text + begin + exit('buyerExperienceConfiguration: {paymentTermsTemplateId: \"gid://shopify/PaymentTermsTemplate/%1\"}'); + end; + + internal procedure CreateLocationResponse(): Text + var + Any: Codeunit Any; + JObject: JsonObject; + JCompanyLocations: JsonObject; + JEdges: JsonArray; + JNode: JsonObject; + JBillingAddress: JsonObject; + JPaymentTerms: JsonObject; + LocationResponse: Text; + begin + JNode.Add('id', StrSubstNo('gid://shopify/CompanyLocation/%1', Any.IntegerInRange(1000, 99999))); + JBillingAddress.Add('address1', 'Address'); + JBillingAddress.Add('address2', 'Address 2'); + JBillingAddress.Add('city', 'City'); + JBillingAddress.Add('countryCode', 'US'); + JBillingAddress.Add('zip', '1111'); + JBillingAddress.Add('phone', '111'); + JBillingAddress.Add('zoneCode', 'CA'); + JBillingAddress.Add('province', 'California'); + JNode.Add('billingAddress', JBillingAddress); + JNode.Add('taxRegistrationId', 'XYZ1234'); + JPaymentTerms.ReadFrom('{"paymentTermsTemplate": {id: "gid://shopify/PaymentTermsTemplate/111"}}'); + JNode.Add('buyerExperienceConfiguration', JPaymentTerms); + JEdges.Add(JNode); + JCompanyLocations.Add('edges', JEdges); + JObject.Add('companyLocations', JCompanyLocations); + JObject.WriteTo(LocationResponse); + exit(LocationResponse); + end; } From d86daa5e01563a321896e07a408ad0d943215d85 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 13:34:32 +0100 Subject: [PATCH 24/33] TaxID and Payment Terms export tests --- .../Companies/ShpfyCompanyAPISubs.Codeunit.al | 56 +++++++++++++ .../Companies/ShpfyCompanyAPITest.Codeunit.al | 80 ++++++++++++++++++- .../ShpfyCompanyInitialize.Codeunit.al | 5 ++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 Apps/W1/Shopify/test/Companies/ShpfyCompanyAPISubs.Codeunit.al diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPISubs.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPISubs.Codeunit.al new file mode 100644 index 000000000..d111005cd --- /dev/null +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPISubs.Codeunit.al @@ -0,0 +1,56 @@ +codeunit 139631 "Shpfy Company API Subs." +{ + EventSubscriberInstance = Manual; + + var + ExecutedQuery: Text; + + [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; + + local procedure MakeResponse(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + Uri: Text; + GraphQlQuery: Text; + ModifyLocationGQLStartTok: Label '{"query":"mutation {companyLocationUpdate(companyLocationId: ', Locked = true; + CreateTaxIdGQLStartTok: Label '{"query":"mutation {companyLocationCreateTaxRegistration(locationId:', 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.StartsWith(ModifyLocationGQLStartTok) or GraphQlQuery.StartsWith(CreateTaxIdGQLStartTok) then begin + HttpResponseMessage := GetEmptyResponse(); + ExecutedQuery := GraphQlQuery; + end; + end; + end; + end; + + local procedure GetEmptyResponse(): HttpResponseMessage + var + HttpResponseMessage: HttpResponseMessage; + Body: Text; + begin + Body := '{}'; + HttpResponseMessage.Content.WriteFrom(Body); + exit(HttpResponseMessage); + end; + + internal procedure GetExecutedQuery(): Text + begin + exit(ExecutedQuery); + end; +} \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 738b11a1a..91d2dc178 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -4,9 +4,13 @@ codeunit 139637 "Shpfy Company API Test" TestPermissions = Disabled; var + Shop: Record "Shpfy Shop"; + Any: Codeunit Any; LibraryAssert: Codeunit "Library Assert"; LibraryRandom: Codeunit "Library - Random"; + InitializeTest: Codeunit "Shpfy Initialize Test"; CompanyInitialize: Codeunit "Shpfy Company Initialize"; + IsInitialized: Boolean; [Test] procedure UnitTestCreateCompanyGraphQuery() @@ -146,7 +150,6 @@ codeunit 139637 "Shpfy Company API Test" [Test] procedure UnitTestCreateCompanyWithPaymentTerms() var - Customer: Record Customer; ShopifyCompany: Record "Shpfy Company"; CompanyLocation: Record "Shpfy Company Location"; ShopifyCustomer: Record "Shpfy Customer"; @@ -167,4 +170,79 @@ codeunit 139637 "Shpfy Company API Test" // [THEN] The payment terms id is present in query. LibraryAssert.IsTrue(GraphQL.Contains(StrSubstNo(CompanyInitialize.PaymentTermsGQLNode(), CompanyLocation."Shpfy Payment Terms Id")), 'Payment Terms Id'); end; + + [Test] + procedure UnitTestUpdateCompanyWithPaymentTerms() + var + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + GraphQL: Text; + begin + // [SCENARIO] Update Shopify company with payment terms. + Initialize(); + + // [GIVEN] Shopify company + CompanyInitialize.CreateShopifyCompany(ShopifyCompany); + // [GIVEN] Shopify company location with payment terms id + CompanyLocation := CompanyInitialize.CreateShopifyCompanyLocation(ShopifyCompany); + CompanyLocation."Shpfy Payment Terms Id" := LibraryRandom.RandIntInRange(1000, 9999); + CompanyLocation.Modify(false); + // [GIVEN] Shopify company location with changed payment terms id + CompanyLocation."Shpfy Payment Terms Id" := LibraryRandom.RandIntInRange(1000, 9999); + + // [WHEN] Invoke CompanyAPI.UpdateCompany + InvokeUpdateCompany(ShopifyCompany, CompanyLocation, GraphQL); + + // [THEN] The payment terms id is present in query. + LibraryAssert.IsTrue(GraphQL.Contains(StrSubstNo(CompanyInitialize.PaymentTermsGQLNode(), CompanyLocation."Shpfy Payment Terms Id")), 'Payment terms modification miisong'); + end; + + [Test] + procedure UnitTestUpdateCompanyLocationWithTaxId() + var + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + GraphQL: Text; + begin + // [SCENARIO] Update Shopify company location with tax id. + Initialize(); + + // [GIVEN] Shopify company + CompanyInitialize.CreateShopifyCompany(ShopifyCompany); + // [GIVEN] Shopify company location with tax id + CompanyLocation := CompanyInitialize.CreateShopifyCompanyLocation(ShopifyCompany); + CompanyLocation."Tax Registration Id" := Any.AlphanumericText(20); + CompanyLocation.Modify(false); + // [GIVEN] Shopify company location with changed tax id + CompanyLocation."Tax Registration Id" := Any.AlphanumericText(20); + + // [WHEN] Invoke CompanyAPI.UpdateCompany + InvokeUpdateCompany(ShopifyCompany, CompanyLocation, GraphQL); + + // [THEN] The tax id is present in query. + LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.TaxIdGQLNode(CompanyLocation)), 'Tax Registration Id'); + end; + + + local procedure Initialize() + begin + Any.SetDefaultSeed(); + + if IsInitialized then + exit; + Shop := InitializeTest.CreateShop(); + IsInitialized := true; + end; + + local procedure InvokeUpdateCompany(var ShopifyCompany: Record "Shpfy Company"; var CompanyLocation: Record "Shpfy Company Location"; var GraphQL: Text) + var + CompanyAPI: Codeunit "Shpfy Company API"; + CompanyAPISubs: Codeunit "Shpfy Company API Subs."; + begin + BindSubscription(CompanyAPISubs); + CompanyAPI.SetShop(Shop); + CompanyAPI.UpdateCompany(ShopifyCompany, CompanyLocation); + GraphQL := CompanyAPISubs.GetExecutedQuery(); + UnbindSubscription(CompanyAPISubs); + end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index 93832609a..4c9e107bd 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -133,4 +133,9 @@ codeunit 139638 "Shpfy Company Initialize" JObject.WriteTo(LocationResponse); exit(LocationResponse); end; + + internal procedure TaxIdGQLNode(CompanyLocation: Record "Shpfy Company Location"): Text + begin + exit(StrSubstNo('locationId: \"gid://shopify/CompanyLocation/%1\", taxId: \"%2\"', CompanyLocation.Id, CompanyLocation."Tax Registration Id")); + end; } From 853e713c0a067209b812ff2fb78f642446c9188a Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 13:58:06 +0100 Subject: [PATCH 25/33] Add external id export test --- .../Companies/ShpfyCompanyAPITest.Codeunit.al | 42 +++++++++++++++++++ .../ShpfyCompanyInitialize.Codeunit.al | 5 +++ 2 files changed, 47 insertions(+) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 91d2dc178..07a25d418 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -223,6 +223,33 @@ codeunit 139637 "Shpfy Company API Test" LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.TaxIdGQLNode(CompanyLocation)), 'Tax Registration Id'); end; + [Test] + procedure UnitTestCreateCompanyGraphQueryWithExternalId() + var + Customer: Record Customer; + ShopifyCompany: Record "Shpfy Company"; + CompanyLocation: Record "Shpfy Company Location"; + ShopifyCustomer: Record "Shpfy Customer"; + CompanyAPI: Codeunit "Shpfy Company API"; + GraphQL: Text; + begin + // [SCENARIO] Creating the GrapghQL query to create a new company in Shopify with external id. + Initialize(); + + // [GIVEN] Customer record + CreateCustomer(Customer); + // [GIVEN] Shopify Company connected with customer + CompanyInitialize.CreateShopifyCompany(ShopifyCompany); + // [GIVEN] Shopify Customer connected with customer + CreateShopifyCustomer(ShopifyCustomer, Customer.SystemId); + + // [WHEN] Invoke CompanyAPI.CreateCompanyGraphQLQuery + GraphQL := CompanyAPI.CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); + + // [THEN] The external id is present in query. + LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.ExternalIdGQLNode(Customer)), 'External Id'); + end; + local procedure Initialize() begin @@ -245,4 +272,19 @@ codeunit 139637 "Shpfy Company API Test" GraphQL := CompanyAPISubs.GetExecutedQuery(); UnbindSubscription(CompanyAPISubs); end; + + local procedure CreateCustomer(var Customer: Record Customer) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer.Insert(false); + end; + + local procedure CreateShopifyCustomer(var ShopifyCustomer: Record "Shpfy Customer"; CustomerSystemId: Guid) + begin + ShopifyCustomer.Init(); + ShopifyCustomer.Id := Any.IntegerInRange(10000, 99999); + ShopifyCustomer."Customer SystemId" := CustomerSystemId; + ShopifyCustomer.Insert(false); + end; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index 4c9e107bd..a72dd1d52 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -138,4 +138,9 @@ codeunit 139638 "Shpfy Company Initialize" begin exit(StrSubstNo('locationId: \"gid://shopify/CompanyLocation/%1\", taxId: \"%2\"', CompanyLocation.Id, CompanyLocation."Tax Registration Id")); end; + + internal procedure ExternalIdGQLNode(Customer: Record Customer): Text + begin + exit(StrSubstNo('externalId: \"%1\"', Customer."No.")); + end; } From 6e073693b1dd05ad181d80981747cb480282bf05 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 16:30:14 +0100 Subject: [PATCH 26/33] refactor --- .../Companies/ShpfyCompanyAPITest.Codeunit.al | 6 +- .../ShpfyCompanyImportTest.Codeunit.al | 14 ++--- .../ShpfyTaxIdMappingTest.Codeunit.al | 60 ++++++++++--------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 07a25d418..4e3f2bda9 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -194,7 +194,7 @@ codeunit 139637 "Shpfy Company API Test" InvokeUpdateCompany(ShopifyCompany, CompanyLocation, GraphQL); // [THEN] The payment terms id is present in query. - LibraryAssert.IsTrue(GraphQL.Contains(StrSubstNo(CompanyInitialize.PaymentTermsGQLNode(), CompanyLocation."Shpfy Payment Terms Id")), 'Payment terms modification miisong'); + LibraryAssert.IsTrue(GraphQL.Contains(StrSubstNo(CompanyInitialize.PaymentTermsGQLNode(), CompanyLocation."Shpfy Payment Terms Id")), 'Payment terms modification missing in query.'); end; [Test] @@ -220,7 +220,7 @@ codeunit 139637 "Shpfy Company API Test" InvokeUpdateCompany(ShopifyCompany, CompanyLocation, GraphQL); // [THEN] The tax id is present in query. - LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.TaxIdGQLNode(CompanyLocation)), 'Tax Registration Id'); + LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.TaxIdGQLNode(CompanyLocation)), 'Tax Registration Id missing in query.'); end; [Test] @@ -247,7 +247,7 @@ codeunit 139637 "Shpfy Company API Test" GraphQL := CompanyAPI.CreateCompanyGraphQLQuery(ShopifyCompany, CompanyLocation, ShopifyCustomer); // [THEN] The external id is present in query. - LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.ExternalIdGQLNode(Customer)), 'External Id'); + LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.ExternalIdGQLNode(Customer)), 'externalId missing in query.'); end; diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al index 1f627ed0d..cc300b42f 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al @@ -43,16 +43,13 @@ codeunit 139647 "Shpfy Company Import Test" procedure UnitTestImportCompanyWithLocation() var ShopifyCompany: Record "Shpfy Company"; + EmptyGuid: Guid; begin // [SCENARIO] Importing a company with location with defined payment term. Initialize(); // [GIVEN] Shopify company - ShopifyCompany.Init(); - ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); - ShopifyCompany."Shop Id" := Shop."Shop Id"; - ShopifyCompany."Created At" := CurrentDateTime() - 1; - ShopifyCompany.Insert(false); + CreateCompany(ShopifyCompany, EmptyGuid); // [WHEN] Invoke CompanyImport InvokeCompanyImport(ShopifyCompany); @@ -79,7 +76,7 @@ codeunit 139647 "Shpfy Company Import Test" // [GIVEN] Shopify payment terms ShopifyPaymentTermsId := CreateShopifyPaymentTerms(PaymentTermsCode); // [GIVEN] Customer record with payment terms - CreateCustomer(Customer, PaymentTermsCode); + CreateCustomerWithPaymentTerms(Customer, PaymentTermsCode); // [GIVEN] Shopify Company CreateCompany(ShopifyCompany, Customer.SystemId); // [GIVEN] Company Location @@ -150,7 +147,7 @@ codeunit 139647 "Shpfy Company Import Test" exit(PaymentTerms.Code); end; - local procedure CreateShopifyPaymentTerms(var PaymentTermsCode: Code[10]): BigInteger + local procedure CreateShopifyPaymentTerms(PaymentTermsCode: Code[10]): BigInteger var ShopifyPaymentTerms: Record "Shpfy Payment Terms"; begin @@ -161,7 +158,7 @@ codeunit 139647 "Shpfy Company Import Test" exit(ShopifyPaymentTerms.Id); end; - local procedure CreateCustomer(var Customer: Record Customer; PaymentTermsCode: Code[10]) + local procedure CreateCustomerWithPaymentTerms(var Customer: Record Customer; PaymentTermsCode: Code[10]) begin Customer.Init(); Customer."No." := Any.AlphanumericText(20); @@ -174,6 +171,7 @@ codeunit 139647 "Shpfy Company Import Test" ShopifyCompany.Init(); ShopifyCompany.Id := Any.IntegerInRange(10000, 99999); ShopifyCompany."Customer SystemId" := CustomerSystemId; + ShopifyCompany."Shop Id" := Shop."Shop Id"; ShopifyCompany.Insert(false); end; diff --git a/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al index 5ee859353..2a5aeabc6 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyTaxIdMappingTest.Codeunit.al @@ -24,12 +24,10 @@ codeunit 139628 "Shpfy Tax Id Mapping Test" // [SCENARIO] GetTaxRegistrationId for Tax Registration No. implementation of mapping Initialize(); - // [GIVEN] Customer record with Tax Registration No. + // [GIVEN] Registration No. RegistrationNo := Any.AlphanumericText(50); - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer."Registration Number" := RegistrationNo; - Customer.Insert(false); + // [GIVEN] Customer + CreateCustomerWithRegistrationNo(Customer, RegistrationNo); // [GIVEN] TaxRegistrationIdMapping interface is "Registration No." TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."; @@ -51,12 +49,10 @@ codeunit 139628 "Shpfy Tax Id Mapping Test" // [SCENARIO] GetTaxRegistrationId for VAT Registration No. implementation of mapping Initialize(); - // [GIVEN] Customer record with VAT Registration No. + // [GIVEN] VAT Registration No. VATRegistrationNo := Any.AlphanumericText(20); - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer."VAT Registration No." := VATRegistrationNo; - Customer.Insert(false); + // [GIVEN] Customer + CreateCustomerWithVATRegNo(Customer, VATRegistrationNo); // [GIVEN] TaxRegistrationIdMapping interface is "VAT Registration No." TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."; @@ -81,15 +77,9 @@ codeunit 139628 "Shpfy Tax Id Mapping Test" // [GIVEN] Registration No. RegistrationNo := Any.AlphanumericText(50); // [GIVEN] Customer record with Registration No. - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer."Registration Number" := RegistrationNo; - Customer.Insert(false); + CreateCustomerWithRegistrationNo(Customer, RegistrationNo); // [GIVEN] CompanyLocation record with Tax Registration Id - CompanyLocation.Init(); - CompanyLocation.Id := Any.IntegerInRange(10000, 99999); - CompanyLocation."Tax Registration Id" := RegistrationNo; - CompanyLocation.Insert(false); + CreateLocationWithTaxId(CompanyLocation, RegistrationNo); // [GIVEN] TaxRegistrationIdMapping interface is "Registration No." TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"Registration No."; @@ -114,15 +104,9 @@ codeunit 139628 "Shpfy Tax Id Mapping Test" // [GIVEN] VAT Registration No. VATRegistrationNo := Any.AlphanumericText(20); // [GIVEN] Customer record with VAT Registration No. - Customer.Init(); - Customer."No." := Any.AlphanumericText(20); - Customer."VAT Registration No." := VATRegistrationNo; - Customer.Insert(false); + CreateCustomerWithRegistrationNo(Customer, VATRegistrationNo); // [GIVEN] CompanyLocation record with Tax Registration Id - CompanyLocation.Init(); - CompanyLocation.Id := Any.IntegerInRange(10000, 99999); - CompanyLocation."Tax Registration Id" := VATRegistrationNo; - CompanyLocation.Insert(false); + CreateLocationWithTaxId(CompanyLocation, VATRegistrationNo); // [GIVEN] TaxRegistrationIdMapping interface is "VAT Registration No." TaxRegistrationIdMapping := Enum::"Shpfy Comp. Tax Id Mapping"::"VAT Registration No."; @@ -146,5 +130,27 @@ codeunit 139628 "Shpfy Tax Id Mapping Test" Commit(); end; + local procedure CreateCustomerWithRegistrationNo(var Customer: Record Customer; var RegistrationNo: Text[50]) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."Registration Number" := RegistrationNo; + Customer.Insert(false); + end; + + local procedure CreateCustomerWithVATRegNo(var Customer: Record Customer; var VATRegistrationNo: Text[20]) + begin + Customer.Init(); + Customer."No." := Any.AlphanumericText(20); + Customer."VAT Registration No." := VATRegistrationNo; + Customer.Insert(false); + end; -} + local procedure CreateLocationWithTaxId(var CompanyLocation: Record "Shpfy Company Location"; var RegistrationNo: Text[50]) + begin + CompanyLocation.Init(); + CompanyLocation.Id := Any.IntegerInRange(10000, 99999); + CompanyLocation."Tax Registration Id" := RegistrationNo; + CompanyLocation.Insert(false); + end; +} \ No newline at end of file From edc648010bc90be1dd7f03be022a2c0a73ed877b Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 30 Oct 2024 20:47:08 +0100 Subject: [PATCH 27/33] refactor --- .../ShpfyCompanyImportSubs.Codeunit.al | 7 ++- .../ShpfyCompanyImportTest.Codeunit.al | 51 ++++++++++++++----- .../ShpfyCompanyInitialize.Codeunit.al | 24 ++++----- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al index c809b9c63..494553717 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportSubs.Codeunit.al @@ -3,6 +3,7 @@ codeunit 139630 "Shpfy Company Import Subs." EventSubscriberInstance = Manual; var + LocationValues: Dictionary of [Text, Text]; CompanyImportExecuted: Boolean; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Shpfy Communication Events", 'OnClientSend', '', true, false)] @@ -58,7 +59,7 @@ codeunit 139630 "Shpfy Company Import Subs." HttpResponseMessage: HttpResponseMessage; Body: Text; begin - Body := CompanyInitialize.CreateLocationResponse(); + Body := CompanyInitialize.CreateLocationResponse(LocationValues); HttpResponseMessage.Content.WriteFrom(Body); exit(HttpResponseMessage); end; @@ -68,5 +69,9 @@ codeunit 139630 "Shpfy Company Import Subs." exit(CompanyImportExecuted); end; + internal procedure SetLocationValues(NewLocationValues: Dictionary of [Text, Text]) + begin + LocationValues := NewLocationValues; + end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al index cc300b42f..43aac7710 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al @@ -43,6 +43,7 @@ codeunit 139647 "Shpfy Company Import Test" procedure UnitTestImportCompanyWithLocation() var ShopifyCompany: Record "Shpfy Company"; + LocationValues: Dictionary of [Text, Text]; EmptyGuid: Guid; begin // [SCENARIO] Importing a company with location with defined payment term. @@ -50,12 +51,14 @@ codeunit 139647 "Shpfy Company Import Test" // [GIVEN] Shopify company CreateCompany(ShopifyCompany, EmptyGuid); + // [GIVEN] Company location values in Shopify + CreateLocationValues(LocationValues); // [WHEN] Invoke CompanyImport - InvokeCompanyImport(ShopifyCompany); + InvokeCompanyImport(ShopifyCompany, LocationValues); // [THEN] Location is created with the correct payment term and all other . - AssertShopifyCompanyLocationValues(ShopifyCompany); + VerifyShopifyCompanyLocationValues(ShopifyCompany, LocationValues); end; [Test] @@ -194,33 +197,53 @@ codeunit 139647 "Shpfy Company Import Test" TempShopifyCustomer.Insert(false); end; - local procedure InvokeCompanyImport(var ShopifyCompany: Record "Shpfy Company") + local procedure InvokeCompanyImport(var ShopifyCompany: Record "Shpfy Company"; LocationValues: Dictionary of [Text, Text]) var CompanyImport: Codeunit "Shpfy Company Import"; CompanyImportSubs: Codeunit "Shpfy Company Import Subs."; begin BindSubscription(CompanyImportSubs); + CompanyImportSubs.SetLocationValues(LocationValues); CompanyImport.SetShop(Shop); ShopifyCompany.SetRange("Id", ShopifyCompany.Id); CompanyImport.Run(ShopifyCompany); UnbindSubscription(CompanyImportSubs); end; - local procedure AssertShopifyCompanyLocationValues(var ShopifyCompany: Record "Shpfy Company") + local procedure VerifyShopifyCompanyLocationValues(var ShopifyCompany: Record "Shpfy Company"; LocationValues: Dictionary of [Text, Text]) var CompanyLocation: Record "Shpfy Company Location"; + Id, PaymentTermsId : BigInteger; begin + Evaluate(Id, LocationValues.Get('id')); + Evaluate(PaymentTermsId, LocationValues.Get('paymentTermsTemplateId')); CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); LibraryAssert.IsTrue(CompanyLocation.FindFirst(), 'Company location does not exist'); - LibraryAssert.IsTrue(CompanyLocation."Shpfy Payment Terms Id" <> 0, 'Payment Terms Id not imported'); - LibraryAssert.AreEqual('XYZ1234', CompanyLocation."Tax Registration Id", 'Tax Registration id not imported'); - LibraryAssert.AreEqual('Address', CompanyLocation.Address, 'Address not imported'); - LibraryAssert.AreEqual('Address 2', CompanyLocation."Address 2", 'Address 2 not imported'); - LibraryAssert.AreEqual('111', CompanyLocation."Phone No.", 'Phone No. not imported'); - LibraryAssert.AreEqual('1111', CompanyLocation.Zip, 'Zip not imported'); - LibraryAssert.AreEqual('City', CompanyLocation.City, 'City not imported'); - LibraryAssert.AreEqual('US', CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); - LibraryAssert.AreEqual('CA', CompanyLocation."Province Code", 'Province Code not imported'); - LibraryAssert.AreEqual('California', CompanyLocation."Province Name", 'Province Name not imported'); + LibraryAssert.AreEqual(Id, CompanyLocation.Id, 'Id not imported'); + LibraryAssert.AreEqual(LocationValues.Get('address'), CompanyLocation.Address, 'Address not imported'); + LibraryAssert.AreEqual(LocationValues.Get('address2'), CompanyLocation."Address 2", 'Address 2 not imported'); + LibraryAssert.AreEqual(LocationValues.Get('phone'), CompanyLocation."Phone No.", 'Phone No. not imported'); + LibraryAssert.AreEqual(LocationValues.Get('zip'), CompanyLocation.Zip, 'Zip not imported'); + LibraryAssert.AreEqual(LocationValues.Get('city'), CompanyLocation.City, 'City not imported'); + LibraryAssert.AreEqual(LocationValues.Get('country'), CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); + LibraryAssert.AreEqual(LocationValues.Get('zoneCode'), CompanyLocation."Province Code", 'Province Code not imported'); + LibraryAssert.AreEqual(LocationValues.Get('province'), CompanyLocation."Province Name", 'Province Name not imported'); + LibraryAssert.AreEqual(PaymentTermsId, CompanyLocation."Shpfy Payment Terms Id", 'Payment Terms Id not imported'); + LibraryAssert.AreEqual(LocationValues.Get('taxRegistrationId'), CompanyLocation."Tax Registration Id", 'Tax Registration id not imported'); + end; + + local procedure CreateLocationValues(LocationValues: Dictionary of [Text, Text]) + begin + LocationValues.Add('id', Format(Any.IntegerInRange(10000, 99999))); + LocationValues.Add('address', Any.AlphanumericText(20)); + LocationValues.Add('address2', Any.AlphanumericText(20)); + LocationValues.Add('phone', Format(Any.IntegerInRange(1000, 9999))); + LocationValues.Add('zip', Format(Any.IntegerInRange(1000, 9999))); + LocationValues.Add('city', Any.AlphanumericText(20)); + LocationValues.Add('country', Any.AlphanumericText(2)); + LocationValues.Add('zoneCode', Any.AlphanumericText(2)); + LocationValues.Add('province', Any.AlphanumericText(20)); + LocationValues.Add('paymentTermsTemplateId', Format(Any.IntegerInRange(10000, 99999))); + LocationValues.Add('taxRegistrationId', Any.AlphanumericText(50)); end; } \ No newline at end of file diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index a72dd1d52..6eaf9ea7d 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -103,7 +103,7 @@ codeunit 139638 "Shpfy Company Initialize" exit('buyerExperienceConfiguration: {paymentTermsTemplateId: \"gid://shopify/PaymentTermsTemplate/%1\"}'); end; - internal procedure CreateLocationResponse(): Text + internal procedure CreateLocationResponse(LocationValues: Dictionary of [Text, Text]): Text var Any: Codeunit Any; JObject: JsonObject; @@ -114,18 +114,18 @@ codeunit 139638 "Shpfy Company Initialize" JPaymentTerms: JsonObject; LocationResponse: Text; begin - JNode.Add('id', StrSubstNo('gid://shopify/CompanyLocation/%1', Any.IntegerInRange(1000, 99999))); - JBillingAddress.Add('address1', 'Address'); - JBillingAddress.Add('address2', 'Address 2'); - JBillingAddress.Add('city', 'City'); - JBillingAddress.Add('countryCode', 'US'); - JBillingAddress.Add('zip', '1111'); - JBillingAddress.Add('phone', '111'); - JBillingAddress.Add('zoneCode', 'CA'); - JBillingAddress.Add('province', 'California'); + JNode.Add('id', StrSubstNo('gid://shopify/CompanyLocation/%1', LocationValues.Get('id'))); + JBillingAddress.Add('address1', LocationValues.Get('address1')); + JBillingAddress.Add('address2', LocationValues.Get('address2')); + JBillingAddress.Add('city', LocationValues.Get('city')); + JBillingAddress.Add('countryCode', LocationValues.Get('countryCode')); + JBillingAddress.Add('zip', LocationValues.Get('zip')); + JBillingAddress.Add('phone', LocationValues.Get('phone')); + JBillingAddress.Add('zoneCode', LocationValues.Get('zoneCode')); + JBillingAddress.Add('province', LocationValues.Get('province')); JNode.Add('billingAddress', JBillingAddress); - JNode.Add('taxRegistrationId', 'XYZ1234'); - JPaymentTerms.ReadFrom('{"paymentTermsTemplate": {id: "gid://shopify/PaymentTermsTemplate/111"}}'); + JNode.Add('taxRegistrationId', LocationValues.Get('taxRegistrationId')); + JPaymentTerms.ReadFrom(StrSubstNo('{"paymentTermsTemplate": {id: "gid://shopify/PaymentTermsTemplate/%1"}}', LocationValues.Get('paymentTermsTemplateId'))); JNode.Add('buyerExperienceConfiguration', JPaymentTerms); JEdges.Add(JNode); JCompanyLocations.Add('edges', JEdges); From da0530631c089f950e7f8857d936bf2fdb34bd9d Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Thu, 31 Oct 2024 09:28:05 +0100 Subject: [PATCH 28/33] fix test --- .../test/Companies/ShpfyCompanyImportTest.Codeunit.al | 8 ++++---- .../test/Companies/ShpfyCompanyInitialize.Codeunit.al | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al index 43aac7710..2c49b02e2 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al @@ -220,12 +220,12 @@ codeunit 139647 "Shpfy Company Import Test" CompanyLocation.SetRange("Company SystemId", ShopifyCompany.SystemId); LibraryAssert.IsTrue(CompanyLocation.FindFirst(), 'Company location does not exist'); LibraryAssert.AreEqual(Id, CompanyLocation.Id, 'Id not imported'); - LibraryAssert.AreEqual(LocationValues.Get('address'), CompanyLocation.Address, 'Address not imported'); + LibraryAssert.AreEqual(LocationValues.Get('address1'), CompanyLocation.Address, 'Address not imported'); LibraryAssert.AreEqual(LocationValues.Get('address2'), CompanyLocation."Address 2", 'Address 2 not imported'); LibraryAssert.AreEqual(LocationValues.Get('phone'), CompanyLocation."Phone No.", 'Phone No. not imported'); LibraryAssert.AreEqual(LocationValues.Get('zip'), CompanyLocation.Zip, 'Zip not imported'); LibraryAssert.AreEqual(LocationValues.Get('city'), CompanyLocation.City, 'City not imported'); - LibraryAssert.AreEqual(LocationValues.Get('country'), CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); + LibraryAssert.AreEqual(LocationValues.Get('countryCode'), CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); LibraryAssert.AreEqual(LocationValues.Get('zoneCode'), CompanyLocation."Province Code", 'Province Code not imported'); LibraryAssert.AreEqual(LocationValues.Get('province'), CompanyLocation."Province Name", 'Province Name not imported'); LibraryAssert.AreEqual(PaymentTermsId, CompanyLocation."Shpfy Payment Terms Id", 'Payment Terms Id not imported'); @@ -235,12 +235,12 @@ codeunit 139647 "Shpfy Company Import Test" local procedure CreateLocationValues(LocationValues: Dictionary of [Text, Text]) begin LocationValues.Add('id', Format(Any.IntegerInRange(10000, 99999))); - LocationValues.Add('address', Any.AlphanumericText(20)); + LocationValues.Add('address1', Any.AlphanumericText(20)); LocationValues.Add('address2', Any.AlphanumericText(20)); LocationValues.Add('phone', Format(Any.IntegerInRange(1000, 9999))); LocationValues.Add('zip', Format(Any.IntegerInRange(1000, 9999))); LocationValues.Add('city', Any.AlphanumericText(20)); - LocationValues.Add('country', Any.AlphanumericText(2)); + LocationValues.Add('countryCode', Any.AlphanumericText(2)); LocationValues.Add('zoneCode', Any.AlphanumericText(2)); LocationValues.Add('province', Any.AlphanumericText(20)); LocationValues.Add('paymentTermsTemplateId', Format(Any.IntegerInRange(10000, 99999))); diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al index 6eaf9ea7d..48ed43e55 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyInitialize.Codeunit.al @@ -3,7 +3,6 @@ codeunit 139638 "Shpfy Company Initialize" SingleInstance = true; var - Any: Codeunit Any; internal procedure CreateShopifyCompanyLocation() CompanyLocation: Record "Shpfy Company Location" From 58bbf662a7e6d313442a54e21cdc5919395bc577 Mon Sep 17 00:00:00 2001 From: Gediminas Gaubys Date: Thu, 31 Oct 2024 12:34:30 +0200 Subject: [PATCH 29/33] Minor adjustment --- .../Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al index 2c49b02e2..58372fbda 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyImportTest.Codeunit.al @@ -225,8 +225,8 @@ codeunit 139647 "Shpfy Company Import Test" LibraryAssert.AreEqual(LocationValues.Get('phone'), CompanyLocation."Phone No.", 'Phone No. not imported'); LibraryAssert.AreEqual(LocationValues.Get('zip'), CompanyLocation.Zip, 'Zip not imported'); LibraryAssert.AreEqual(LocationValues.Get('city'), CompanyLocation.City, 'City not imported'); - LibraryAssert.AreEqual(LocationValues.Get('countryCode'), CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); - LibraryAssert.AreEqual(LocationValues.Get('zoneCode'), CompanyLocation."Province Code", 'Province Code not imported'); + LibraryAssert.AreEqual(LocationValues.Get('countryCode').ToUpper(), CompanyLocation."Country/Region Code", 'Country/Region Code not imported'); + LibraryAssert.AreEqual(LocationValues.Get('zoneCode').ToUpper(), CompanyLocation."Province Code", 'Province Code not imported'); LibraryAssert.AreEqual(LocationValues.Get('province'), CompanyLocation."Province Name", 'Province Name not imported'); LibraryAssert.AreEqual(PaymentTermsId, CompanyLocation."Shpfy Payment Terms Id", 'Payment Terms Id not imported'); LibraryAssert.AreEqual(LocationValues.Get('taxRegistrationId'), CompanyLocation."Tax Registration Id", 'Tax Registration id not imported'); From f4dc3841b1a2db09dbd84ded4d12d5f3b37f798f Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Tue, 12 Nov 2024 14:03:44 +0100 Subject: [PATCH 30/33] fix naming --- .../Codeunits/ShpfyCompByTaxId.Codeunit.al | 14 ++++++------- .../Codeunits/ShpfyCompanyExport.Codeunit.al | 20 +++++++++---------- .../Codeunits/ShpfyCompanyMapping.Codeunit.al | 4 ++-- .../Tables/ShpfyCompanyLocation.Table.al | 2 +- .../ShpfyCompanyMappingTest.Codeunit.al | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al index cd75259a8..9c5d293d1 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompByTaxId.Codeunit.al @@ -51,16 +51,16 @@ codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shp local procedure CreateCompany(CompanyId: BigInteger; ShopCode: Code[20]; TemplateCode: Code[20]; AllowCreate: Boolean): Code[20] var ShopifyCompany: Record "Shpfy Company"; - TempCompany: Record "Shpfy Company" temporary; + TempShopifyCompany: Record "Shpfy Company" temporary; CompanyImport: Codeunit "Shpfy Company Import"; begin CompanyImport.SetShop(ShopCode); CompanyImport.SetAllowCreate(AllowCreate); CompanyImport.SetTemplateCode(TemplateCode); - TempCompany.Id := CompanyId; - TempCompany.Insert(false); + TempShopifyCompany.Id := CompanyId; + TempShopifyCompany.Insert(false); - CompanyImport.Run(TempCompany); + CompanyImport.Run(TempShopifyCompany); CompanyImport.GetCompany(ShopifyCompany); if ShopifyCompany.Find() then ShopifyCompany.CalcFields("Customer No."); @@ -73,12 +73,12 @@ codeunit 30366 "Shpfy Comp. By Tax Id" implements "Shpfy ICompany Mapping", "Shp Customer: Record Customer; ShopifyCustomer: Record "Shpfy Customer"; Shop: Record "Shpfy Shop"; - ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; begin Clear(Customer); Shop.Get(ShopifyCompany."Shop Code"); - ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; - ShpfyTaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); + TaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; + TaxRegistrationIdMapping.SetMappingFiltersForCustomers(Customer, CompanyLocation); if Customer.FindFirst() then begin ShopifyCompany."Customer SystemId" := Customer.SystemId; 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 221ab9dc2..a503a65d5 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyExport.Codeunit.al @@ -88,7 +88,7 @@ codeunit 30284 "Shpfy Company Export" TaxArea: Record "Shpfy Tax Area"; TempShopifyCompany: Record "Shpfy Company" temporary; TempCompanyLocation: Record "Shpfy Company Location" temporary; - ShpfyTaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; + TaxRegistrationIdMapping: Interface "Shpfy Tax Registration Id Mapping"; CountyCodeTooLongErr: Text; ShpfyPaymentTermsId: BigInteger; begin @@ -145,10 +145,10 @@ codeunit 30284 "Shpfy Company Export" CompanyLocation."Phone No." := Customer."Phone No."; - ShpfyTaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; - CompanyLocation."Tax Registration Id" := ShpfyTaxRegistrationIdMapping.GetTaxRegistrationId(Customer); + TaxRegistrationIdMapping := Shop."Shpfy Comp. Tax Id Mapping"; + CompanyLocation."Tax Registration Id" := TaxRegistrationIdMapping.GetTaxRegistrationId(Customer); - if GetShpfyPaymentTermsIdFromCustomer(Customer, ShpfyPaymentTermsId) then + if GetShopifyPaymentTermsIdFromCustomer(Customer, ShpfyPaymentTermsId) then CompanyLocation."Shpfy Payment Terms Id" := ShpfyPaymentTermsId; if HasDiff(ShopifyCompany, TempShopifyCompany) or HasDiff(CompanyLocation, TempCompanyLocation) then begin @@ -209,14 +209,14 @@ codeunit 30284 "Shpfy Company Export" CreateCustomers := NewCustomers; end; - local procedure GetShpfyPaymentTermsIdFromCustomer(Customer: Record Customer; var ShpfyPaymentTermsId: BigInteger): Boolean + local procedure GetShopifyPaymentTermsIdFromCustomer(Customer: Record Customer; var ShpfyPaymentTermsId: BigInteger): Boolean var - ShpfyPaymentTerms: Record "Shpfy Payment Terms"; + ShopifyPaymentTerms: Record "Shpfy Payment Terms"; begin - ShpfyPaymentTerms.SetRange("Shop Code", Shop.Code); - ShpfyPaymentTerms.SetRange("Payment Terms Code", Customer."Payment Terms Code"); - if ShpfyPaymentTerms.FindFirst() then begin - ShpfyPaymentTermsId := ShpfyPaymentTerms.Id; + ShopifyPaymentTerms.SetRange("Shop Code", Shop.Code); + ShopifyPaymentTerms.SetRange("Payment Terms Code", Customer."Payment Terms Code"); + if ShopifyPaymentTerms.FindFirst() then begin + ShpfyPaymentTermsId := ShopifyPaymentTerms.Id; exit(true); end; end; diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al index c33129139..4237999ee 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyMapping.Codeunit.al @@ -20,14 +20,14 @@ codeunit 30303 "Shpfy Company Mapping" internal procedure FindMapping(var ShopifyCompany: Record "Shpfy Company"; var TempShopifyCustomer: Record "Shpfy Customer" temporary): Boolean; var - ShpfyCompByEmailPhone: Codeunit "Shpfy Comp. By Email/Phone"; + CompByEmailPhone: Codeunit "Shpfy Comp. By Email/Phone"; IMapping: Interface "Shpfy ICompany Mapping"; begin IMapping := Shop."Company Mapping Type"; if IMapping is "Shpfy IFind Company Mapping" then exit((IMapping as "Shpfy IFind Company Mapping").FindMapping(ShopifyCompany, TempShopifyCustomer)) else - ShpfyCompByEmailPhone.FindMapping(ShopifyCompany, TempShopifyCustomer); + CompByEmailPhone.FindMapping(ShopifyCompany, TempShopifyCustomer); end; internal procedure SetShop(Code: Code[20]) diff --git a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al index 769bef712..6b876271f 100644 --- a/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al +++ b/Apps/W1/Shopify/app/src/Companies/Tables/ShpfyCompanyLocation.Table.al @@ -93,7 +93,7 @@ table 30151 "Shpfy Company Location" } field(14; "Shpfy Payment Terms Id"; BigInteger) { - Caption = 'Shpfy Payment Terms Id'; + Caption = 'Shopify Payment Terms Id'; DataClassification = CustomerContent; ToolTip = 'Specifies the Shopify Payment Terms Id which is mapped with Customer''s Payment Terms.'; } diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al index 966358865..d2bcb5c94 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyMappingTest.Codeunit.al @@ -524,9 +524,9 @@ codeunit 139627 "Shpfy Company Mapping Test" Customer.Modify(false); end; - local procedure SetCompTaxIdMapping(ShpfyCompTaxIdMapping: Enum Microsoft.Integration.Shopify."Shpfy Comp. Tax Id Mapping") + local procedure SetCompTaxIdMapping(ShopifyCompTaxIdMapping: Enum Microsoft.Integration.Shopify."Shpfy Comp. Tax Id Mapping") begin - Shop."Shpfy Comp. Tax Id Mapping" := ShpfyCompTaxIdMapping; + Shop."Shpfy Comp. Tax Id Mapping" := ShopifyCompTaxIdMapping; Shop.Modify(false); end; From f6c0c19ee1ad0171801caf550fe2578348b10783 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 13 Nov 2024 11:26:19 +0100 Subject: [PATCH 31/33] remove duplicated object --- .../Codeunits/ShpfySkipRecordMgt.Codeunit.al | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al diff --git a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al b/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al deleted file mode 100644 index 9c0f4a5ea..000000000 --- a/Apps/W1/Shopify/app/src/Logs/Codeunits/ShpfySkipRecordMgt.Codeunit.al +++ /dev/null @@ -1,44 +0,0 @@ -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; - -} From d5e6fad3aa6831a9dbf84bb5e67cb4ce619dff62 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 13 Nov 2024 12:44:07 +0100 Subject: [PATCH 32/33] fix issue with default location --- .../app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 22d076355..9093f25d8 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -394,6 +394,7 @@ codeunit 30286 "Shpfy Company API" begin if JsonHelper.GetJsonArray(JResponse, JLocations, 'data.companyLocations.edges') then begin foreach JLocation in JLocations do begin + Clear(CompanyLocation); Cursor := JsonHelper.GetValueAsText(JLocation.AsObject(), 'cursor'); CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLocation, 'node.id')); if IsDefaultCompanyLocation then @@ -404,7 +405,7 @@ codeunit 30286 "Shpfy Company API" CompanyLocation.Id := CompanyLocationId; CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); - CompanyLocation.Insert(); + CompanyLocation.Insert(true); end; CompanyLocation.Address := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.billingAddress.address1', MaxStrLen(CompanyLocation.Address)), 1, MaxStrLen(CompanyLocation.Address)); From b6e00ce1440fa6feae0e8dea1d7cf12d96452d30 Mon Sep 17 00:00:00 2001 From: Piotr Michalak Date: Wed, 13 Nov 2024 15:18:43 +0100 Subject: [PATCH 33/33] change clear to init --- .../app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al | 2 +- Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al index 9093f25d8..bf62c2c74 100644 --- a/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al +++ b/Apps/W1/Shopify/app/src/Companies/Codeunits/ShpfyCompanyAPI.Codeunit.al @@ -394,7 +394,6 @@ codeunit 30286 "Shpfy Company API" begin if JsonHelper.GetJsonArray(JResponse, JLocations, 'data.companyLocations.edges') then begin foreach JLocation in JLocations do begin - Clear(CompanyLocation); Cursor := JsonHelper.GetValueAsText(JLocation.AsObject(), 'cursor'); CompanyLocationId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLocation, 'node.id')); if IsDefaultCompanyLocation then @@ -402,6 +401,7 @@ codeunit 30286 "Shpfy Company API" CompanyLocation.SetRange(Id, CompanyLocationId); if not CompanyLocation.FindFirst() then begin + CompanyLocation.Init(); CompanyLocation.Id := CompanyLocationId; CompanyLocation."Company SystemId" := ShopifyCompany.SystemId; CompanyLocation.Name := CopyStr(JsonHelper.GetValueAsText(JLocation, 'node.name'), 1, MaxStrLen(CompanyLocation.Name)); diff --git a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al index 4e3f2bda9..9b071be3e 100644 --- a/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al +++ b/Apps/W1/Shopify/test/Companies/ShpfyCompanyAPITest.Codeunit.al @@ -250,7 +250,6 @@ codeunit 139637 "Shpfy Company API Test" LibraryAssert.IsTrue(GraphQL.Contains(CompanyInitialize.ExternalIdGQLNode(Customer)), 'externalId missing in query.'); end; - local procedure Initialize() begin Any.SetDefaultSeed();