mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[FIX] Reset the account on the statement line when the reconciliation is disabled.
[ADD] Set the transaction type for HSBC statement import.
This commit is contained in:
@@ -137,6 +137,12 @@ class account_banking_account_settings(osv.osv):
|
||||
[('parent_id', '=', False)]
|
||||
)[0]
|
||||
|
||||
def find(self, cr, uid, journal_id, partner_bank_id=False, context=None):
|
||||
domain = [('journal_id','=',journal_id)]
|
||||
if partner_bank_id:
|
||||
domain.append(('partner_bank_id','=',partner_bank_id))
|
||||
return self.search(cr, uid, domain, context=context)
|
||||
|
||||
_defaults = {
|
||||
'company_id': _default_company,
|
||||
#'multi_currency': lambda *a: False,
|
||||
|
||||
@@ -99,11 +99,12 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
del wizard_vals[key]
|
||||
|
||||
# write the related fields on the transaction model
|
||||
for wizard in self.read(
|
||||
cr, uid, ids, ['import_transaction_id'], context=context):
|
||||
if wizard['import_transaction_id']:
|
||||
if isinstance(ids, int):
|
||||
ids = [ids]
|
||||
for wizard in self.browse(cr, uid, ids, context=context):
|
||||
if wizard.import_transaction_id:
|
||||
transaction_obj.write(
|
||||
cr, uid, wizard['import_transaction_id'][0],
|
||||
cr, uid, wizard.import_transaction_id.id,
|
||||
transaction_vals, context=context)
|
||||
|
||||
# write other fields to the wizard model
|
||||
@@ -216,20 +217,34 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
"""
|
||||
Clear manual and automatic match information
|
||||
"""
|
||||
settings_pool = self.pool.get('account.banking.account.settings')
|
||||
statement_pool = self.pool.get('account.bank.statement.line')
|
||||
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
self.write(cr, uid, ids,
|
||||
{'partner_id': False,
|
||||
# 'manual_invoice_id': False,
|
||||
# 'manual_move_line_id': False,
|
||||
}, context=context)
|
||||
|
||||
wizs = self.read(
|
||||
cr, uid, ids, ['import_transaction_id'], context=context)
|
||||
trans_ids = [x['import_transaction_id'][0] for x in wizs
|
||||
if x['import_transaction_id']]
|
||||
return self.pool.get('banking.import.transaction').clear_and_write(
|
||||
cr, uid, trans_ids, context=context)
|
||||
|
||||
for wiz in self.browse(cr, uid, ids, context=context):
|
||||
# Get the bank account setting record, to reset the account
|
||||
account_id = False
|
||||
journal_id = wiz.statement_line_id.statement_id.journal_id.id
|
||||
setting_ids = settings_pool.find(cr, uid, journal_id, context=context)
|
||||
if len(setting_ids)>0:
|
||||
setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
|
||||
if wiz.amount < 0:
|
||||
account_id = setting.default_credit_account_id and setting.default_credit_account_id.id
|
||||
else:
|
||||
account_id = setting.default_debit_account_id and setting.default_debit_account_id.id
|
||||
statement_pool.write(cr, uid, wiz.statement_line_id.id, {'account_id':account_id})
|
||||
|
||||
self.write(cr, uid, wiz.id, {'partner_id': False}, context=context)
|
||||
|
||||
wizs = self.read(
|
||||
cr, uid, ids, ['import_transaction_id'], context=context)
|
||||
trans_ids = [x['import_transaction_id'][0] for x in wizs
|
||||
if x['import_transaction_id']]
|
||||
self.pool.get('banking.import.transaction').clear_and_write(
|
||||
cr, uid, trans_ids, context=context)
|
||||
return True
|
||||
|
||||
def reverse_duplicate(self, cr, uid, ids, context=None):
|
||||
if isinstance(ids, (int, float)):
|
||||
|
||||
@@ -22,12 +22,14 @@
|
||||
#
|
||||
|
||||
from account_banking.parsers import models
|
||||
from account_banking.parsers.convert import str2date
|
||||
from tools.translate import _
|
||||
from mt940_parser import HSBCParser
|
||||
import re
|
||||
import osv
|
||||
import logging
|
||||
|
||||
bt = models.mem_bank_transaction
|
||||
logger = logging.getLogger('hsbc_mt940')
|
||||
|
||||
def record2float(record, value):
|
||||
if record['creditmarker'][-1] == 'C':
|
||||
@@ -46,7 +48,10 @@ class transaction(models.mem_bank_transaction):
|
||||
}
|
||||
|
||||
type_map = {
|
||||
'TRF': bt.ORDER,
|
||||
'NTRF': bt.ORDER,
|
||||
'NMSC': bt.ORDER,
|
||||
'NPAY': bt.PAYMENT_BATCH,
|
||||
'NCHK': bt.CHECK,
|
||||
}
|
||||
|
||||
def __init__(self, record, *args, **kwargs):
|
||||
@@ -60,9 +65,15 @@ class transaction(models.mem_bank_transaction):
|
||||
|
||||
self.transferred_amount = record2float(record, 'amount')
|
||||
|
||||
#print record.get('bookingcode')
|
||||
# Set the transfer type based on the bookingcode
|
||||
if record.get('bookingcode','ignore') in self.type_map:
|
||||
self.transfer_type = self.type_map[record['bookingcode']]
|
||||
else:
|
||||
# Default to the generic order, so it will be eligible for matching
|
||||
self.transfer_type = bt.ORDER
|
||||
|
||||
if not self.is_valid():
|
||||
print "Invalid: %s" % record
|
||||
logger.info("Invalid: %s", record)
|
||||
def is_valid(self):
|
||||
'''
|
||||
We don't have remote_account so override base
|
||||
@@ -94,7 +105,7 @@ class statement(models.mem_bank_statement):
|
||||
def _transaction_info():
|
||||
self.transaction_info(record)
|
||||
def _not_used():
|
||||
print "Didn't use record: %s" % (record,)
|
||||
logger.info("Didn't use record: %s", record)
|
||||
|
||||
rectypes = {
|
||||
'20' : _transmission_number,
|
||||
@@ -121,7 +132,7 @@ class statement(models.mem_bank_statement):
|
||||
|
||||
transaction = self.transactions[-1]
|
||||
|
||||
transaction.reference = ','.join([record[k] for k in ['infoline{0}'.format(i) for i in range(1,5)] if record.has_key(k)])
|
||||
transaction.id = ','.join([record[k] for k in ['infoline{0}'.format(i) for i in range(2,5)] if record.has_key(k)])
|
||||
|
||||
def raise_error(message, line):
|
||||
raise osv.except_osv(_('Import error'),
|
||||
@@ -153,9 +164,8 @@ class parser_hsbc_mt940(models.parser):
|
||||
if stmnt.is_valid():
|
||||
result.append(stmnt)
|
||||
else:
|
||||
print "Invalid Statement:"
|
||||
print records[0]
|
||||
|
||||
logger.info("Invalid Statement:")
|
||||
logger.info(records[0])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user