From 43ffafae29f73ca87e56f154744f22472d5e90fc Mon Sep 17 00:00:00 2001 From: Hardik Suthar Date: Mon, 19 Dec 2022 18:23:26 +0530 Subject: [PATCH] [16.0][MIG] account_banking_ach_base [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 --- account_banking_ach_base/__manifest__.py | 2 +- account_banking_ach_base/models/__init__.py | 1 + .../models/account_banking_mandate.py | 3 +- .../models/account_move.py | 8 +-- .../models/account_payment_method.py | 16 +++++ .../models/account_payment_order.py | 65 ++++++++----------- account_banking_ach_base/models/res_bank.py | 10 ++- .../views/account_move.xml | 2 +- requirements.txt | 3 + 9 files changed, 59 insertions(+), 51 deletions(-) create mode 100644 account_banking_ach_base/models/account_payment_method.py create mode 100644 requirements.txt diff --git a/account_banking_ach_base/__manifest__.py b/account_banking_ach_base/__manifest__.py index bf02663b..9c9abbe6 100644 --- a/account_banking_ach_base/__manifest__.py +++ b/account_banking_ach_base/__manifest__.py @@ -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", diff --git a/account_banking_ach_base/models/__init__.py b/account_banking_ach_base/models/__init__.py index f3f79834..73f08acf 100644 --- a/account_banking_ach_base/models/__init__.py +++ b/account_banking_ach_base/models/__init__.py @@ -5,3 +5,4 @@ from . import account_payment_order from . import res_bank from . import res_company +from . import account_payment_method diff --git a/account_banking_ach_base/models/account_banking_mandate.py b/account_banking_ach_base/models/account_banking_mandate.py index 59bd0417..e12148d0 100644 --- a/account_banking_ach_base/models/account_banking_mandate.py +++ b/account_banking_ach_base/models/account_banking_mandate.py @@ -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 @@ -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): """ diff --git a/account_banking_ach_base/models/account_move.py b/account_banking_ach_base/models/account_move.py index d7fb0d92..be44eaea 100644 --- a/account_banking_ach_base/models/account_move.py +++ b/account_banking_ach_base/models/account_move.py @@ -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() diff --git a/account_banking_ach_base/models/account_payment_method.py b/account_banking_ach_base/models/account_payment_method.py new file mode 100644 index 00000000..d6c13bde --- /dev/null +++ b/account_banking_ach_base/models/account_payment_method.py @@ -0,0 +1,16 @@ +# Copyright 2016-2020 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# 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 diff --git a/account_banking_ach_base/models/account_payment_order.py b/account_banking_ach_base/models/account_payment_order.py index 3c4d4ec2..8ee2b416 100644 --- a/account_banking_ach_base/models/account_payment_order.py +++ b/account_banking_ach_base/models/account_payment_order.py @@ -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, @@ -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): @@ -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): @@ -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.communication) 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" diff --git a/account_banking_ach_base/models/res_bank.py b/account_banking_ach_base/models/res_bank.py index 7175aa2c..76d4aeb2 100644 --- a/account_banking_ach_base/models/res_bank.py +++ b/account_banking_ach_base/models/res_bank.py @@ -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): @@ -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 ) diff --git a/account_banking_ach_base/views/account_move.xml b/account_banking_ach_base/views/account_move.xml index bddbda40..994cf91d 100644 --- a/account_banking_ach_base/views/account_move.xml +++ b/account_banking_ach_base/views/account_move.xml @@ -5,7 +5,7 @@ account.move - +