From 0f5a5e058cba15f82a22be4d6a246821b5b940ef Mon Sep 17 00:00:00 2001 From: James Jesudason Date: Thu, 22 Mar 2012 12:07:57 +0000 Subject: [PATCH 1/4] [FIX] Payments from a Canadian bank account need the HSBC 6-digit sort-code number --- .../security/ir.model.access.csv | 2 +- account_banking_uk_hsbc/wizard/export_hsbc.py | 9 ++++---- account_banking_uk_hsbc/wizard/paymul.py | 21 ++++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/account_banking_uk_hsbc/security/ir.model.access.csv b/account_banking_uk_hsbc/security/ir.model.access.csv index 42495678f..2c7baa602 100644 --- a/account_banking_uk_hsbc/security/ir.model.access.csv +++ b/account_banking_uk_hsbc/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_banking_hsbc_clientid","banking.hsbc.clientid","model_banking_hsbc_clientid","account_payment.group_account_payment",1,1,1,1 - +"access_banking_export_hsbc","banking.export.hsbc","model_banking_export_hsbc","account_payment.group_account_payment",1,1,1,1 diff --git a/account_banking_uk_hsbc/wizard/export_hsbc.py b/account_banking_uk_hsbc/wizard/export_hsbc.py index 981355e01..57351807e 100644 --- a/account_banking_uk_hsbc/wizard/export_hsbc.py +++ b/account_banking_uk_hsbc/wizard/export_hsbc.py @@ -139,7 +139,7 @@ class banking_export_hsbc_wizard(osv.osv_memory): return super(banking_export_hsbc_wizard, self).create( cursor, uid, wizard_data, context) - def _create_account(self, oe_account): + def _create_account(self, oe_account, origin_country=None, is_origin_account=False): currency = None # let the receiving bank select the currency from the batch holder = oe_account.owner_name or oe_account.partner_id.name self.logger.info('Create account %s' % (holder)) @@ -191,7 +191,8 @@ class banking_export_hsbc_wizard(osv.osv_memory): currency=currency, swiftcode=oe_account.bank.bic, country=oe_account.country_id.code, - #origin_country=origin_country + origin_country=origin_country, + is_origin_account=is_origin_account ) transaction_kwargs = { 'charges': paymul.CHARGES_PAYEE, @@ -237,7 +238,7 @@ class banking_export_hsbc_wizard(osv.osv_memory): ) self.logger.info('====') - dest_account, transaction_kwargs = self._create_account(line.bank_id) + dest_account, transaction_kwargs = self._create_account(line.bank_id, line.order_id.mode.bank_id.country_id.code) means = {'ACH or EZONE': paymul.MEANS_ACH_OR_EZONE, 'Faster Payment': paymul.MEANS_FASTER_PAYMENT, @@ -278,7 +279,7 @@ class banking_export_hsbc_wizard(osv.osv_memory): try: self.logger.info('Source - %s (%s) %s' % (payment_orders[0].mode.bank_id.partner_id.name, payment_orders[0].mode.bank_id.acc_number, payment_orders[0].mode.bank_id.country_id.code)) src_account = self._create_account( - payment_orders[0].mode.bank_id, + payment_orders[0].mode.bank_id, payment_orders[0].mode.bank_id.country_id.code, is_origin_account=True )[0] except ValueError as exc: raise osv.except_osv( diff --git a/account_banking_uk_hsbc/wizard/paymul.py b/account_banking_uk_hsbc/wizard/paymul.py index b9f97f23a..18a954e5b 100644 --- a/account_banking_uk_hsbc/wizard/paymul.py +++ b/account_banking_uk_hsbc/wizard/paymul.py @@ -183,10 +183,13 @@ class NorthAmericanAccount(UKAccount): return account_ident def _set_sortcode(self, sortcode): - if not edifact_digits(sortcode, 9): - raise ValueError("Account routing number must be 9 digits long: " + - str(sortcode)) - + if self.origin_country == 'CA' and self.is_origin_account: + expected_digits = 6 + else: + expected_digits = 9 + if not edifact_digits(sortcode, expected_digits): + raise ValueError("Account routing number must be %d digits long: %s" % + (expected_digits, str(sortcode))) self._sortcode = sortcode @@ -218,14 +221,15 @@ class NorthAmericanAccount(UKAccount): number = property(_get_number, _set_number) - def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None): + def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None, is_origin_account=False): + self.origin_country = origin_country + self.is_origin_account = is_origin_account self.number = number self.holder = holder self.currency = currency self.sortcode = sortcode self.country = country self.bic = swiftcode - self.origin_country = origin_country self.institution_identification = self._set_account_ident() @@ -266,14 +270,15 @@ class SWIFTAccount(UKAccount): number = property(_get_number, _set_number) - def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None): + def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None, is_origin_account=False): + self.origin_country = origin_country + self.is_origin_account = is_origin_account self.number = number self.holder = holder self.currency = currency self.sortcode = sortcode self.country = country self.bic = swiftcode - self.origin_country = origin_country self.institution_identification = self._set_account_ident() From bef796d920043cda446c9d45d41732b37c7d2d4b Mon Sep 17 00:00:00 2001 From: James Jesudason Date: Tue, 27 Mar 2012 15:55:03 +0100 Subject: [PATCH 2/4] [FIX] The destination account address was set incorrectly. --- account_banking_uk_hsbc/__openerp__.py | 4 ++-- account_banking_uk_hsbc/account_banking_uk_hsbc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/account_banking_uk_hsbc/__openerp__.py b/account_banking_uk_hsbc/__openerp__.py index b20aa9bdf..d0a953689 100644 --- a/account_banking_uk_hsbc/__openerp__.py +++ b/account_banking_uk_hsbc/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## { 'name': 'HSBC Account Banking', - 'version': '0.4', + 'version': '0.5', 'license': 'AGPL-3', 'author': 'credativ Ltd', 'website': 'http://www.credativ.co.uk', @@ -45,7 +45,7 @@ This module adds above import/export filter to the account_banking module. All business logic is in account_banking module. - Initial release of this module was co-sponsored by canonical. + Initial release of this module was co-sponsored by Canonical. ''', 'active': False, 'installable': True, diff --git a/account_banking_uk_hsbc/account_banking_uk_hsbc.py b/account_banking_uk_hsbc/account_banking_uk_hsbc.py index 26da3c3d9..796329b1b 100644 --- a/account_banking_uk_hsbc/account_banking_uk_hsbc.py +++ b/account_banking_uk_hsbc/account_banking_uk_hsbc.py @@ -106,7 +106,7 @@ class payment_line(osv.osv): info = '' for line in self.browse(cr, uid, ids, context=context): - partner = line.order_id.mode.bank_id + partner = line.bank_id name = partner.owner_name or partner.partner_id.name st = partner.street and partner.street or '' From ce17d7a10855b76e7d1e40504b5d076dcc66c0c6 Mon Sep 17 00:00:00 2001 From: James Jesudason Date: Wed, 28 Mar 2012 20:01:57 +0100 Subject: [PATCH 3/4] [FIX] Ensure that the payment rate currency is set on the voucher. --- account_banking/banking_import_transaction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/account_banking/banking_import_transaction.py b/account_banking/banking_import_transaction.py index a745934ad..3b1b26631 100644 --- a/account_banking/banking_import_transaction.py +++ b/account_banking/banking_import_transaction.py @@ -1857,6 +1857,7 @@ class account_bank_statement_line(osv.osv): 'date': st_line.date, 'date_due': st_line.date, 'period_id': period_id, + 'payment_rate_currency_id':to_curr_id, } # Define the voucher line From 99a1cb2e570cd77f25fa527b8557e96c64afffa2 Mon Sep 17 00:00:00 2001 From: James Jesudason Date: Thu, 12 Apr 2012 18:42:11 +0100 Subject: [PATCH 4/4] [FIX] The validation of IBAN account numbers was preventing valid account numbers from being entered. --- account_banking/account_banking.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/account_banking/account_banking.py b/account_banking/account_banking.py index 146e4c525..bc8684634 100644 --- a/account_banking/account_banking.py +++ b/account_banking/account_banking.py @@ -1135,8 +1135,9 @@ class res_partner_bank(osv.osv): Create dual function IBAN account for SEPA countries ''' if vals['state'] == 'iban': + iban = vals.get('acc_number',False) or vals.get('acc_number_domestic',False) vals['acc_number'], vals['acc_number_domestic'] = ( - self._correct_IBAN(vals['acc_number'])) + self._correct_IBAN(iban)) return self._founder.create(cursor, uid, vals, context) def write(self, cr, uid, ids, vals, context=None): @@ -1421,7 +1422,9 @@ class res_partner_bank(osv.osv): ) _constraints = [ - (check_iban, _("The IBAN number doesn't seem to be correct"), ["acc_number"]) + # Cannot have this as a constraint as it is rejecting valid numbers from GB and DE + # It works much better without this constraint! + #(check_iban, _("The IBAN number doesn't seem to be correct"), ["acc_number"]) ] res_partner_bank()