Skip to content

Commit

Permalink
[16.0][MIG] account_banking_ach_base
Browse files Browse the repository at this point in the history
[FIX] account_banking_ach_base: use the payment_ids field instead of bank_line_ids

Applies same fix as #101

amount_currency no longer available in 16 (Changed to amount)

communicaton field no longer available in 16 (Changed to ref)
  • Loading branch information
Hardik-OSI authored and JasminSForgeFlow committed Jun 25, 2024
1 parent 8e6181c commit 35258f9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion account_banking_ach_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Localizations for North American Banking & Financials",
"summary": "Add fields required for North American Banking & Financials",
"version": "14.0.1.0.1",
"version": "16.0.1.0.1",
"license": "AGPL-3",
"author": "Thinkwell Designs, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-usa",
Expand Down
1 change: 1 addition & 0 deletions account_banking_ach_base/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import account_payment_order
from . import res_bank
from . import res_company
from . import account_payment_method
3 changes: 1 addition & 2 deletions account_banking_ach_base/models/account_banking_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class AccountBankingMandate(models.Model):
_inherit = "account.banking.mandate"

delay_days = fields.Integer(
string="Delay Days",
required=True,
default=10,
help="""Number of days to wait after invoice
Expand All @@ -20,7 +19,7 @@ def validate(self):
raise UserError(
_("""Delay days must be specified, and greater than 0.""")
)
super(AccountBankingMandate, self).validate()
return super(AccountBankingMandate, self).validate()

def set_payment_modes_on_partner(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions account_banking_ach_base/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def create_account_payment_line(self):
if today < delay_expired:
raise UserError(
_(
"To satisfy payment mandate, cannot add invoice %s to "
"Debit Order until %s!"
% (invoice.name, delay_expired.strftime("%Y-%m-%d"))
)
"To satisfy payment mandate, cannot add invoice %(name)s to Debit Order until %(delay_expired)s!"
),
name=invoice.name,
delay_expired=delay_expired.strftime("%Y-%m-%d"),
)
return super(AccountMove, self).create_account_payment_line()
16 changes: 16 additions & 0 deletions account_banking_ach_base/models/account_payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2016-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountPaymentMethod(models.Model):
_inherit = "account.payment.method"

@api.model
def _get_payment_method_information(self):
res = super()._get_payment_method_information()
res['ACH-In'] = {'mode': 'multi', 'domain': [('type', '=', 'bank')]}
res['ACH-Out'] = {'mode': 'multi', 'domain': [('type', '=', 'bank')]}
return res
65 changes: 28 additions & 37 deletions account_banking_ach_base/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ def ach_settings(self):
legal_id_number = self.company_id.legal_id_number
if not legal_id_number:
raise UserError(
_(
"%s does not have an EIN / SSN / BN "
"assigned!" % self.company_id.name
)
_("%s does not have an EIN / SSN / BN assigned!") % self.company_id.name
)

if not routing_number:
raise UserError(
_("%s does not have a Routing Number assigned!" % bank.name)
_("%s does not have a Routing Number assigned!") % bank.name
)
return {
"immediate_dest": self.company_partner_bank_id.acc_number,
Expand All @@ -62,18 +59,14 @@ def ach_settings(self):
def validate_banking(self, line):
if not line.partner_bank_id.bank_id:
raise UserError(
_(
"%s account number has no Bank "
"assigned" % line.partner_bank_id.acc_number
)
_("%s account number has no Bank assigned")
% line.partner_bank_id.acc_number
)

if not line.partner_bank_id.bank_id.routing_number:
raise UserError(
_(
"%s has no routing number "
"specified" % line.partner_bank_id.bank_id.name
)
_("%s has no routing number specified")
% line.partner_bank_id.bank_id.name
)

def validate_mandates(self, line):
Expand All @@ -82,35 +75,32 @@ def validate_mandates(self, line):
raise UserError(
_(
"Missing ACH Direct Debit mandate on the "
"bank payment line with partner '%s' "
"(reference '%s')."
"payment line with partner %(name)s "
"(reference %(line_name)s).",
name=line.partner_id.name,
line_name=line.name,
)
% (line.partner_id.name, line.name)
)
if line.mandate_id.state != "valid":
raise Warning(
_(
"The ACH Direct Debit mandate with reference '%s' "
"for partner '%s' has expired."
)
% (
line.mandate_id.unique_mandate_reference,
line.mandate_id.partner_id.name,
)
"The ACH Direct Debit mandate with reference %(unique_mandate_reference)s "
"for partner %(name)s has expired."
),
unique_mandate_reference=line.mandate_id.unique_mandate_reference,
name=line.mandate_id.partner_id.name,
)
if line.mandate_id.type == "oneoff" and line.mandate_id.last_debit_date:
raise Warning(
_(
"The mandate with reference '%s' for partner "
"'%s' has type set to 'One-Off' and it has a "
"last debit date set to '%s', so we can't use "
"The mandate with reference %(unique_mandate_reference)s for partner "
"%(name)s has type set to 'One-Off' and it has a "
"last debit date set to %(last_debit_date)s, so we can't use "
"it."
)
% (
line.mandate_id.unique_mandate_reference,
line.mandate_id.partner_id.name,
line.mandate_id.last_debit_date,
)
),
unique_mandate_reference=line.mandate_id.unique_mandate_reference,
name=line.mandate_id.partner_id.name,
last_debit_date=line.mandate_id.last_debit_date,
)

def get_transaction_type(self, amount):
Expand Down Expand Up @@ -140,20 +130,21 @@ def generate_ach_file(self):
file_mod=file_mod,
)
entries = []
for line in self.bank_line_ids:
for line in self.payment_ids:
if inbound_payment:
self.validate_mandates(line)
self.validate_banking(line)
amount = line.amount_currency
partner_name = re.sub(r"[^\w ,]", "", line.partner_id.name)
amount = line.amount
name = re.sub("[^A-Za-z0-9]+", "", line.partner_id.name)
note = re.sub("[^A-Za-z0-9]+", "", line.ref)
entries.append(
{
"type": self.get_transaction_type(amount=amount),
"routing_number": line.partner_bank_id.bank_id.routing_number,
"account_number": line.partner_bank_id.acc_number,
"amount": str(amount),
"name": partner_name,
"addenda": [{"payment_related_info": line.communication}],
"name": name,
"addenda": [{"payment_related_info": note}],
}
)
outbound_payment = self.payment_type == "outbound"
Expand Down
10 changes: 4 additions & 6 deletions account_banking_ach_base/models/res_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ResBank(models.Model):
_inherit = "res.bank"

routing_number = fields.Char(string="Routing Number")
routing_number = fields.Char()

@api.constrains("routing_number")
def validate_routing_number(self):
Expand All @@ -19,13 +19,11 @@ def validate_routing_number(self):
rtn.validate(self.routing_number)
except Exception:
raise ValidationError(
_("%s is not a valid US routing number!" % self.routing_number)
_("%s is not a valid US routing number!") % self.routing_number
)
elif country_code == "CA":
if len(self.routing_number) != 8 or not self.routing_number.is_digit():
raise ValidationError(
_(
"%s is not a valid Canadian routing number!"
% self.routing_number
)
_("%s is not a valid Canadian routing number!")
% self.routing_number
)
2 changes: 1 addition & 1 deletion account_banking_ach_base/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter" />
<field name="arch" type="xml">
<filter name="unpaid" position="after">
<filter name="open" position="after">
<filter
name="payment_orders"
string="Ready for Payment Order"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# generated from manifests external_dependencies
ach
python-stdnum

0 comments on commit 35258f9

Please sign in to comment.