@@ -1047,6 +1047,36 @@ func TestPrepaymentEndToEnd(t *testing.T) {
10471047 assert .Equal (t , cbc .Code ("ZAL-001" ), inv .Preceding [0 ].Code )
10481048 })
10491049
1050+ t .Run ("KOR_ZAL inverts negative totals for credit note" , func (t * testing.T ) {
1051+ doc := testPrepaymentDoc ()
1052+ doc .Inv .InvoiceType = "KOR_ZAL"
1053+ doc .Inv .CorrectedInv = []* ksef.CorrectedInv {
1054+ {SequentialNumber : "ZAL-001" , IssueDate : "2026-01-15" },
1055+ }
1056+ // KSeF credit notes have negative P_13/P_14/P_15 values
1057+ doc .Inv .StandardRateNetSale = "-1000.00"
1058+ doc .Inv .StandardRateTax = "-230.00"
1059+ doc .Inv .TotalAmountDue = "-1230.00"
1060+
1061+ inv , err := doc .ToGOBL ()
1062+ require .NoError (t , err )
1063+
1064+ assert .True (t , inv .HasTags (tax .TagBypass ))
1065+ assert .Equal (t , bill .InvoiceTypeCreditNote , inv .Type )
1066+
1067+ // Totals should be positive (GOBL convention)
1068+ assert .Equal (t , "1000.00" , inv .Totals .Sum .String ())
1069+ assert .Equal (t , "230.00" , inv .Totals .Tax .String ())
1070+ assert .Equal (t , "1230.00" , inv .Totals .TotalWithTax .String ())
1071+ assert .Equal (t , "1230.00" , inv .Totals .Payable .String ())
1072+
1073+ // Tax rate amounts should also be positive
1074+ require .NotNil (t , inv .Totals .Taxes )
1075+ rate := inv .Totals .Taxes .Categories [0 ].Rates [0 ]
1076+ assert .Equal (t , "1000.00" , rate .Base .String ())
1077+ assert .Equal (t , "230.00" , rate .Amount .String ())
1078+ })
1079+
10501080 t .Run ("zero rate prepayment sets correct totals" , func (t * testing.T ) {
10511081 doc := testPrepaymentDoc ()
10521082 doc .Inv .StandardRateNetSale = ""
0 commit comments