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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ codeunit 8060 "Create Billing Documents"
trigger OnRun()
var
BillingLine: Record "Billing Line";
PartnerFilter: Text;
ShowNotification: Boolean;
begin
BillingLine.Copy(Rec);
PartnerFilter := BillingLine.GetFilter(Partner);
ShowNotification := PartnerFilter <> BillingLine.GetFilters();
BillingLine.Reset();
BillingLine.SetFilter(Partner, PartnerFilter);
BillingLine.SetRange("Document Type", Enum::"Rec. Billing Document Type"::None);
if CreateContractInvoice then
BillingLine.SetRange("Billing Template Code", '');
CreateBillingDocuments(BillingLine);
if ShowNotification and (not CreateContractInvoice) then
ShowFiltersIgnoredNotification();
end;

local procedure CreateBillingDocuments(var BillingLine: Record "Billing Line")
Expand Down Expand Up @@ -1036,17 +1028,6 @@ codeunit 8060 "Create Billing Documents"
OnAfterIsNewHeaderNeededPerContract(CreateNewHeader, TempBillingLine, PreviousSubContractNo);
end;

local procedure ShowFiltersIgnoredNotification()
var
FiltersIgnoredNotification: Notification;
FiltersIgnoredMsg: Label 'You have set filters on the Recurring Billing page. The filters were ignored to maintain data consistency.';
begin
FiltersIgnoredNotification.Message(FiltersIgnoredMsg);
FiltersIgnoredNotification.Scope := NotificationScope::LocalScope;
FiltersIgnoredNotification.Send();
end;


internal procedure ErrorIfItemUnitOfMeasureCodeDoesNotExist(ItemNo: Code[20]; ServiceObject: Record "Subscription Header")
var
ItemUnitOfMeasure: Record "Item Unit of Measure";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ codeunit 139688 "Recurring Billing Test"
RecurringBillingPage: TestPage "Recurring Billing";
IsPartnerVendor: Boolean;
PostDocuments: Boolean;
DocumentNoShouldBeEmptyErr: Label 'Document No. should be empty for the first contract';

#region Tests

Expand Down Expand Up @@ -1451,6 +1452,32 @@ codeunit 139688 "Recurring Billing Test"
Assert.AreEqual("Sales Document Type"::"Credit Memo", BillingLine.GetSalesDocumentTypeForContractNo(), 'Sales Document Type is not calculated correctly for Credit Memo.');
end;

[Test]
[HandlerFunctions('CreateBillingDocsCustomerPageHandlerwithoutPost,ExchangeRateSelectionModalPageHandler,MessageHandler,BillingTemplateModalPageHandler')]
procedure CreateCustomerDocumentForSelectedContract()
begin
// [SCENARIO] otherwise, all billing lines will not be included in the document which will lead to wrong invoices and corrupted billing lines
Initialize();

// [GIVEN] Create Recurring Billing Page setup for Customer
RecurringBillingPageSetupForCustomer();

// [WHEN] Filter billing lines to exclude the last line and create/post documents
RecurringBillingPage.OpenEdit();
RecurringBillingPage.BillingTemplateField.Lookup();
PostDocuments := true;
RecurringBillingPage.CreateBillingProposalAction.Invoke();
RecurringBillingPage.Filter.SetFilter("Subscription Contract No.", CustomerContract2."No.");
RecurringBillingPage.CreateDocuments.Invoke();
Commit();

// [THEN] Only billing lines for the selected contract should be Created document.
BillingLine.Reset();
BillingLine.SetRange("Subscription Contract No.", CustomerContract."No.");
BillingLine.FindLast();
Assert.AreEqual('', BillingLine."Document No.", DocumentNoShouldBeEmptyErr);
end;

#endregion Tests

#region Procedures
Expand Down Expand Up @@ -1808,6 +1835,12 @@ codeunit 139688 "Recurring Billing Test"
ExchangeRateSelectionPage.OK().Invoke();
end;

[ModalPageHandler]
procedure CreateBillingDocsCustomerPageHandlerwithoutPost(var CreateBillingDocsCustomerPage: TestPage "Create Customer Billing Docs")
begin
CreateBillingDocsCustomerPage.OK().Invoke();
end;

[MessageHandler]
procedure MessageHandler(Message: Text[1024])
begin
Expand Down