mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] account_banking: Added to_swift convertor
[IMP] account_banking: Fix 'paid' state for last partial payments
[FIX] account_banking_nl_clieop: filter messages to SWIFT set before export
[FIX] account_banking_nl_girotel: convert import to SWIFT before
interpretation
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking',
|
||||
'version': '0.1.47',
|
||||
'version': '0.1.49',
|
||||
'license': 'GPL-3',
|
||||
'author': 'EduSense BV',
|
||||
'website': 'http://www.edusense.nl',
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
__all__ = ['str2date', 'date2str', 'date2date']
|
||||
import unicodedata
|
||||
|
||||
__all__ = ['str2date', 'date2str', 'date2date', 'to_swift']
|
||||
|
||||
try:
|
||||
from datetime import datetime
|
||||
@@ -42,4 +44,17 @@ def date2date(datestr, fromfmt='%d/%m/%y', tofmt='%Y-%m-%d'):
|
||||
'''
|
||||
return date2str(str2date(datestr, fromfmt), tofmt)
|
||||
|
||||
_SWIFT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-?:().,'+ "
|
||||
|
||||
def to_swift(astr):
|
||||
'''
|
||||
Reduce a string to SWIFT format
|
||||
'''
|
||||
if not isinstance(astr, unicode):
|
||||
astr = unicode(astr, 'utf-8')
|
||||
s = [x in _SWIFT and x or ' '
|
||||
for x in unicodedata.normalize('NFKD', astr).encode('ascii', 'ignore')
|
||||
]
|
||||
return ''.join(s)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -399,6 +399,12 @@ class banking_import(wizard.interface):
|
||||
found = round(trans.transferred_amount, digits)
|
||||
if abs(expected) == abs(found):
|
||||
partial = False
|
||||
# Last partial payment will not flag invoice paid without
|
||||
# manual assistence
|
||||
invoice_obj = self.pool.get('account.invoice')
|
||||
invoice_obj.write(cursor, uid, [invoice.id], {
|
||||
'state': 'paid'
|
||||
})
|
||||
elif abs(expected) > abs(found):
|
||||
# Partial payment, reuse invoice
|
||||
_cache(move_line, expected - found)
|
||||
@@ -424,14 +430,6 @@ class banking_import(wizard.interface):
|
||||
if x.partner_id.id == move_line.partner_id.id
|
||||
]
|
||||
|
||||
# Re-check the cases with multiple candidates again:
|
||||
# later matches may have removed possible candidates.
|
||||
for trans, candidates in self.__multiple_matches:
|
||||
best = [x for x in candidates if not _cached(x)]
|
||||
if len(best) == 1:
|
||||
# Now an exact match can be made
|
||||
pass
|
||||
|
||||
return (
|
||||
self._get_move_info(cursor, uid, move_line,
|
||||
account_ids and account_ids[0] or False,
|
||||
@@ -864,12 +862,12 @@ class banking_import(wizard.interface):
|
||||
if transaction.transferred_amount < 0:
|
||||
if len(partner_banks) == 1:
|
||||
account_id = partner_banks[0].partner_id.property_account_payable
|
||||
if len(partner_banks) != 1 or account_id.id == def_pay_account_id:
|
||||
if len(partner_banks) != 1 or not account_id or account_id.id == def_pay_account_id:
|
||||
account_id = account_info.default_credit_account_id
|
||||
else:
|
||||
if len(partner_banks) == 1:
|
||||
account_id = partner_banks[0].partner_id.property_account_receivable
|
||||
if len(partner_banks) != 1 or account_id.id == def_rec_account_id:
|
||||
if len(partner_banks) != 1 or not account_id or account_id.id == def_rec_account_id:
|
||||
account_id = account_info.default_debit_account_id
|
||||
else:
|
||||
account_id = move_info.move_line.account_id
|
||||
|
||||
@@ -26,6 +26,7 @@ from tools.translate import _
|
||||
from account_banking.parsers import convert
|
||||
from account_banking import sepa
|
||||
from account_banking.struct import struct
|
||||
import unicodedata
|
||||
|
||||
__all__ = [
|
||||
'get_period',
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking PATU module',
|
||||
'version': '0.47',
|
||||
'version': '0.49',
|
||||
'license': 'GPL-3',
|
||||
'author': 'Sami Haahtinen',
|
||||
'website': 'http://ressukka.net',
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking NL ClieOp',
|
||||
'version': '0.47',
|
||||
'version': '0.49',
|
||||
'license': 'GPL-3',
|
||||
'author': 'EduSense BV',
|
||||
'website': 'http://www.edusense.nl',
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
##############################################################################
|
||||
|
||||
from account_banking import record
|
||||
from account_banking.parsers import convert
|
||||
|
||||
__all__ = ['DirectDebitBatch', 'PaymentsBatch', 'DirectDebit', 'Payment',
|
||||
'DirectDebitFile', 'PaymentsFile', 'SalaryPaymentsFile',
|
||||
@@ -27,6 +28,13 @@ __all__ = ['DirectDebitBatch', 'PaymentsBatch', 'DirectDebit', 'Payment',
|
||||
'OrdersFile',
|
||||
]
|
||||
|
||||
class StringField(record.Field):
|
||||
def take(self, buffer):
|
||||
return convert.to_swift(super(Field, self).take(buffer))
|
||||
|
||||
def format(self, value):
|
||||
return convert.to_swift(super(Field, self).format(value))
|
||||
|
||||
def eleven_test(s):
|
||||
'''
|
||||
Dutch eleven-test for validating 9-long local bank account numbers.
|
||||
@@ -52,7 +60,7 @@ class HeaderRecord(record.Record): #{{{
|
||||
record.Filler('variantcode', 1, 'A'),
|
||||
record.DateField('creation_date', '%d%m%y', auto=True),
|
||||
record.Filler('filename', 8, 'CLIEOP03'),
|
||||
record.Field('sender_id', 5),
|
||||
StringField('sender_id', 5),
|
||||
record.Field('file_id', 4),
|
||||
record.Field('duplicatecode', 1),
|
||||
record.Filler('filler', 21),
|
||||
@@ -82,7 +90,7 @@ class BatchHeaderRecord(record.Record):
|
||||
record.NumberField('accountno_sender', 10),
|
||||
record.NumberField('batch_tracer', 4),
|
||||
record.Filler('currency_order', 3, 'EUR'),
|
||||
record.Field('batch_id', 16),
|
||||
StringField('batch_id', 16),
|
||||
record.Filler('filler', 10),
|
||||
]
|
||||
|
||||
@@ -102,7 +110,7 @@ class FixedMessageRecord(record.Record):
|
||||
_fields = [
|
||||
record.Filler('recordcode', 4, '0020'),
|
||||
record.Filler('variantcode', 1, 'A'),
|
||||
record.Field('fixed_message', 32),
|
||||
StringField('fixed_message', 32),
|
||||
record.Filler('filler', 13),
|
||||
]
|
||||
|
||||
@@ -114,7 +122,7 @@ class SenderRecord(record.Record):
|
||||
# NAW = Name, Address, Residence
|
||||
record.Field('NAWcode', 1),
|
||||
record.DateField('preferred_execution_date', '%d%m%y', auto=True),
|
||||
record.Field('name_sender', 35),
|
||||
StringField('name_sender', 35),
|
||||
record.Field('testcode', 1),
|
||||
record.Filler('filler', 2),
|
||||
]
|
||||
@@ -136,7 +144,7 @@ class NamePayerRecord(record.Record):
|
||||
_fields = [
|
||||
record.Filler('recordcode', 4, '0110'),
|
||||
record.Filler('variantcode', 1, 'B'),
|
||||
record.Field('name', 35),
|
||||
StringField('name', 35),
|
||||
record.Filler('filler', 10),
|
||||
]
|
||||
|
||||
@@ -145,7 +153,7 @@ class PaymentReferenceRecord(record.Record):
|
||||
_fields = [
|
||||
record.Filler('recordcode', 4, '0150'),
|
||||
record.Filler('variantcode', 1, 'A'),
|
||||
record.Field('paymentreference', 16),
|
||||
StringField('paymentreference', 16),
|
||||
record.Filler('filler', 29),
|
||||
]
|
||||
|
||||
@@ -154,7 +162,7 @@ class DescriptionRecord(record.Record):
|
||||
_fields = [
|
||||
record.Filler('recordcode', 4, '0160'),
|
||||
record.Filler('variantcode', 1, 'A'),
|
||||
record.Field('description', 32),
|
||||
StringField('description', 32),
|
||||
record.Filler('filler', 13),
|
||||
]
|
||||
|
||||
@@ -163,7 +171,7 @@ class NameBeneficiaryRecord(record.Record):
|
||||
_fields = [
|
||||
record.Filler('recordcode', 4, '0170'),
|
||||
record.Filler('variantcode', 1, 'B'),
|
||||
record.Field('name', 35),
|
||||
StringField('name', 35),
|
||||
record.Filler('filler', 10),
|
||||
]
|
||||
|
||||
@@ -171,7 +179,7 @@ class OrderRecord(record.Record):
|
||||
'''Order details'''
|
||||
_fields = [
|
||||
record.Filler('recordcode', 6, 'KAE092'),
|
||||
record.Field('name_transactioncode', 18),
|
||||
StringField('name_transactioncode', 18),
|
||||
record.NumberField('total_amount', 13),
|
||||
record.Field('accountno_sender', 10),
|
||||
record.NumberField('total_accountnos', 5),
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking - Girotel',
|
||||
'version': '0.47',
|
||||
'version': '0.49',
|
||||
'license': 'GPL-3',
|
||||
'author': 'EduSense BV',
|
||||
'website': 'http://www.edusense.nl',
|
||||
|
||||
@@ -37,9 +37,13 @@ Assumptions:
|
||||
2. new transactions are appended after previously known transactions of
|
||||
the same date
|
||||
3. banks maintain order in transaction lists within a single date
|
||||
4. the data comes from the SWIFT-network (limited ASCII)
|
||||
|
||||
Assumption 4 seems not always true, leading to wrong character conversions.
|
||||
As a counter measure, all imported data is converted to SWIFT-format before usage.
|
||||
'''
|
||||
from account_banking.parsers import models
|
||||
from account_banking.parsers.convert import str2date
|
||||
from account_banking.parsers.convert import str2date, to_swift
|
||||
from tools.translate import _
|
||||
import csv
|
||||
|
||||
@@ -59,6 +63,15 @@ class transaction_message(object):
|
||||
|
||||
ids = {}
|
||||
|
||||
def __setattribute__(self, attr, value):
|
||||
if attr != 'attrnames' and attr in self.attrnames:
|
||||
value = to_swift(value)
|
||||
super(transaction_message, self).__setattribute__(attr, val)
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
retval = super(transaction_message, self).__getattribute__(attr)
|
||||
return attr != 'attrnames' and attr in self.attrnames and to_swift(retval) or retval
|
||||
|
||||
def genid(self):
|
||||
'''
|
||||
Generate a new id when not assigned before
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking',
|
||||
'version': '0.47',
|
||||
'version': '0.49',
|
||||
'license': 'GPL-3',
|
||||
'author': 'EduSense BV',
|
||||
'website': 'http://www.edusense.nl',
|
||||
|
||||
Reference in New Issue
Block a user