diff --git a/l10n_us_account_routing/README.rst b/l10n_us_account_routing/README.rst new file mode 100644 index 00000000..e69de29b diff --git a/l10n_us_account_routing/__init__.py b/l10n_us_account_routing/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/l10n_us_account_routing/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/l10n_us_account_routing/__manifest__.py b/l10n_us_account_routing/__manifest__.py new file mode 100644 index 00000000..e5fc87c8 --- /dev/null +++ b/l10n_us_account_routing/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Bank Routing Numbers", + "version": "16.0.1.0.0", + "category": "Banking addons", + "summary": "Add the routing numbers to the banks", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/l10n-usa", + "depends": ["base"], + "data": ["views/res_bank.xml"], + "installable": True, + "license": "LGPL-3", + "external_dependencies": {"python": ["python-stdnum"]}, +} diff --git a/l10n_us_account_routing/models/__init__.py b/l10n_us_account_routing/models/__init__.py new file mode 100644 index 00000000..6c600d3f --- /dev/null +++ b/l10n_us_account_routing/models/__init__.py @@ -0,0 +1 @@ +from . import res_bank diff --git a/l10n_us_account_routing/models/res_bank.py b/l10n_us_account_routing/models/res_bank.py new file mode 100644 index 00000000..988b96f1 --- /dev/null +++ b/l10n_us_account_routing/models/res_bank.py @@ -0,0 +1,29 @@ +from stdnum.us import rtn + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ResBank(models.Model): + _inherit = "res.bank" + + routing_number = fields.Char() + + @api.constrains("routing_number") + def validate_routing_number(self): + if not self.routing_number or not self.country: + return + country_code = self.country.code + if country_code == "US": + try: + rtn.validate(self.routing_number) + except Exception: + raise ValidationError( + _("%s is not a valid US routing number!") % self.routing_number + ) from None + elif country_code == "CA": + if len(self.routing_number) != 8 or not self.routing_number.isdigit(): + raise ValidationError( + _("%s is not a valid Canadian routing number!") + % self.routing_number + ) diff --git a/l10n_us_account_routing/readme/CONTRIBUTORS.rst b/l10n_us_account_routing/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..f896b2f2 --- /dev/null +++ b/l10n_us_account_routing/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Thiago Mulero diff --git a/l10n_us_account_routing/readme/DESCRIPTION.rst b/l10n_us_account_routing/readme/DESCRIPTION.rst new file mode 100644 index 00000000..5e8540f4 --- /dev/null +++ b/l10n_us_account_routing/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +The banks now can have one validate routing number diff --git a/l10n_us_account_routing/static/description/icon.png b/l10n_us_account_routing/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/l10n_us_account_routing/static/description/icon.png differ diff --git a/l10n_us_account_routing/tests/__init__.py b/l10n_us_account_routing/tests/__init__.py new file mode 100644 index 00000000..b8dff629 --- /dev/null +++ b/l10n_us_account_routing/tests/__init__.py @@ -0,0 +1 @@ +from . import test_routing_number_bank diff --git a/l10n_us_account_routing/tests/test_routing_number_bank.py b/l10n_us_account_routing/tests/test_routing_number_bank.py new file mode 100644 index 00000000..534c65fb --- /dev/null +++ b/l10n_us_account_routing/tests/test_routing_number_bank.py @@ -0,0 +1,60 @@ +from odoo.exceptions import ValidationError +from odoo.tests import TransactionCase + + +class TestResBank(TransactionCase): + def setUp(self): + super(TestResBank, self).setUp() + self.us_bank = self.env["res.bank"].create( + { + "name": "US Bank", + "country": self.env["res.country"].search([("code", "=", "US")]).id, + } + ) + + self.canadian_bank = self.env["res.bank"].create( + { + "name": "Canadian Bank", + "country": self.env["res.country"].search([("code", "=", "CA")]).id, + } + ) + + self.belgium_bank = self.env["res.bank"].create( + { + "name": "Belgium Bank", + "country": self.env["res.country"].search([("code", "=", "BE")]).id, + } + ) + + def test_routing_number_us_bank(self): + number = self.us_bank.routing_number = 310033974 + self.assertEqual( + number, + 310033974, + "You should have the routing number 310033974 for the bank %s" + % self.us_bank.name, + ) + # We want to test the exception + with self.assertRaises(ValidationError): + self.us_bank.routing_number = 1 + + def test_routing_number_canadian_bank(self): + number = self.canadian_bank.routing_number = 12162004 + self.assertEqual( + number, + 12162004, + "You should have the routing number 12162004 for the bank %s" + % self.canadian_bank.name, + ) + # We want to test the exception + with self.assertRaises(ValidationError): + self.canadian_bank.routing_number = 1 + + def test_routing_number_belgium_bank(self): + number = self.belgium_bank.routing_number = 5 + self.assertEqual( + number, + 5, + "You should have the routing number 5 for the bank %s" + % self.belgium_bank.name, + ) diff --git a/l10n_us_account_routing/views/res_bank.xml b/l10n_us_account_routing/views/res_bank.xml new file mode 100644 index 00000000..31a9d2eb --- /dev/null +++ b/l10n_us_account_routing/views/res_bank.xml @@ -0,0 +1,13 @@ + + + + Bank Routing Transit Number + res.bank + + + + + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..f8f07db7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +python-stdnum diff --git a/setup/l10n_us_account_routing/odoo/addons/l10n_us_account_routing b/setup/l10n_us_account_routing/odoo/addons/l10n_us_account_routing new file mode 120000 index 00000000..1d6c2a0d --- /dev/null +++ b/setup/l10n_us_account_routing/odoo/addons/l10n_us_account_routing @@ -0,0 +1 @@ +../../../../l10n_us_account_routing \ No newline at end of file diff --git a/setup/l10n_us_account_routing/setup.py b/setup/l10n_us_account_routing/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/l10n_us_account_routing/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)