Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions src/Layers/ES/Tests/Misc/DocumentAttachmentTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ codeunit 134776 "Document Attachment Tests"
OpportunityTwoLbl: Label 'Opportunity2';
RenameCodeLbl: Label 'T';
SecondAttachmentFileNameMismatchErr: Label 'Second file name not equal to saved attachment.';
SourceRecordNotResolvedErr: Label 'The source record must be resolved for the %1.', Comment = '%1 = Table Caption';
UnexpectedSourceTableErr: Label 'The RecordRef must be opened on the %1.', Comment = '%1 = Table Caption';
TwoAttachmentsExpectedErr: Label 'Two attachments were expected for this record.';
ValueMustBeEqualErr: Label '%1 must be equal to %2 in the %3.', Comment = '%1 = Field Caption , %2 = Expected Value, %3 = Table Caption';

Expand Down Expand Up @@ -4526,6 +4528,98 @@ codeunit 134776 "Document Attachment Tests"
CheckDocAttachments(Database::"Sales Line", 2, CreditMemoNo, SalesHeaderReturnOrder."Document Type"::"Credit Memo".AsInteger(), 'SalesReturnLine');
end;

[Test]
procedure EnsureAttachmentCanBeUploadedOnPostedSalesShipment()
var
Customer: Record Customer;
Item: Record Item;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
SalesShipmentHeader: Record "Sales Shipment Header";
DocumentAttachment: Record "Document Attachment";
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
// [SCENARIO 646549] Uploading a file from the Documents FactBox on Posted Sales Shipment must not fail with "The record is not open".
Initialize();

// [GIVEN] Create Customer and Item with a new Inventory Posting Setup for the blank Location, so the shipment can be posted.
LibrarySales.CreateCustomer(Customer);
LibraryInventory.CreateItem(Item);
CreateInventoryPostingSetupForItem(Item);

// [GIVEN] Create and post Sales Order to get a Posted Sales Shipment.
CreateSalesDoc(SalesHeader, SalesLine, Customer, Item, SalesHeader."Document Type"::Order);
SalesShipmentHeader.Get(LibrarySales.PostSalesDocument(SalesHeader, true, false));

// [GIVEN] Document Attachment record as the Documents FactBox filters it on the Posted Sales Shipment page.
DocumentAttachment.Init();
DocumentAttachment."Table ID" := Database::"Sales Shipment Header";
DocumentAttachment."No." := SalesShipmentHeader."No.";

// [WHEN] The Documents FactBox resolves the source record before saving the uploaded file.
// [THEN] The source record is resolved and the RecordRef is opened on Sales Shipment Header.
Assert.IsTrue(
DocumentAttachmentMgmt.GetRefTable(RecRef, DocumentAttachment),
StrSubstNo(SourceRecordNotResolvedErr, SalesShipmentHeader.TableCaption()));
Assert.AreEqual(
Database::"Sales Shipment Header",
RecRef.Number(),
StrSubstNo(UnexpectedSourceTableErr, SalesShipmentHeader.TableCaption()));

// [WHEN] The uploaded file is saved through the resolved RecordRef.
CreateDocAttach(RecRef, 'PostedSalesShipment.jpeg', false, false);

// [THEN] Verify the attachment is stored for the Posted Sales Shipment.
CheckDocAttachmentsForPostedDocs(Database::"Sales Shipment Header", 1, SalesShipmentHeader."No.", 'PostedSalesShipment');
end;

[Test]
procedure EnsureAttachmentCanBeUploadedOnPostedReturnReceipt()
var
Customer: Record Customer;
Item: Record Item;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
ReturnReceiptHeader: Record "Return Receipt Header";
DocumentAttachment: Record "Document Attachment";
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
// [SCENARIO 646549] Uploading a file from the Documents FactBox on Posted Return Receipt must not fail with "The record is not open".
Initialize();

// [GIVEN] Create Customer and Item with a new Inventory Posting Setup for the blank Location, so the return receipt can be posted.
LibrarySales.CreateCustomer(Customer);
LibraryInventory.CreateItem(Item);
CreateInventoryPostingSetupForItem(Item);

// [GIVEN] Create and post Sales Return Order to get a Posted Return Receipt.
CreateSalesDoc(SalesHeader, SalesLine, Customer, Item, SalesHeader."Document Type"::"Return Order");
ReturnReceiptHeader.Get(LibrarySales.PostSalesDocument(SalesHeader, true, false));

// [GIVEN] Document Attachment record as the Documents FactBox filters it on the Posted Return Receipt page.
DocumentAttachment.Init();
DocumentAttachment."Table ID" := Database::"Return Receipt Header";
DocumentAttachment."No." := ReturnReceiptHeader."No.";

// [WHEN] The Documents FactBox resolves the source record before saving the uploaded file.
// [THEN] The source record is resolved and the RecordRef is opened on Return Receipt Header.
Assert.IsTrue(
DocumentAttachmentMgmt.GetRefTable(RecRef, DocumentAttachment),
StrSubstNo(SourceRecordNotResolvedErr, ReturnReceiptHeader.TableCaption()));
Assert.AreEqual(
Database::"Return Receipt Header",
RecRef.Number(),
StrSubstNo(UnexpectedSourceTableErr, ReturnReceiptHeader.TableCaption()));

// [WHEN] The uploaded file is saved through the resolved RecordRef.
CreateDocAttach(RecRef, 'PostedReturnReceipt.jpeg', false, false);

// [THEN] Verify the attachment is stored for the Posted Return Receipt.
CheckDocAttachmentsForPostedDocs(Database::"Return Receipt Header", 1, ReturnReceiptHeader."No.", 'PostedReturnReceipt');
end;

local procedure Initialize()
var
LibraryERMCountryData: Codeunit "Library - ERM Country Data";
Expand Down Expand Up @@ -5184,6 +5278,21 @@ codeunit 134776 "Document Attachment Tests"
CreateDocAttachProductionImageType(RecRef, StrSubstNo(AttachmentFileNameLbl, LibraryRandom.RandText(5)), true);
end;

local procedure CreateInventoryPostingSetupForItem(var Item: Record Item)
var
InventoryPostingGroup: Record "Inventory Posting Group";
InventoryPostingSetup: Record "Inventory Posting Setup";
begin
LibraryInventory.CreateInventoryPostingGroup(InventoryPostingGroup);
LibraryInventory.CreateInventoryPostingSetup(InventoryPostingSetup, '', InventoryPostingGroup.Code);
InventoryPostingSetup.Validate("Inventory Account", LibraryERM.CreateGLAccountNo());
InventoryPostingSetup.Validate("Inventory Account (Interim)", LibraryERM.CreateGLAccountNo());
InventoryPostingSetup.Modify(true);

Item.Validate("Inventory Posting Group", InventoryPostingGroup.Code);
Item.Modify(true);
end;

[ModalPageHandler]
procedure RelatedAttachmentsHandler(var RelatedAttachmentsPage: TestPage "Email Related Attachments")
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ page 1178 "Doc. Attachment List Factbox"
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then
if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then begin
Comment thread
DhavalMore88 marked this conversation as resolved.
Comment thread
DhavalMore88 marked this conversation as resolved.
OnAfterGetRecRefFail(Rec, RecRef);
if RecRef.Number() = 0 then
Error(CannotResolveSourceRecordErr, Rec."Table ID");
end;
DocumentAttachment.SaveAttachment(files, RecRef);
CurrPage.Update();
end;
Expand Down Expand Up @@ -195,8 +198,11 @@ page 1178 "Doc. Attachment List Factbox"
if Rec."Table ID" = 0 then
exit;

if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then
if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then begin
OnAfterGetRecRefFail(Rec, RecRef);
if RecRef.Number() = 0 then
Error(CannotResolveSourceRecordErr, Rec."Table ID");
end;
DocumentAttachmentDetails.OpenForRecRef(RecRef);
OnBeforeDocumentAttachmentDetailsRunModal(Rec, RecRef, DocumentAttachmentDetails);
DocumentAttachmentDetails.RunModal();
Expand All @@ -207,8 +213,11 @@ page 1178 "Doc. Attachment List Factbox"
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then
if not DocumentAttachmentMgmt.GetRefTable(RecRef, Rec) then begin
OnAfterGetRecRefFail(Rec, RecRef);
if RecRef.Number() = 0 then
Error(CannotResolveSourceRecordErr, Rec."Table ID");
end;
OfficeMgmt.InitiateSendToAttachments(RecRef);
CurrPage.Update(true);
end;
Expand Down Expand Up @@ -263,6 +272,7 @@ page 1178 "Doc. Attachment List Factbox"
IsOfficeAddIn: Boolean;
EmailHasAttachments: Boolean;
CannotDownloadOrViewFileWithEmptyNameErr: Label 'The file must have a name.';
CannotResolveSourceRecordErr: Label 'Attachments are not supported for table %1.', Comment = '%1 = Table ID of the record that the attachment belongs to.';
Comment thread
DhavalMore88 marked this conversation as resolved.

[IntegrationEvent(true, false)]
local procedure OnAfterGetRecRefFail(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ codeunit 1173 "Document Attachment Mgmt"
Job: Record Job;
SalesCrMemoHeader: Record "Sales Cr.Memo Header";
SalesInvoiceHeader: Record "Sales Invoice Header";
SalesShipmentHeader: Record "Sales Shipment Header";
ReturnReceiptHeader: Record "Return Receipt Header";
PurchInvHeader: Record "Purch. Inv. Header";
PurchCrMemoHdr: Record "Purch. Cr. Memo Hdr.";
VATReportHeader: Record "VAT Report Header";
Expand Down Expand Up @@ -176,6 +178,18 @@ codeunit 1173 "Document Attachment Mgmt"
if SalesCrMemoHeader.Get(DocumentAttachment."No.") then
RecRef.GetTable(SalesCrMemoHeader);
end;
Database::"Sales Shipment Header":
begin
RecRef.Open(Database::"Sales Shipment Header");
if SalesShipmentHeader.Get(DocumentAttachment."No.") then
RecRef.GetTable(SalesShipmentHeader);
end;
Database::"Return Receipt Header":
begin
RecRef.Open(Database::"Return Receipt Header");
if ReturnReceiptHeader.Get(DocumentAttachment."No.") then
RecRef.GetTable(ReturnReceiptHeader);
end;
Database::"Purchase Header":
begin
RecRef.Open(Database::"Purchase Header");
Expand Down
109 changes: 109 additions & 0 deletions src/Layers/W1/Tests/Misc/DocumentAttachmentTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ codeunit 134776 "Document Attachment Tests"
OpportunityTwoLbl: Label 'Opportunity2';
RenameCodeLbl: Label 'T';
SecondAttachmentFileNameMismatchErr: Label 'Second file name not equal to saved attachment.';
SourceRecordNotResolvedErr: Label 'The source record must be resolved for the %1.', Comment = '%1 = Table Caption';
UnexpectedSourceTableErr: Label 'The RecordRef must be opened on the %1.', Comment = '%1 = Table Caption';
TwoAttachmentsExpectedErr: Label 'Two attachments were expected for this record.';
ValueMustBeEqualErr: Label '%1 must be equal to %2 in the %3.', Comment = '%1 = Field Caption , %2 = Expected Value, %3 = Table Caption';

Expand Down Expand Up @@ -4526,6 +4528,98 @@ codeunit 134776 "Document Attachment Tests"
CheckDocAttachments(Database::"Sales Line", 2, CreditMemoNo, SalesHeaderReturnOrder."Document Type"::"Credit Memo".AsInteger(), 'SalesReturnLine');
end;

[Test]
Comment thread
DhavalMore88 marked this conversation as resolved.
procedure EnsureAttachmentCanBeUploadedOnPostedSalesShipment()
var
Customer: Record Customer;
Item: Record Item;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
SalesShipmentHeader: Record "Sales Shipment Header";
DocumentAttachment: Record "Document Attachment";
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
// [SCENARIO 646549] Uploading a file from the Documents FactBox on Posted Sales Shipment must not fail with "The record is not open".
Initialize();

// [GIVEN] Create Customer and Item with a new Inventory Posting Setup for the blank Location, so the shipment can be posted.
LibrarySales.CreateCustomer(Customer);
LibraryInventory.CreateItem(Item);
CreateInventoryPostingSetupForItem(Item);

// [GIVEN] Create and post Sales Order to get a Posted Sales Shipment.
CreateSalesDoc(SalesHeader, SalesLine, Customer, Item, SalesHeader."Document Type"::Order);
SalesShipmentHeader.Get(LibrarySales.PostSalesDocument(SalesHeader, true, false));

// [GIVEN] Document Attachment record as the Documents FactBox filters it on the Posted Sales Shipment page.
DocumentAttachment.Init();
DocumentAttachment."Table ID" := Database::"Sales Shipment Header";
DocumentAttachment."No." := SalesShipmentHeader."No.";

// [WHEN] The Documents FactBox resolves the source record before saving the uploaded file.
// [THEN] The source record is resolved and the RecordRef is opened on Sales Shipment Header.
Assert.IsTrue(
DocumentAttachmentMgmt.GetRefTable(RecRef, DocumentAttachment),
StrSubstNo(SourceRecordNotResolvedErr, SalesShipmentHeader.TableCaption()));
Assert.AreEqual(
Database::"Sales Shipment Header",
RecRef.Number(),
StrSubstNo(UnexpectedSourceTableErr, SalesShipmentHeader.TableCaption()));

// [WHEN] The uploaded file is saved through the resolved RecordRef.
CreateDocAttach(RecRef, 'PostedSalesShipment.jpeg', false, false);

// [THEN] Verify the attachment is stored for the Posted Sales Shipment.
CheckDocAttachmentsForPostedDocs(Database::"Sales Shipment Header", 1, SalesShipmentHeader."No.", 'PostedSalesShipment');
end;

[Test]
procedure EnsureAttachmentCanBeUploadedOnPostedReturnReceipt()
var
Customer: Record Customer;
Item: Record Item;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
ReturnReceiptHeader: Record "Return Receipt Header";
DocumentAttachment: Record "Document Attachment";
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
RecRef: RecordRef;
begin
// [SCENARIO 646549] Uploading a file from the Documents FactBox on Posted Return Receipt must not fail with "The record is not open".
Initialize();

// [GIVEN] Create Customer and Item with a new Inventory Posting Setup for the blank Location, so the return receipt can be posted.
LibrarySales.CreateCustomer(Customer);
LibraryInventory.CreateItem(Item);
CreateInventoryPostingSetupForItem(Item);

// [GIVEN] Create and post Sales Return Order to get a Posted Return Receipt.
CreateSalesDoc(SalesHeader, SalesLine, Customer, Item, SalesHeader."Document Type"::"Return Order");
ReturnReceiptHeader.Get(LibrarySales.PostSalesDocument(SalesHeader, true, false));

// [GIVEN] Document Attachment record as the Documents FactBox filters it on the Posted Return Receipt page.
DocumentAttachment.Init();
DocumentAttachment."Table ID" := Database::"Return Receipt Header";
DocumentAttachment."No." := ReturnReceiptHeader."No.";

// [WHEN] The Documents FactBox resolves the source record before saving the uploaded file.
// [THEN] The source record is resolved and the RecordRef is opened on Return Receipt Header.
Assert.IsTrue(
DocumentAttachmentMgmt.GetRefTable(RecRef, DocumentAttachment),
StrSubstNo(SourceRecordNotResolvedErr, ReturnReceiptHeader.TableCaption()));
Assert.AreEqual(
Database::"Return Receipt Header",
RecRef.Number(),
StrSubstNo(UnexpectedSourceTableErr, ReturnReceiptHeader.TableCaption()));

// [WHEN] The uploaded file is saved through the resolved RecordRef.
CreateDocAttach(RecRef, 'PostedReturnReceipt.jpeg', false, false);

// [THEN] Verify the attachment is stored for the Posted Return Receipt.
CheckDocAttachmentsForPostedDocs(Database::"Return Receipt Header", 1, ReturnReceiptHeader."No.", 'PostedReturnReceipt');
end;

local procedure Initialize()
var
LibraryERMCountryData: Codeunit "Library - ERM Country Data";
Expand Down Expand Up @@ -5172,6 +5266,21 @@ codeunit 134776 "Document Attachment Tests"
CreateDocAttachProductionImageType(RecRef, StrSubstNo(AttachmentFileNameLbl, LibraryRandom.RandText(5)), true);
end;

local procedure CreateInventoryPostingSetupForItem(var Item: Record Item)
var
InventoryPostingGroup: Record "Inventory Posting Group";
InventoryPostingSetup: Record "Inventory Posting Setup";
begin
LibraryInventory.CreateInventoryPostingGroup(InventoryPostingGroup);
LibraryInventory.CreateInventoryPostingSetup(InventoryPostingSetup, '', InventoryPostingGroup.Code);
InventoryPostingSetup.Validate("Inventory Account", LibraryERM.CreateGLAccountNo());
InventoryPostingSetup.Validate("Inventory Account (Interim)", LibraryERM.CreateGLAccountNo());
InventoryPostingSetup.Modify(true);

Item.Validate("Inventory Posting Group", InventoryPostingGroup.Code);
Item.Modify(true);
end;

[ModalPageHandler]
procedure RelatedAttachmentsHandler(var RelatedAttachmentsPage: TestPage "Email Related Attachments")
begin
Expand Down
Loading