Skip to content

Commit

Permalink
Merge PR #117 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by max3903
  • Loading branch information
OCA-git-bot committed Jun 24, 2024
2 parents b2f1b56 + 76a8fa5 commit 57e65b5
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions l10n_us_account_routing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions l10n_us_account_routing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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"]},
}
1 change: 1 addition & 0 deletions l10n_us_account_routing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_bank
29 changes: 29 additions & 0 deletions l10n_us_account_routing/models/res_bank.py
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions l10n_us_account_routing/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Thiago Mulero <[email protected]>
1 change: 1 addition & 0 deletions l10n_us_account_routing/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The banks now can have one validate routing number
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions l10n_us_account_routing/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_routing_number_bank
60 changes: 60 additions & 0 deletions l10n_us_account_routing/tests/test_routing_number_bank.py
Original file line number Diff line number Diff line change
@@ -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,
)
13 changes: 13 additions & 0 deletions l10n_us_account_routing/views/res_bank.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_res_bank_form_routing" model="ir.ui.view">
<field name="name">Bank Routing Transit Number</field>
<field name="model">res.bank</field>
<field name="inherit_id" ref="base.view_res_bank_form" />
<field name="arch" type="xml">
<field name="bic" position="after">
<field name="routing_number" />
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/l10n_us_account_routing/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 57e65b5

Please sign in to comment.