Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shopify] Log Skipped Records on export processes #27539

Merged
merged 34 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
713875f
Add Skipped Record table definition
petemchlk Sep 25, 2024
096152a
Add logging function
petemchlk Sep 27, 2024
da67ced
Add retention policy related code
petemchlk Sep 28, 2024
134b1e7
Add new logs,add fields in log
petemchlk Oct 1, 2024
ff08b22
add skipping logs to lines export, add shop so logging can be ommited
petemchlk Oct 1, 2024
7deaef5
fixes after testing
petemchlk Oct 2, 2024
34d4c99
Add logging to shopify synch shipments to shopify
petemchlk Oct 2, 2024
6417191
Remove development code, add summaries
petemchlk Oct 3, 2024
2f950bb
fix/add summary
petemchlk Oct 3, 2024
bb49612
add skip action
petemchlk Oct 3, 2024
259b674
change text to label variable
petemchlk Oct 3, 2024
c704dc4
fix label
petemchlk Oct 3, 2024
7772a29
create tests for customer logs
petemchlk Oct 7, 2024
092bdc6
fix typo
petemchlk Oct 7, 2024
7b4b8fa
add product tests
petemchlk Oct 8, 2024
c284c52
add missing product variant tests
petemchlk Oct 9, 2024
b83ec43
add invoice tests and shipment tests
petemchlk Oct 9, 2024
b8246a5
add shipment export test
petemchlk Oct 9, 2024
f5d5da9
Add fulfillment test
petemchlk Oct 9, 2024
415b042
add DIsable logging test
petemchlk Oct 10, 2024
dc61ac0
test refactor fixes
petemchlk Oct 10, 2024
27c7538
tests refactor
petemchlk Oct 11, 2024
e3b5e6c
tests refactor and pr comments resolve
petemchlk Oct 11, 2024
adca60e
small refactors
petemchlk Oct 11, 2024
6b32486
reafactors
petemchlk Oct 14, 2024
def03a7
PR fixes
petemchlk Oct 14, 2024
8b5213f
Merge branch 'main' into dev/pmi/SkipRecordLog
petemchlk Oct 15, 2024
dc6c443
fix bug, move procedures to helper codeunit
petemchlk Oct 15, 2024
6f3e4c8
Renumber objects, add table to permissionsets
petemchlk Oct 25, 2024
713a726
PR fixes
petemchlk Oct 25, 2024
506f35a
Tests fixes
petemchlk Oct 25, 2024
958bdbe
PR fixes
petemchlk Oct 28, 2024
4f0ff2e
Merge branch 'main' into dev/pmi/SkipRecordLog
GediminasGaubys Oct 30, 2024
cfa6b3b
rename codeunit
petemchlk Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ codeunit 30273 "Shpfy Installer"
var
LogEntry: Record "Shpfy Log Entry";
DataCapture: Record "Shpfy Data Capture";
SkippedRecord: Record "Shpfy Skipped Record";
RetentionPolicySetup: Codeunit "Retention Policy Setup";
RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables";
UpgradeTag: Codeunit "Upgrade Tag";
Expand All @@ -38,12 +39,14 @@ codeunit 30273 "Shpfy Installer"

RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Log Entry", LogEntry.FieldNo(SystemCreatedAt));
RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Data Capture", DataCapture.FieldNo(SystemModifiedAt));
RetenPolAllowedTables.AddAllowedTable(Database::"Shpfy Skipped Record", SkippedRecord.FieldNo(SystemCreatedAt));

if not IsInitialSetup then
exit;

CreateRetentionPolicySetup(Database::"Shpfy Log Entry", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month"));
CreateRetentionPolicySetup(Database::"Shpfy Data Capture", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month"));
CreateRetentionPolicySetup(Database::"Shpfy Skipped Record", RetentionPolicySetup.FindOrCreateRetentionPeriod("Retention Period Enum"::"1 Month"));
UpgradeTag.SetUpgradeTag(GetShopifyLogEntryAddedToAllowedListUpgradeTag());
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ codeunit 30116 "Shpfy Customer Export"
var
Shop: Record "Shpfy Shop";
CustomerApi: Codeunit "Shpfy Customer API";
ShopifySkipRecordMgt: Codeunit "Shpfy Skip Record Mgt.";
CreateCustomers: Boolean;
CountyCodeTooLongLbl: Label 'Can not export customer %1 %2. The length of the string is %3, but it must be less than or equal to %4 characters. Value: %5, field: %6', Comment = '%1 - Customer No., %2 - Customer Name, %3 - Length, %4 - Max Length, %5 - Value, %6 - Field Name';

Expand Down Expand Up @@ -87,9 +88,12 @@ codeunit 30116 "Shpfy Customer Export"
var
ShopifyCustomer: Record "Shpfy Customer";
CustomerAddress: Record "Shpfy Customer Address";
EmptyEmailAddressLbl: Label 'Customer has no e-mail address.';
begin
if Customer."E-Mail" = '' then
if Customer."E-Mail" = '' then begin
ShopifySkipRecordMgt.LogSkippedRecord(Customer.RecordId, EmptyEmailAddressLbl, Shop);
exit;
end;

Clear(ShopifyCustomer);
Clear(CustomerAddress);
Expand Down Expand Up @@ -296,10 +300,13 @@ codeunit 30116 "Shpfy Customer Export"
var
ShopifyCustomer: Record "Shpfy Customer";
CustomerAddress: Record "Shpfy Customer Address";
CustomerWithPhoneNoOrEmailExistsLbl: Label 'Customer already exists with the same e-mail or phone.';
begin
ShopifyCustomer.Get(CustomerID);
if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then
if ShopifyCustomer."Customer SystemId" <> Customer.SystemId then begin
ShopifySkipRecordMgt.LogSkippedRecord(ShopifyCustomer.Id, Customer.RecordId, CustomerWithPhoneNoOrEmailExistsLbl, Shop);
exit; // An other customer with the same e-mail or phone is the source of it.
end;

CustomerAddress.SetRange("Customer Id", CustomerId);
CustomerAddress.SetRange(Default, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ codeunit 30362 "Shpfy Posted Invoice Export"
DraftOrdersAPI: Codeunit "Shpfy Draft Orders API";
FulfillmentAPI: Codeunit "Shpfy Fulfillment API";
JsonHelper: Codeunit "Shpfy Json Helper";
SkipRecordMgt: Codeunit "Shpfy Skip Record Mgt.";

trigger OnRun()
begin
Expand Down Expand Up @@ -92,22 +93,34 @@ codeunit 30362 "Shpfy Posted Invoice Export"
var
ShopifyCompany: Record "Shpfy Company";
ShopifyCustomer: Record "Shpfy Customer";
CustomerNotExistInShopifyLbl: Label 'Customer does not exists as Shopify company or customer.';
PaymentTermsNotExistLbl: Label 'Payment terms %1 do not exist in Shopify.', Comment = '%1 = Payment Terms Code.';
CustomerNoIsDefaultCustomerNoLbl: Label 'Bill-to customer no. is the default customer no. for Shopify shop.';
CustomerTemplateExistsLbl: Label 'Shopify Customer template exists for customer no. %1 shop %2.', Comment = '%1 = Customer No., %2 = Shop Code';
begin
ShopifyCompany.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No.");
if ShopifyCompany.IsEmpty() then begin
ShopifyCustomer.SetRange("Customer No.", SalesInvoiceHeader."Bill-to Customer No.");
if ShopifyCustomer.IsEmpty() then
if ShopifyCustomer.IsEmpty() then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNotExistInShopifyLbl, Shop);
exit(false);
end;
end;

if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then
if not ShopifyPaymentTermsExists(SalesInvoiceHeader."Payment Terms Code") then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(PaymentTermsNotExistLbl, SalesInvoiceHeader."Payment Terms Code"), Shop);
exit(false);
end;

if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then
if Shop."Default Customer No." = SalesInvoiceHeader."Bill-to Customer No." then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, CustomerNoIsDefaultCustomerNoLbl, Shop);
exit(false);
end;

if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then
if CheckCustomerTemplates(SalesInvoiceHeader."Bill-to Customer No.") then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, StrSubstNo(CustomerTemplateExistsLbl, SalesInvoiceHeader."Bill-to Customer No.", Shop.Code), Shop);
exit(false);
end;

if not CheckSalesInvoiceHeaderLines(SalesInvoiceHeader) then
exit(false);
Expand Down Expand Up @@ -145,22 +158,32 @@ codeunit 30362 "Shpfy Posted Invoice Export"
local procedure CheckSalesInvoiceHeaderLines(SalesInvoiceHeader: Record "Sales Invoice Header"): Boolean
var
SalesInvoiceLine: Record "Sales Invoice Line";
NoLinesInSalesInvoiceLbl: Label 'No relevant sales invoice lines exist.';
InvalidQuantityLbl: Label 'Invalid quantity in sales invoice line.';
EmptyNoInLineLbl: Label 'No. field is empty in Sales Invoice Line.';
begin
SalesInvoiceLine.SetRange("Document No.", SalesInvoiceHeader."No.");
SalesInvoiceLine.SetFilter(Type, '<>%1', SalesInvoiceLine.Type::" ");
if SalesInvoiceLine.IsEmpty() then
if SalesInvoiceLine.IsEmpty() then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceHeader.RecordId, NoLinesInSalesInvoiceLbl, Shop);
exit(false);
end;

SalesInvoiceLine.Reset();

SalesInvoiceLine.SetRange("Document No.", SalesInvoiceHeader."No.");
SalesInvoiceLine.SetRange(Type, SalesInvoiceLine.Type::Item);
if SalesInvoiceLine.FindSet() then
repeat
if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then
if (SalesInvoiceLine.Quantity <> 0) and (SalesInvoiceLine.Quantity <> Round(SalesInvoiceLine.Quantity, 1)) then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, InvalidQuantityLbl, Shop);
exit(false);
end;

if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then
if (SalesInvoiceLine.Type <> SalesInvoiceLine.Type::" ") and (SalesInvoiceLine."No." = '') then begin
SkipRecordMgt.LogSkippedRecord(SalesInvoiceLine.RecordId, EmptyNoInLineLbl, Shop);
exit(false);
end;
until SalesInvoiceLine.Next() = 0;

exit(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Microsoft.Integration.Shopify;

/// <summary>
/// Codeunit Shpfy Skip Record Mgt. (ID 30313).
/// </summary>
codeunit 30313 "Shpfy Skip Record Mgt."
{
Access = Internal;
Permissions = tabledata "Shpfy Skipped Record" = rimd;

/// <summary>
/// Creates log entry for skipped record.
/// </summary>
/// <param name="ShopifyId">Related Shopify Id of the record.</param>
/// <param name="TableId">Table Id of the record.</param>
/// <param name="RecordId">Record Id of the record.</param>
/// <param name="SkippedReason">Reason for skipping the record.</param>
/// <param name="Shop">Shop record.</param>
internal procedure LogSkippedRecord(ShopifyId: BigInteger; RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop")
var
ShpfySkippedRecord: Record "Shpfy Skipped Record";
begin
if Shop."Logging Mode" = Enum::"Shpfy Logging Mode"::Disabled then
exit;
ShpfySkippedRecord.Init();
ShpfySkippedRecord.Validate("Shopify Id", ShopifyId);
ShpfySkippedRecord.Validate("Table ID", RecordId.TableNo());
ShpfySkippedRecord.Validate("Record ID", RecordId);
ShpfySkippedRecord.Validate("Skipped Reason", SkippedReason);
ShpfySkippedRecord.Insert(true);
end;

/// <summary>
/// Creates log entry for skipped recordwith empty Shopify Id.
/// </summary>
/// <param name="RecordId">Record Id of the record.</param>
/// <param name="SkippedReason">Reason for skipping the record.</param>
/// <param name="Shop">Shop record.</param>
internal procedure LogSkippedRecord(RecordId: RecordID; SkippedReason: Text[250]; Shop: Record "Shpfy Shop")
begin
LogSkippedRecord(0, RecordId, SkippedReason, Shop);
end;

}
61 changes: 61 additions & 0 deletions Apps/W1/Shopify/app/src/Logs/Pages/ShpfySkippedRecords.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Microsoft.Integration.Shopify;

/// <summary>
/// Page Shpfy Skipped Records (ID 30166).
/// </summary>
page 30166 "Shpfy Skipped Records"
{
ApplicationArea = All;
Caption = 'Shopify Skipped Records';
PageType = List;
SourceTable = "Shpfy Skipped Record";
UsageCategory = Lists;
Editable = false;
InsertAllowed = false;
SourceTableView = sorting("Entry No.") order(descending);

layout
{
area(Content)
{
repeater(General)
{
field(EntryNo; Rec."Entry No.") { }
field("Shopify Id"; Rec."Shopify Id") { }
field("Table ID"; Rec."Table ID") { }
field("Table Name"; Rec."Table Name") { }
field(Description; Rec.Description)
{
trigger OnDrillDown()
begin
Rec.ShowPage();
end;
}
field("Skipped Reason"; Rec."Skipped Reason") { }
}
}
}

actions
{
area(Promoted)
{
actionref(Show_Promoted; Show) { }
}
area(Processing)
{
action(Show)
{
ApplicationArea = All;
Caption = 'Show record';
Image = View;
ToolTip = 'Show the details of the selected record.';

trigger OnAction()
begin
Rec.ShowPage();
end;
}
}
}
}
115 changes: 115 additions & 0 deletions Apps/W1/Shopify/app/src/Logs/Tables/ShpfySkippedRecord.Table.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace Microsoft.Integration.Shopify;

using System.Reflection;
using Microsoft.Utilities;

/// <summary>
/// Table Shpfy Skipped Record (ID 30159).
/// </summary>
table 30159 "Shpfy Skipped Record"
{
Caption = 'Shpfy Skipped Record';
DataClassification = CustomerContent;
Access = Internal;

fields
{
field(1; "Entry No."; Integer)
{
AutoIncrement = true;
Caption = 'Entry No.';
ToolTip = 'Specifies the number of the entry, as assigned from the specific number series when the entry was created.';

}
field(2; "Shopify Id"; BigInteger)
{
Caption = 'Skipped Record Id';
ToolTip = 'Specifies the Shopify Id of the skipped record.';
}
field(3; "Table ID"; Integer)
{
Caption = 'Table ID';
ToolTip = 'Specifies the Table ID of the skipped record.';
DataClassification = SystemMetadata;

trigger OnValidate()
begin
"Table Name" := GetTableCaption();
end;
}
field(4; "Table Name"; Text[250])
{
Caption = 'Table Name';
ToolTip = 'Specifies the Table Name of the skipped record.';
DataClassification = SystemMetadata;
}
field(5; "Record ID"; RecordID)
{
Caption = 'Record ID';
ToolTip = 'Specifies the Record ID of the skipped record.';

trigger OnValidate()
begin
Description := GetRecDescription();
end;
}
field(6; Description; Text[250])
{
Caption = 'Description';
ToolTip = 'Specifies the description of the skipped record.';
}
field(7; "Skipped Reason"; Text[250])
{
Caption = 'Skipped Reason';
ToolTip = 'Specifies the reason why the record was skipped.';
}
}
keys
{
key(Key1; "Entry No.")
{
Clustered = true;
}
}

local procedure GetTableCaption(): Text[250]
var
AllObjWithCaption: Record AllObjWithCaption;
begin
if "Table ID" <> 0 then
if AllObjWithCaption.Get(AllObjWithCaption."Object Type"::Table, "Table ID") then
exit(AllObjWithCaption."Object Caption");
end;

local procedure GetRecDescription() Result: Text
var
RecRef: RecordRef;
PKFilter: Text;
Delimiter: Text;
Pos: Integer;
begin
if RecRef.Get("Record ID") then begin
RecRef.SetRecFilter();
PKFilter := RecRef.GetView();
repeat
Pos := StrPos(PKFilter, '=FILTER(');
if Pos <> 0 then begin
PKFilter := CopyStr(PKFilter, Pos + 8);
Result += Delimiter + CopyStr(PKFilter, 1, StrPos(PKFilter, ')') - 1);
Delimiter := ',';
end;
until Pos = 0;
end;
end;

/// <summary>
/// Show related record from Record ID field.
/// </summary>
internal procedure ShowPage()
var
PageManagement: Codeunit "Page Management";
begin
if "Record ID".TableNo() <> 0 then
PageManagement.PageRun("Record ID");
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ permissionset 30102 "Shpfy - Edit"
tabledata "Shpfy Shop Collection Map" = IMD,
tabledata "Shpfy Shop Inventory" = IMD,
tabledata "Shpfy Shop Location" = IMD,
tabledata "Shpfy Skipped Record" = IMD,
tabledata "Shpfy Synchronization Info" = IMD,
tabledata "Shpfy Tag" = IMD,
tabledata "Shpfy Tax Area" = IMD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ permissionset 30100 "Shpfy - Read"
tabledata "Shpfy Shop Collection Map" = R,
tabledata "Shpfy Shop Inventory" = R,
tabledata "Shpfy Shop Location" = R,
tabledata "Shpfy Skipped Record" = R,
tabledata "Shpfy Synchronization Info" = R,
tabledata "Shpfy Tag" = R,
tabledata "Shpfy Tax Area" = R,
Expand Down
Loading
Loading