-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by max3903
- Loading branch information
Showing
13 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_bank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Thiago Mulero <thiago.mulero@forgeflow.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_routing_number_bank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/l10n_us_account_routing/odoo/addons/l10n_us_account_routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../l10n_us_account_routing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |