mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MRG] Merged with prerequisite branch
This commit is contained in:
@@ -359,14 +359,6 @@ class account_bank_statement(orm.Model):
|
||||
def create_move_from_st_line(self, cr, uid, st_line_id,
|
||||
company_currency_id, st_line_number,
|
||||
context=None):
|
||||
# This is largely a copy of the original code in account
|
||||
# Modifications are marked with AB
|
||||
# Modifications by account_voucher are merged below.
|
||||
# As there is no valid inheritance mechanism for large actions, this
|
||||
# is the only option to add functionality to existing actions.
|
||||
# WARNING: when the original code changes, this trigger has to be
|
||||
# updated in sync.
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
account_move_obj = self.pool.get('account.move')
|
||||
@@ -376,15 +368,13 @@ class account_bank_statement(orm.Model):
|
||||
st_line = account_bank_statement_line_obj.browse(
|
||||
cr, uid, st_line_id, context=context)
|
||||
|
||||
# AB: take period from statement line and write to context
|
||||
# Take period from statement line and write to context
|
||||
# this will be picked up by the _prepare_move* methods
|
||||
period_id = self._get_period(
|
||||
cr, uid, st_line.date, context=context)
|
||||
localctx = context.copy()
|
||||
localctx['period_id'] = period_id
|
||||
# --AB
|
||||
|
||||
# AB: Take account_voucher into account:
|
||||
# Write date & period on the voucher, delegate to account_voucher's
|
||||
# override of this method. Then post the related move and return.
|
||||
if st_line.voucher_id:
|
||||
@@ -873,16 +863,13 @@ class res_partner_bank(orm.Model):
|
||||
if country.code in sepa.IBAN.countries:
|
||||
acc_number_fmt = sepa.BBAN(acc_number, country.code)
|
||||
if acc_number_fmt.valid:
|
||||
values['acc_number'] = str(acc_number_fmt)
|
||||
values['acc_number_domestic'] = str(acc_number_fmt)
|
||||
else:
|
||||
values['acc_number'] = acc_number
|
||||
result.update(warning(
|
||||
_('Invalid format'),
|
||||
_('The account number has the wrong format for %s')
|
||||
% country.name
|
||||
))
|
||||
else:
|
||||
values['acc_number'] = acc_number
|
||||
return result
|
||||
|
||||
def onchange_iban(
|
||||
|
||||
@@ -29,9 +29,9 @@ from openerp import netsvc
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.decimal_precision import decimal_precision as dp
|
||||
from openerp.addons.account_banking.parsers import models
|
||||
from openerp.addons.account_banking.parsers.convert import *
|
||||
from openerp.addons.account_banking.parsers import convert
|
||||
from openerp.addons.account_banking import sepa
|
||||
from openerp.addons.account_banking.wizard.banktools import *
|
||||
from openerp.addons.account_banking.wizard import banktools
|
||||
|
||||
bt = models.mem_bank_transaction
|
||||
|
||||
@@ -242,8 +242,8 @@ class banking_import_transaction(orm.Model):
|
||||
candidates = [
|
||||
x for x in move_lines
|
||||
if x.partner_id.id in partner_ids and
|
||||
(str2date(x.date, '%Y-%m-%d') <=
|
||||
(str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
(convert.str2date(x.date, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window))
|
||||
and (not _cached(x) or _remaining(x))
|
||||
]
|
||||
@@ -264,8 +264,8 @@ class banking_import_transaction(orm.Model):
|
||||
candidates = [
|
||||
x for x in candidates or move_lines
|
||||
if (x.invoice and has_id_match(x.invoice, ref, msg) and
|
||||
str2date(x.invoice.date_invoice, '%Y-%m-%d') <=
|
||||
(str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
convert.str2date(x.invoice.date_invoice, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window)
|
||||
and (not _cached(x) or _remaining(x)))
|
||||
]
|
||||
@@ -277,8 +277,8 @@ class banking_import_transaction(orm.Model):
|
||||
x for x in move_lines
|
||||
if (is_zero(x.move_id, ((x.debit or 0.0) - (x.credit or 0.0)) -
|
||||
trans.transferred_amount)
|
||||
and str2date(x.date, '%Y-%m-%d') <=
|
||||
(str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
and convert.str2date(x.date, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window)
|
||||
and (not _cached(x) or _remaining(x)))
|
||||
]
|
||||
@@ -293,8 +293,8 @@ class banking_import_transaction(orm.Model):
|
||||
best = [x for x in candidates
|
||||
if (is_zero(x.move_id, ((x.debit or 0.0) - (x.credit or 0.0)) -
|
||||
trans.transferred_amount)
|
||||
and str2date(x.date, '%Y-%m-%d') <=
|
||||
(str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
and convert.str2date(x.date, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window))
|
||||
]
|
||||
if len(best) == 1:
|
||||
@@ -312,8 +312,8 @@ class banking_import_transaction(orm.Model):
|
||||
# transfers first
|
||||
paid = [x for x in move_lines
|
||||
if x.invoice and has_id_match(x.invoice, ref, msg)
|
||||
and str2date(x.invoice.date_invoice, '%Y-%m-%d')
|
||||
<= str2date(trans.execution_date, '%Y-%m-%d')
|
||||
and convert.str2date(x.invoice.date_invoice, '%Y-%m-%d')
|
||||
<= convert.str2date(trans.execution_date, '%Y-%m-%d')
|
||||
and (_cached(x) and not _remaining(x))
|
||||
]
|
||||
if paid:
|
||||
@@ -923,7 +923,7 @@ class banking_import_transaction(orm.Model):
|
||||
account_info = info[transaction.local_account][currency_code]
|
||||
else:
|
||||
# Pull account info/currency
|
||||
account_info = get_company_bank_account(
|
||||
account_info = banktools.get_company_bank_account(
|
||||
self.pool, cr, uid, transaction.local_account,
|
||||
transaction.local_currency, company, results['log']
|
||||
)
|
||||
@@ -980,10 +980,9 @@ class banking_import_transaction(orm.Model):
|
||||
continue
|
||||
|
||||
# Link accounting period
|
||||
period_id = get_period(
|
||||
self.pool, cr, uid,
|
||||
str2date(transaction.effective_date,'%Y-%m-%d'), company,
|
||||
results['log'])
|
||||
period_id = banktools.get_period(
|
||||
self.pool, cr, uid, transaction.effective_date,
|
||||
company, results['log'])
|
||||
if not period_id:
|
||||
results['trans_skipped_cnt'] += 1
|
||||
if not injected:
|
||||
@@ -1042,7 +1041,7 @@ class banking_import_transaction(orm.Model):
|
||||
partner_banks = []
|
||||
else:
|
||||
# Link remote partner, import account when needed
|
||||
partner_banks = get_bank_accounts(
|
||||
partner_banks = banktools.get_bank_accounts(
|
||||
self.pool, cr, uid, transaction.remote_account,
|
||||
results['log'], fail=True
|
||||
)
|
||||
@@ -1061,7 +1060,7 @@ class banking_import_transaction(orm.Model):
|
||||
country_code = company.partner_id.country.code
|
||||
else:
|
||||
country_code = None
|
||||
partner_id = get_or_create_partner(
|
||||
partner_id = banktools.get_or_create_partner(
|
||||
self.pool, cr, uid, transaction.remote_owner,
|
||||
transaction.remote_owner_address,
|
||||
transaction.remote_owner_postalcode,
|
||||
@@ -1071,7 +1070,7 @@ class banking_import_transaction(orm.Model):
|
||||
supplier=transaction.transferred_amount < 0,
|
||||
context=context)
|
||||
if transaction.remote_account:
|
||||
partner_bank_id = create_bank_account(
|
||||
partner_bank_id = banktools.create_bank_account(
|
||||
self.pool, cr, uid, partner_id,
|
||||
transaction.remote_account,
|
||||
transaction.remote_owner,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
|
||||
|
||||
@@ -33,9 +33,9 @@ import base64
|
||||
import datetime
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.account_banking.parsers import models
|
||||
from openerp.addons.account_banking.parsers.convert import *
|
||||
from openerp.addons.account_banking.parsers import convert
|
||||
from openerp.addons.account_banking.struct import struct
|
||||
from openerp.addons.account_banking.wizard.banktools import *
|
||||
from openerp.addons.account_banking.wizard import banktools
|
||||
from openerp.addons.decimal_precision import decimal_precision as dp
|
||||
|
||||
bt = models.mem_bank_transaction
|
||||
@@ -92,7 +92,6 @@ class banking_import_line(orm.TransientModel):
|
||||
], 'Transaction type'),
|
||||
'duplicate': fields.boolean('Duplicate'),
|
||||
}
|
||||
banking_import_line()
|
||||
|
||||
|
||||
class banking_import(orm.TransientModel):
|
||||
@@ -184,7 +183,7 @@ class banking_import(orm.TransientModel):
|
||||
|
||||
else:
|
||||
# Pull account info/currency
|
||||
account_info = get_company_bank_account(
|
||||
account_info = banktools.get_company_bank_account(
|
||||
self.pool, cursor, uid, statement.local_account,
|
||||
statement.local_currency, company, results.log
|
||||
)
|
||||
@@ -241,7 +240,7 @@ class banking_import(orm.TransientModel):
|
||||
# matching procedure
|
||||
statement_ids = statement_obj.search(cursor, uid, [
|
||||
('name', '=', statement.id),
|
||||
('date', '=', date2str(statement.date)),
|
||||
('date', '=', convert.date2str(statement.date)),
|
||||
])
|
||||
if statement_ids:
|
||||
results.log.append(
|
||||
@@ -274,7 +273,7 @@ class banking_import(orm.TransientModel):
|
||||
statement_id = statement_obj.create(cursor, uid, dict(
|
||||
name = statement.id,
|
||||
journal_id = account_info.journal_id.id,
|
||||
date = date2str(statement.date),
|
||||
date = convert.date2str(statement.date),
|
||||
balance_start = statement.start_balance,
|
||||
balance_end_real = statement.end_balance,
|
||||
balance_end = statement.end_balance,
|
||||
@@ -439,7 +438,3 @@ class banking_import(orm.TransientModel):
|
||||
cr, uid, 'bank.import.transaction', context=c),
|
||||
'parser': _default_parser_type,
|
||||
}
|
||||
|
||||
banking_import()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
|
||||
@@ -19,9 +19,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import datetime
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.account_banking.parsers import convert
|
||||
from openerp.addons.account_banking import sepa
|
||||
from openerp.addons.account_banking.struct import struct
|
||||
|
||||
@@ -33,54 +31,23 @@ __all__ = [
|
||||
'create_bank_account',
|
||||
]
|
||||
|
||||
def get_period(pool, cursor, uid, date, company, log):
|
||||
def get_period(pool, cr, uid, date, company, log=None):
|
||||
'''
|
||||
Get a suitable period for the given date range and the given company.
|
||||
Wrapper over account_period.find() to log exceptions of
|
||||
missing periods instead of raising.
|
||||
'''
|
||||
fiscalyear_obj = pool.get('account.fiscalyear')
|
||||
period_obj = pool.get('account.period')
|
||||
if not date:
|
||||
date = convert.date2str(datetime.datetime.today())
|
||||
|
||||
search_date = convert.date2str(date)
|
||||
fiscalyear_ids = fiscalyear_obj.search(cursor, uid, [
|
||||
('date_start','<=', search_date), ('date_stop','>=', search_date),
|
||||
('state','=','draft'), ('company_id','=',company.id)
|
||||
])
|
||||
if not fiscalyear_ids:
|
||||
fiscalyear_ids = fiscalyear_obj.search(cursor, uid, [
|
||||
('date_start','<=',search_date), ('date_stop','>=',search_date),
|
||||
('state','=','draft'), ('company_id','=',None)
|
||||
])
|
||||
if not fiscalyear_ids:
|
||||
log.append(
|
||||
_('No suitable fiscal year found for date %(date)s and company %(company_name)s')
|
||||
% dict(company_name=company.name, date=date)
|
||||
)
|
||||
return False
|
||||
elif len(fiscalyear_ids) > 1:
|
||||
log.append(
|
||||
_('Multiple overlapping fiscal years found for date %(date)s and company %(company_name)s')
|
||||
% dict(company_name=company.name, date=date)
|
||||
)
|
||||
return False
|
||||
|
||||
fiscalyear_id = fiscalyear_ids[0]
|
||||
period_ids = period_obj.search(cursor, uid, [
|
||||
('date_start','<=',search_date), ('date_stop','>=',search_date),
|
||||
('fiscalyear_id','=',fiscalyear_id), ('state','=','draft'),
|
||||
('special', '=', False),
|
||||
])
|
||||
if not period_ids:
|
||||
log.append(_('No suitable period found for date %(date)s and company %(company_name)s')
|
||||
% dict(company_name=company.name, date=date)
|
||||
)
|
||||
return False
|
||||
if len(period_ids) != 1:
|
||||
log.append(_('Multiple overlapping periods for date %(date)s and company %(company_name)s')
|
||||
% dict(company_name=company.name, date=date)
|
||||
)
|
||||
return False
|
||||
context = {'account_period_prefer_normal': True}
|
||||
if company:
|
||||
context['company_id'] = company.id
|
||||
try:
|
||||
period_ids = pool.get('account.period').find(
|
||||
cr, uid, dt=date, context=context)
|
||||
except Exception, e:
|
||||
if log is None:
|
||||
raise
|
||||
else:
|
||||
log.append(e)
|
||||
return False
|
||||
return period_ids[0]
|
||||
|
||||
def get_bank_accounts(pool, cursor, uid, account_number, log, fail=False):
|
||||
|
||||
@@ -156,28 +156,55 @@ class transaction(models.mem_bank_transaction):
|
||||
The string consists of slash separated KEY/VALUE pairs,
|
||||
but the slash is allowed to and known to occur in VALUE as well!
|
||||
"""
|
||||
items = field[1:].split('/') # skip leading slash
|
||||
def _sepa_message(field, reason):
|
||||
return _(
|
||||
'unable to parse SEPA string: %s - %s' % (field, reason))
|
||||
|
||||
def _get_next_key(items, start):
|
||||
'''Find next key, starting from start, returns the key found,
|
||||
the start position in the array and the end position + 1'''
|
||||
known_keys = [
|
||||
'TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF', 'SWOC',
|
||||
'REMI', 'ADDR', 'CPRP', 'CREF', 'CSID', 'ISDT', 'MARF',
|
||||
'NRTX', 'NRTXR', 'PREF', 'PURP', 'REFOB', 'RREF', 'RTYP',
|
||||
'SVCL', 'SWOD', 'BENM//ID', 'ORDP//ID', 'ORDP//RID',
|
||||
'ORIG//CSID', 'ORIG//MARF', 'ULTD//NAME', 'ULTD//ID',
|
||||
'ULTB//NAME', 'ULTB//ID'
|
||||
]
|
||||
items_len = len(items)
|
||||
start_index = start
|
||||
# Search until start after end of items
|
||||
while start_index < items_len:
|
||||
end_index = start_index + 1
|
||||
while end_index < items_len:
|
||||
key = '/'.join(items[start_index:end_index])
|
||||
if key in known_keys:
|
||||
return (key, start_index, end_index)
|
||||
end_index += 1
|
||||
start_index += 1
|
||||
return False
|
||||
|
||||
items = field[1:].split('/')
|
||||
assert len(items) > 1, _sepa_message(field, _('too few items'))
|
||||
sepa_dict = {}
|
||||
prev_key = False
|
||||
known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',
|
||||
'SWOC', 'REMI', ]
|
||||
while items:
|
||||
if len(items) == 1:
|
||||
raise orm.except_orm(
|
||||
_('Error !'),
|
||||
_("unable to parse SEPA string: %s") % field)
|
||||
key = items.pop(0)
|
||||
if key not in known_keys:
|
||||
# either an unknown key or a value containing a slash
|
||||
if prev_key:
|
||||
sepa_dict[prev_key] = sepa_dict[prev_key] + '/' + key
|
||||
else:
|
||||
raise orm.except_orm(
|
||||
_('Error !'),
|
||||
_("unable to parse SEPA string: %s") % field)
|
||||
else:
|
||||
sepa_dict[key] = items.pop(0).strip()
|
||||
prev_key = key
|
||||
item_index = 0
|
||||
items_len = len(items)
|
||||
key_info = _get_next_key(items, item_index)
|
||||
assert key_info, _sepa_message(
|
||||
field, _('no key found for start %d') % item_index)
|
||||
assert key_info[1] == 0, _sepa_message(
|
||||
field, _('invalid data found before key %s') % key_info[0])
|
||||
while key_info:
|
||||
sepa_key = key_info[0]
|
||||
item_index = key_info[2]
|
||||
# Find where next key - if any - starts
|
||||
key_info = _get_next_key(items, item_index)
|
||||
value_end_index = (key_info and key_info[1]) or items_len
|
||||
sepa_value = (
|
||||
((value_end_index > item_index)
|
||||
and '/'.join(items[item_index:value_end_index]))
|
||||
or '')
|
||||
sepa_dict[sepa_key] = sepa_value
|
||||
return sepa_dict
|
||||
|
||||
def parse_type(field):
|
||||
|
||||
@@ -131,7 +131,7 @@ class payment_order(orm.Model):
|
||||
wizard_obj = self.pool.get(wizard_model)
|
||||
wizard_id = wizard_obj.create(cr, uid, {}, context)
|
||||
result = {
|
||||
'name': wizard_obj._description or 'Payment Order Export',
|
||||
'name': wizard_obj._description or _('Payment Order Export'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': wizard_model,
|
||||
|
||||
@@ -57,7 +57,7 @@ class payment_order_create(orm.TransientModel):
|
||||
# line2bank = line_obj.line2bank(cr, uid, line_ids, t, context)
|
||||
line2bank = line_obj.line2bank(
|
||||
cr, uid, line_ids, payment.mode.id, context)
|
||||
_today = datetime.utcnow().strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
_today = fields.date.context_today(self, cr, uid, context=context)
|
||||
### end account banking
|
||||
|
||||
## Finally populate the current payment with new lines:
|
||||
@@ -69,15 +69,17 @@ class payment_order_create(orm.TransientModel):
|
||||
### account_banking
|
||||
# date_to_pay = line.date_maturity
|
||||
date_to_pay = (
|
||||
line.date_maturity if line.date_maturity
|
||||
and line.date_maturity > _today else False)
|
||||
line.date_maturity
|
||||
if line.date_maturity and line.date_maturity > _today
|
||||
else False)
|
||||
### end account banking
|
||||
elif payment.date_prefered == 'fixed':
|
||||
### account_banking
|
||||
# date_to_pay = payment.date_planned
|
||||
date_to_pay = (
|
||||
payment.date_planned if payment.date_planned
|
||||
and payment.date_planned > _today else False)
|
||||
payment.date_planned
|
||||
if payment.date_planned and payment.date_planned > _today
|
||||
else False)
|
||||
### end account banking
|
||||
|
||||
### account_banking
|
||||
|
||||
Reference in New Issue
Block a user