Skip to content
Merged
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
26 changes: 14 additions & 12 deletions src/Layers/AU/Tests/VAT/NonDeductiblePurchPosting.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ codeunit 134283 "Non-Deductible Purch. Posting"
end;

[Test]
procedure CombinedVATAmountLineForTwoPurchLineFirstNonDedVATSecondNormalVAT()
procedure SeparateVATAmountLinesForTwoPurchLineFirstNonDedVATSecondNormalVAT()
var
VATPostingSetup: Record "VAT Posting Setup";
VATProductPostingGroup: Record "VAT Product Posting Group";
Expand All @@ -140,23 +140,22 @@ codeunit 134283 "Non-Deductible Purch. Posting"
Currency: Record Currency;
PurchPost: Codeunit "Purch.-Post";
TotalVATAmount: Decimal;
VATIdentifier: Code[20];
NonDedVATIdentifier: Code[20];
begin
// [SCENARIO 456471] Combine VAT amount line from two purchase lines (first has Non-Deductible VAT, second is not) has correct Non-Deductible VAT Base and Non-Deductible VAT Amount

// [SCENARIO 456471] Separate VAT amount lines from two purchase lines (first has Non-Deductible VAT, second is not) have correct Non-Deductible VAT Base and Non-Deductible VAT Amount
Initialize();
LibraryNonDeductibleVAT.CreateNonDeductibleNormalVATPostingSetup(VATPostingSetup);
VATIdentifier := VATPostingSetup."VAT Identifier";
NonDedVATIdentifier := VATPostingSetup."VAT Identifier";
LibraryPurchase.CreatePurchHeader(
PurchHeader, PurchHeader."Document Type"::Invoice,
LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group"));
CreatePurchLineItemWithVATProdPostingGroup(NonDedPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");

LibraryERM.CreateVATProductPostingGroup(VATProductPostingGroup);
LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Bus. Posting Group", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Identifier", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
VATPostingSetup.Validate("VAT %", LibraryRandom.RandIntInRange(10, 20));
VATPostingSetup.Validate("VAT Identifier", VATIdentifier);
VATPostingSetup.Modify(true);

CreatePurchLineItemWithVATProdPostingGroup(NormalPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");
Expand All @@ -168,12 +167,15 @@ codeunit 134283 "Non-Deductible Purch. Posting"
TotalVATAmount, Currency, LibraryRandom.RandIntInRange(10, 50), false, 0, '', true, WorkDate());

// [THEN]
Assert.RecordCount(TempVATAmountLine, 1);
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Base"), Format(0));
ClearLastError();
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Amount"), Format(0));
Assert.RecordCount(TempVATAmountLine, 2);
TempVATAmountLine.SetRange("VAT Identifier", NonDedVATIdentifier);
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
TempVATAmountLine.SetRange("VAT Identifier", VATPostingSetup."VAT Identifier");
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", 0);
TempVATAmountLine.TestField("Non-Deductible VAT Amount", 0);
end;

[Test]
Expand Down
51 changes: 51 additions & 0 deletions src/Layers/CZ/Tests/VAT/NonDeductiblePurchPosting.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,57 @@ codeunit 134283 "Non-Deductible Purch. Posting"
GLEntry.TestField("Non-Deductible VAT Amount", NonDeductibleVATAmount);
end;

[Test]
procedure SeparateVATAmountLinesForTwoPurchLineFirstNonDedVATSecondNormalVAT()
var
VATPostingSetup: Record "VAT Posting Setup";
VATProductPostingGroup: Record "VAT Product Posting Group";
PurchHeader: Record "Purchase Header";
NonDedPurchLine: Record "Purchase Line";
NormalPurchLine: Record "Purchase Line";
TempPurchLine: Record "Purchase Line" temporary;
TempVATAmountLine: Record "VAT Amount Line" temporary;
Currency: Record Currency;
PurchPost: Codeunit "Purch.-Post";
TotalVATAmount: Decimal;
NonDedVATIdentifier: Code[20];
begin
// [SCENARIO 456471] Separate VAT amount lines from two purchase lines (first has Non-Deductible VAT, second is not) have correct Non-Deductible VAT Base and Non-Deductible VAT Amount
Initialize();
LibraryNonDeductibleVAT.CreateNonDeductibleNormalVATPostingSetup(VATPostingSetup);
NonDedVATIdentifier := VATPostingSetup."VAT Identifier";
LibraryPurchase.CreatePurchHeader(
PurchHeader, PurchHeader."Document Type"::Invoice,
LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group"));
CreatePurchLineItemWithVATProdPostingGroup(NonDedPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");

LibraryERM.CreateVATProductPostingGroup(VATProductPostingGroup);
LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Bus. Posting Group", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Identifier", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
VATPostingSetup.Validate("VAT %", LibraryRandom.RandIntInRange(10, 20));
VATPostingSetup.Modify(true);

CreatePurchLineItemWithVATProdPostingGroup(NormalPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");
PurchPost.GetPurchLines(PurchHeader, TempPurchLine, 0);
NormalPurchLine.CalcVATAmountLines(0, PurchHeader, TempPurchLine, TempVATAmountLine);

// [WHEN]
TempVATAmountLine.UpdateLines(
TotalVATAmount, Currency, LibraryRandom.RandIntInRange(10, 50), false, 0, '', true, WorkDate());

// [THEN]
Assert.RecordCount(TempVATAmountLine, 2);
TempVATAmountLine.SetRange("VAT Identifier", NonDedVATIdentifier);
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
TempVATAmountLine.SetRange("VAT Identifier", VATPostingSetup."VAT Identifier");
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", 0);
TempVATAmountLine.TestField("Non-Deductible VAT Amount", 0);
end;

[Test]
procedure PurchInvoiceWithPrepayment()
var
Expand Down
4 changes: 4 additions & 0 deletions src/Layers/IT/Tests/VAT/NonDedVATMisc.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,8 @@ codeunit 134284 "Non Ded. VAT Misc."
begin
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATCalculationType);
DeductiblePercent := GetDeductibleVATPctFromVATPostingSetup(VATPostingSetup);
VATPostingSetup.Validate(
"VAT Identifier", LibraryUtility.GenerateRandomCode(VATPostingSetup.FieldNo("VAT Identifier"), Database::"VAT Posting Setup"));
LibraryERM.CreateGLAccount(GLAccount);
AssignNonDeductibleVATAccount(VATPostingSetup, GLAccount."No.");
AssignDeductibleVATPct(VATPostingSetup, LibraryRandom.RandInt(99));
Expand Down Expand Up @@ -1628,6 +1630,8 @@ codeunit 134284 "Non Ded. VAT Misc."
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATCalcType);
DeductiblePercent := GetDeductibleVATPctFromVATPostingSetup(VATPostingSetup);
NonDeductGLAccountNo := VATPostingSetup."Non-Ded. Purchase VAT Account";
VATPostingSetup.Validate(
"VAT Identifier", LibraryUtility.GenerateRandomCode(VATPostingSetup.FieldNo("VAT Identifier"), Database::"VAT Posting Setup"));
AssignNonDeductibleVATAccount(VATPostingSetup, '');
AssignDeductibleVATPct(VATPostingSetup, 0);
VATPostingSetup.Modify(true);
Expand Down
25 changes: 13 additions & 12 deletions src/Layers/IT/Tests/VAT/NonDeductiblePurchPosting.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ codeunit 134283 "Non-Deductible Purch. Posting"
end;

[Test]
procedure CombinedVATAmountLineForTwoPurchLineFirstNonDedVATSecondNormalVAT()
procedure SeparateVATAmountLinesForTwoPurchLineFirstNonDedVATSecondNormalVAT()
var
VATPostingSetup: Record "VAT Posting Setup";
VATProductPostingGroup: Record "VAT Product Posting Group";
Expand All @@ -140,13 +140,12 @@ codeunit 134283 "Non-Deductible Purch. Posting"
Currency: Record Currency;
PurchPost: Codeunit "Purch.-Post";
TotalVATAmount: Decimal;
VATIdentifier: Code[20];
NonDedVATIdentifier: Code[20];
begin
// [SCENARIO 456471] Combine VAT amount line from two purchase lines (first has Non-Deductible VAT, second is not) has correct Non-Deductible VAT Base and Non-Deductible VAT Amount

// [SCENARIO 456471] Separate VAT amount lines from two purchase lines (first has Non-Deductible VAT, second is not) have correct Non-Deductible VAT Base and Non-Deductible VAT Amount
Initialize();
LibraryNonDeductibleVAT.CreateNonDeductibleNormalVATPostingSetup(VATPostingSetup);
VATIdentifier := VATPostingSetup."VAT Identifier";
NonDedVATIdentifier := VATPostingSetup."VAT Identifier";
LibraryPurchase.CreatePurchHeader(
PurchHeader, PurchHeader."Document Type"::Invoice,
LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group"));
Expand All @@ -156,7 +155,6 @@ codeunit 134283 "Non-Deductible Purch. Posting"
LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Bus. Posting Group", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
VATPostingSetup.Validate("VAT %", LibraryRandom.RandIntInRange(10, 20));
VATPostingSetup.Validate("VAT Identifier", VATIdentifier);
VATPostingSetup.Modify(true);

CreatePurchLineItemWithVATProdPostingGroup(NormalPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");
Expand All @@ -168,12 +166,15 @@ codeunit 134283 "Non-Deductible Purch. Posting"
TotalVATAmount, Currency, LibraryRandom.RandIntInRange(10, 50), false, 0, '', true, WorkDate());

// [THEN]
Assert.RecordCount(TempVATAmountLine, 1);
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Base"), Format(0));
ClearLastError();
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Amount"), Format(0));
Assert.RecordCount(TempVATAmountLine, 2);
TempVATAmountLine.SetRange("VAT Identifier", NonDedVATIdentifier);
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
TempVATAmountLine.SetRange("VAT Identifier", VATPostingSetup."VAT Identifier");
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", 0);
TempVATAmountLine.TestField("Non-Deductible VAT Amount", 0);
end;

[Test]
Expand Down
26 changes: 14 additions & 12 deletions src/Layers/RU/Tests/VAT/NonDeductiblePurchPosting.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ codeunit 134283 "Non-Deductible Purch. Posting"
end;

[Test]
procedure CombinedVATAmountLineForTwoPurchLineFirstNonDedVATSecondNormalVAT()
procedure SeparateVATAmountLinesForTwoPurchLineFirstNonDedVATSecondNormalVAT()
var
VATPostingSetup: Record "VAT Posting Setup";
VATProductPostingGroup: Record "VAT Product Posting Group";
Expand All @@ -140,23 +140,22 @@ codeunit 134283 "Non-Deductible Purch. Posting"
Currency: Record Currency;
PurchPost: Codeunit "Purch.-Post";
TotalVATAmount: Decimal;
VATIdentifier: Code[20];
NonDedVATIdentifier: Code[20];
begin
// [SCENARIO 456471] Combine VAT amount line from two purchase lines (first has Non-Deductible VAT, second is not) has correct Non-Deductible VAT Base and Non-Deductible VAT Amount

// [SCENARIO 456471] Separate VAT amount lines from two purchase lines (first has Non-Deductible VAT, second is not) have correct Non-Deductible VAT Base and Non-Deductible VAT Amount
Initialize();
LibraryNonDeductibleVAT.CreateNonDeductibleNormalVATPostingSetup(VATPostingSetup);
VATIdentifier := VATPostingSetup."VAT Identifier";
NonDedVATIdentifier := VATPostingSetup."VAT Identifier";
LibraryPurchase.CreatePurchHeader(
PurchHeader, PurchHeader."Document Type"::Invoice,
LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group"));
CreatePurchLineItemWithVATProdPostingGroup(NonDedPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");

LibraryERM.CreateVATProductPostingGroup(VATProductPostingGroup);
LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Bus. Posting Group", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Identifier", VATProductPostingGroup.Code);
VATPostingSetup.Validate("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT");
VATPostingSetup.Validate("VAT %", LibraryRandom.RandIntInRange(10, 20));
VATPostingSetup.Validate("VAT Identifier", VATIdentifier);
VATPostingSetup.Modify(true);

CreatePurchLineItemWithVATProdPostingGroup(NormalPurchLine, PurchHeader, VATPostingSetup."VAT Prod. Posting Group");
Expand All @@ -168,12 +167,15 @@ codeunit 134283 "Non-Deductible Purch. Posting"
TotalVATAmount, Currency, LibraryRandom.RandIntInRange(10, 50), false, 0, '', true, WorkDate(), false);

// [THEN]
Assert.RecordCount(TempVATAmountLine, 1);
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Base"), Format(0));
ClearLastError();
asserterror TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
Assert.ExpectedTestFieldError(NonDedPurchLine.FieldCaption("Non-Deductible VAT Amount"), Format(0));
Assert.RecordCount(TempVATAmountLine, 2);
TempVATAmountLine.SetRange("VAT Identifier", NonDedVATIdentifier);
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", NonDedPurchLine."Non-Deductible VAT Base");
TempVATAmountLine.TestField("Non-Deductible VAT Amount", NonDedPurchLine."Non-Deductible VAT Amount");
TempVATAmountLine.SetRange("VAT Identifier", VATPostingSetup."VAT Identifier");
TempVATAmountLine.FindFirst();
TempVATAmountLine.TestField("Non-Deductible VAT Base", 0);
TempVATAmountLine.TestField("Non-Deductible VAT Amount", 0);
end;

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,6 @@ codeunit 6201 "Non-Ded. VAT Impl."
if IsHandled then
exit;

if PurchaseLine."Non-Deductible VAT %" = 0 then
exit;
PurchaseLine.SetRange("Document Type", PurchaseLine."Document Type");
PurchaseLine.SetRange("Document No.", PurchaseLine."Document No.");
PurchaseLine.SetFilter("Line No.", '<>%1', PurchaseLine."Line No.");
Expand Down
4 changes: 4 additions & 0 deletions src/Layers/W1/Tests/VAT/NonDedVATMisc.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,8 @@ codeunit 134284 "Non Ded. VAT Misc."
begin
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATCalculationType);
DeductiblePercent := GetDeductibleVATPctFromVATPostingSetup(VATPostingSetup);
VATPostingSetup.Validate(
"VAT Identifier", LibraryUtility.GenerateRandomCode(VATPostingSetup.FieldNo("VAT Identifier"), Database::"VAT Posting Setup"));
LibraryERM.CreateGLAccount(GLAccount);
AssignNonDeductibleVATAccount(VATPostingSetup, GLAccount."No.");
AssignDeductibleVATPct(VATPostingSetup, LibraryRandom.RandInt(99));
Expand Down Expand Up @@ -1682,6 +1684,8 @@ codeunit 134284 "Non Ded. VAT Misc."
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATCalcType);
DeductiblePercent := GetDeductibleVATPctFromVATPostingSetup(VATPostingSetup);
NonDeductGLAccountNo := VATPostingSetup."Non-Ded. Purchase VAT Account";
VATPostingSetup.Validate(
"VAT Identifier", LibraryUtility.GenerateRandomCode(VATPostingSetup.FieldNo("VAT Identifier"), Database::"VAT Posting Setup"));
AssignNonDeductibleVATAccount(VATPostingSetup, '');
AssignDeductibleVATPct(VATPostingSetup, 0);
VATPostingSetup.Modify(true);
Expand Down
Loading
Loading