From 3db85dbd9c913feed05a3f38800550f4a519859e Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Fri, 5 May 2023 09:17:29 +0000 Subject: [PATCH] Ignoring VAT lines without a percent, sneakily removing (the) from country names --- l10n/countries.go | 74 +++++++++++++++++++++++----------------------- tax/totals.go | 3 +- tax/totals_test.go | 7 +++-- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/l10n/countries.go b/l10n/countries.go index 523bfd9a..29f9a445 100644 --- a/l10n/countries.go +++ b/l10n/countries.go @@ -270,10 +270,10 @@ var CountryDefinitions = []CountryDef{ {AR, "Argentina", "ar"}, {AM, "Armenia", "am"}, {AW, "Aruba", "aw"}, - {AU, "Australia ", "au"}, + {AU, "Australia", "au"}, {AT, "Austria", "at"}, {AZ, "Azerbaijan", "az"}, - {BS, "Bahamas (the)", "bs"}, + {BS, "Bahamas", "bs"}, {BH, "Bahrain", "bh"}, {BD, "Bangladesh", "bd"}, {BB, "Barbados", "bb"}, @@ -283,13 +283,13 @@ var CountryDefinitions = []CountryDef{ {BJ, "Benin", "bj"}, {BM, "Bermuda", "bm"}, {BT, "Bhutan", "bt"}, - {BO, "Bolivia (Plurinational State of)", "bo"}, + {BO, "Bolivia, Plurinational State of", "bo"}, {BQ, "Bonaire, Sint Eustatius and Saba", "bq"}, {BA, "Bosnia and Herzegovina", "ba"}, {BW, "Botswana", "bw"}, {BV, "Bouvet Island", "bv"}, {BR, "Brazil", "br"}, - {IO, "British Indian Ocean Territory (the)", "io"}, + {IO, "British Indian Ocean Territory", "io"}, {BN, "Brunei Darussalam", "bn"}, {BG, "Bulgaria", "bg"}, {BF, "Burkina Faso", "bf"}, @@ -298,18 +298,18 @@ var CountryDefinitions = []CountryDef{ {KH, "Cambodia", "kh"}, {CM, "Cameroon", "cm"}, {CA, "Canada", "ca"}, - {KY, "Cayman Islands (the)", "ky"}, - {CF, "Central African Republic (the)", "cf"}, + {KY, "Cayman Islands", "ky"}, + {CF, "Central African Republic", "cf"}, {TD, "Chad", "td"}, {CL, "Chile", "cl"}, {CN, "China", "cn"}, {CX, "Christmas Island", "cx"}, - {CC, "Cocos (Keeling) Islands (the)", "cc"}, + {CC, "Cocos (Keeling) Islands", "cc"}, {CO, "Colombia", "co"}, - {KM, "Comoros (the)", "km"}, - {CG, "Congo (the Democratic Republic of the)", "cd"}, - {CD, "Congo (the)", "cd"}, - {CK, "Cook Islands (the)", "ck"}, + {KM, "Comoros", "km"}, + {CG, "Congo", "cg"}, + {CD, "Congo, Democratic Republic of the", "cd"}, + {CK, "Cook Islands", "ck"}, {CR, "Costa Rica", "cr"}, {CI, "Côte d'Ivoire", "ci"}, {HR, "Croatia", "hr"}, @@ -320,7 +320,7 @@ var CountryDefinitions = []CountryDef{ {DK, "Denmark", "dk"}, {DJ, "Djibouti", "dj"}, {DM, "Dominica", "dm"}, - {DO, "Dominican Republic (the)", "do"}, + {DO, "Dominican Republic", "do"}, {EC, "Ecuador", "ec"}, {EG, "Egypt", "eg"}, {SV, "El Salvador", "sv"}, @@ -329,16 +329,16 @@ var CountryDefinitions = []CountryDef{ {EE, "Estonia", "ee"}, {SZ, "Eswatini", "sz"}, {ET, "Ethiopia", "et"}, - {FK, "Falkland Islands (the)", "fk"}, - {FO, "Faroe Islands (the)", "fo"}, + {FK, "Falkland Islands", "fk"}, + {FO, "Faroe Islands", "fo"}, {FJ, "Fiji", "fj"}, {FI, "Finland", "fi"}, {FR, "France", "fr"}, {GF, "French Guiana", "gf"}, {PF, "French Polynesia", "pf"}, - {TF, "French Southern Territories (the) ", "tf"}, + {TF, "French Southern Territories", "tf"}, {GA, "Gabon", "ga"}, - {GM, "Gambia (the)", "gm"}, + {GM, "Gambia", "gm"}, {GE, "Georgia", "ge"}, {DE, "Germany", "de"}, {GH, "Ghana", "gh"}, @@ -362,7 +362,7 @@ var CountryDefinitions = []CountryDef{ {IS, "Iceland", "is"}, {IN, "India", "in"}, {ID, "Indonesia", "id"}, - {IR, "Iran (Islamic Republic of)", "ir"}, + {IR, "Iran, Islamic Republic of", "ir"}, {IQ, "Iraq", "iq"}, {IE, "Ireland", "ie"}, {IM, "Isle of Man", "im"}, @@ -375,11 +375,11 @@ var CountryDefinitions = []CountryDef{ {KZ, "Kazakhstan", "kz"}, {KE, "Kenya", "ke"}, {KI, "Kiribati", "ki"}, - {KP, "Korea (the Democratic People's Republic of)", "kp"}, - {KR, "Korea (the Republic of)", "kr"}, + {KP, "Korea, Democratic People's Republic of", "kp"}, + {KR, "Korea, Republic of", "kr"}, {KW, "Kuwait", "kw"}, {KG, "Kyrgyzstan", "kg"}, - {LA, "Lao People's Democratic Republic (the)", "la"}, + {LA, "Lao People's Democratic Republic", "la"}, {LV, "Latvia", "lv"}, {LB, "Lebanon", "lb"}, {LS, "Lesotho", "ls"}, @@ -396,14 +396,14 @@ var CountryDefinitions = []CountryDef{ {MV, "Maldives", "mv"}, {ML, "Mali", "ml"}, {MT, "Malta", "mt"}, - {MH, "Marshall Islands (the)", "mh"}, + {MH, "Marshall Islands", "mh"}, {MQ, "Martinique", "mq"}, {MR, "Mauritania", "mr"}, {MU, "Mauritius", "mu"}, {YT, "Mayotte", "yt"}, {MX, "Mexico", "mx"}, - {FM, "Micronesia (Federated States of)", "fm"}, - {MD, "Moldova (the Republic of)", "md"}, + {FM, "Micronesia, Federated States of", "fm"}, + {MD, "Moldova, Republic of", "md"}, {MC, "Monaco", "mc"}, {MN, "Mongolia", "mn"}, {ME, "Montenegro", "me"}, @@ -414,15 +414,15 @@ var CountryDefinitions = []CountryDef{ {NA, "Namibia", "na"}, {NR, "Nauru", "nr"}, {NP, "Nepal", "np"}, - {NL, "Netherlands (the)", "nl"}, + {NL, "Netherlands", "nl"}, {NC, "New Caledonia", "nc"}, {NZ, "New Zealand", "nz"}, {NI, "Nicaragua", "ni"}, - {NE, "Niger (the)", "ne"}, + {NE, "Niger", "ne"}, {NG, "Nigeria", "ng"}, {NU, "Niue", "nu"}, {NF, "Norfolk Island", "nf"}, - {MP, "Northern Mariana Islands (the)", "mp"}, + {MP, "Northern Mariana Islands", "mp"}, {NO, "Norway", "no"}, {OM, "Oman", "om"}, {PK, "Pakistan", "pk"}, @@ -432,7 +432,7 @@ var CountryDefinitions = []CountryDef{ {PG, "Papua New Guinea", "pg"}, {PY, "Paraguay", "py"}, {PE, "Peru", "pe"}, - {PH, "Philippines (the)", "ph"}, + {PH, "Philippines", "ph"}, {PN, "Pitcairn", "pn"}, {PL, "Poland", "pl"}, {PT, "Portugal", "pt"}, @@ -440,7 +440,7 @@ var CountryDefinitions = []CountryDef{ {QA, "Qatar", "qa"}, {RE, "Réunion", "re"}, {RO, "Romania", "ro"}, - {RU, "Russian Federation (the)", "ru"}, + {RU, "Russian Federation", "ru"}, {RW, "Rwanda", "rw"}, {BL, "Saint Barthélemy", "bl"}, {SH, "Saint Helena, Ascension and Tristan da Cunha", "sh"}, @@ -468,17 +468,17 @@ var CountryDefinitions = []CountryDef{ {SS, "South Sudan", "ss"}, {ES, "Spain", "es"}, {LK, "Sri Lanka", "lk"}, - {SD, "Sudan (the)", "sd"}, + {SD, "Sudan", "sd"}, {SR, "Suriname", "sr"}, {SJ, "Svalbard and Jan Mayen", ""}, {SE, "Sweden", "se"}, {CH, "Switzerland", "ch"}, - {SY, "Syrian Arab Republic (the)", "sy"}, + {SY, "Syrian Arab Republic", "sy"}, {TW, "Taiwan (Province of China)", "tw"}, {TJ, "Tajikistan", "tj"}, {TZ, "Tanzania, the United Republic of", "tz"}, {TH, "Thailand", "th"}, - {TL, "Timor-Leste ", "tl"}, + {TL, "Timor-Leste", "tl"}, {TG, "Togo", "tg"}, {TK, "Tokelau", "tk"}, {TO, "Tonga", "to"}, @@ -486,18 +486,18 @@ var CountryDefinitions = []CountryDef{ {TN, "Tunisia", "tn"}, {TR, "Türkiye", "tr"}, {TM, "Turkmenistan", "tm"}, - {TC, "Turks and Caicos Islands (the)", "tc"}, + {TC, "Turks and Caicos Islands", "tc"}, {TV, "Tuvalu", "tv"}, {UG, "Uganda", "ug"}, {UA, "Ukraine", "ua"}, - {AE, "United Arab Emirates (the)", "ae"}, - {GB, "United Kingdom of Great Britain and Northern Ireland (the)", "uk"}, - {US, "United States of America (the)", "us"}, - {UM, "United States Minor Outlying Islands (the)", ""}, + {AE, "United Arab Emirates", "ae"}, + {GB, "United Kingdom", "uk"}, + {US, "United States of America", "us"}, + {UM, "United States Minor Outlying Islands", ""}, {UY, "Uruguay", "uy"}, {UZ, "Uzbekistan", "uz"}, {VU, "Vanuatu", "vu"}, - {VE, "Venezuela (Bolivarian Republic of)", "ve"}, + {VE, "Venezuela, Bolivarian Republic of", "ve"}, {VN, "Viet Nam", "vn"}, {VG, "Virgin Islands (British)", "vg"}, {VI, "Virgin Islands (U.S.)", "vi"}, diff --git a/tax/totals.go b/tax/totals.go index b657f6ba..05a78ea1 100644 --- a/tax/totals.go +++ b/tax/totals.go @@ -133,7 +133,8 @@ func (tc *TotalCalculator) Calculate(t *Total) error { return ErrInvalidPricesInclude.WithMessage("cannot include retained category '%s'", tc.Includes.String()) } if c.Percent == nil { - return ErrInvalidRate.WithMessage("missing '%s' percentage", tc.Includes.String()) + // can't work without a percent value, just skip + continue } // update the price scale, add two 0s, this will be removed later. diff --git a/tax/totals_test.go b/tax/totals_test.go index f1a6bb93..079f0d9c 100644 --- a/tax/totals_test.go +++ b/tax/totals_test.go @@ -766,14 +766,17 @@ func TestTotalCalculate(t *testing.T) { taxes: tax.Set{ { Category: common.TaxCategoryVAT, + Tags: []cbc.Key{"random"}, }, }, amount: num.MakeAmount(10000, 2), }, }, taxIncluded: common.TaxCategoryVAT, - err: tax.ErrInvalidRate, - errContent: "missing 'VAT' percentage", + want: &tax.Total{ + Categories: []*tax.CategoryTotal{}, + Sum: num.MakeAmount(0, 2), + }, }, }