Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] l10n_us_account_routing #117

Merged
merged 3 commits into from
Jun 24, 2024
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
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

Check warning on line 15 in l10n_us_account_routing/models/res_bank.py

View check run for this annotation

Codecov / codecov/patch

l10n_us_account_routing/models/res_bank.py#L15

Added line #L15 was not covered by tests
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>
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
python-stdnum
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,
)
Loading