mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[RFR] Do not reuse the transaction amount but always take the statement line
amount. To be able to do so, create the transaction's statement line a little earlier. [FIX] Syntax error in assigning confirm_map items [RFR] Remove autosplit functionality that was already disabled [FIX] Logical order of the arguments in an error message
This commit is contained in:
@@ -62,7 +62,7 @@ class banking_import_transaction(orm.Model):
|
||||
return []
|
||||
|
||||
digits = dp.get_precision('Account')(cr)[1]
|
||||
amount = round(abs(trans.transferred_amount), digits)
|
||||
amount = round(abs(trans.statement_line_id.amount), digits)
|
||||
# Make sure to be able to pinpoint our costs invoice for later
|
||||
# matching
|
||||
reference = '%s.%s: %s' % (trans.statement, trans.transaction, trans.reference)
|
||||
@@ -233,10 +233,6 @@ class banking_import_transaction(orm.Model):
|
||||
digits = dp.get_precision('Account')(cr)[1]
|
||||
partial = False
|
||||
|
||||
# Disabled splitting transactions for now
|
||||
# TODO allow splitting in the interactive wizard
|
||||
allow_splitting = False
|
||||
|
||||
# Search invoice on partner
|
||||
if partner_ids:
|
||||
candidates = [
|
||||
@@ -276,7 +272,7 @@ class banking_import_transaction(orm.Model):
|
||||
candidates = [
|
||||
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)
|
||||
trans.statement_line_id.amount)
|
||||
and convert.str2date(x.date, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window)
|
||||
@@ -292,7 +288,7 @@ class banking_import_transaction(orm.Model):
|
||||
# TODO: currency coercing
|
||||
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)
|
||||
trans.statement_line_id.amount)
|
||||
and convert.str2date(x.date, '%Y-%m-%d') <=
|
||||
(convert.str2date(trans.execution_date, '%Y-%m-%d') +
|
||||
self.payment_window))
|
||||
@@ -343,7 +339,7 @@ class banking_import_transaction(orm.Model):
|
||||
|
||||
trans2 = None
|
||||
if move_line and partial:
|
||||
found = round(trans.transferred_amount, digits)
|
||||
found = round(trans.statement_line_id.amount, digits)
|
||||
if abs(expected) == abs(found):
|
||||
partial = False
|
||||
# Last partial payment will not flag invoice paid without
|
||||
@@ -358,24 +354,6 @@ class banking_import_transaction(orm.Model):
|
||||
elif abs(expected) > abs(found):
|
||||
# Partial payment, reuse invoice
|
||||
_cache(move_line, expected - found)
|
||||
elif abs(expected) < abs(found) and allow_splitting:
|
||||
# Possible combined payments, need to split transaction to
|
||||
# verify
|
||||
_cache(move_line)
|
||||
trans2 = self.copy(
|
||||
cr, uid, trans.id,
|
||||
dict(
|
||||
transferred_amount = trans.transferred_amount - expected,
|
||||
transaction = trans.transaction + 'b',
|
||||
parent_id = trans.id,
|
||||
), context=context)
|
||||
# update the current record
|
||||
self.write(cr, uid, trans.id, dict(
|
||||
transferred_amount = expected,
|
||||
transaction = trans.transaction + 'a',
|
||||
), context)
|
||||
# rebrowse the current record after writing
|
||||
trans = self.browse(cr, uid, trans.id, context=context)
|
||||
if move_line:
|
||||
account_ids = [
|
||||
x.id for x in bank_account_ids
|
||||
@@ -712,7 +690,7 @@ class banking_import_transaction(orm.Model):
|
||||
# due to float representation and rounding difficulties
|
||||
for trans in self.browse(cr, uid, ids, context=context):
|
||||
if self.pool.get('res.currency').is_zero(
|
||||
cr, uid,
|
||||
cr, uid,
|
||||
trans.statement_id.currency,
|
||||
me['transferred_amount'] - trans.transferred_amount):
|
||||
dupes.append(trans.id)
|
||||
@@ -878,12 +856,6 @@ class banking_import_transaction(orm.Model):
|
||||
else:
|
||||
transaction = transactions[i]
|
||||
|
||||
if (transaction.statement_line_id and
|
||||
transaction.statement_line_id.state == 'confirmed'):
|
||||
raise orm.except_orm(
|
||||
_("Cannot perform match"),
|
||||
_("Cannot perform match on a confirmed transction"))
|
||||
|
||||
if transaction.local_account in error_accounts:
|
||||
results['trans_skipped_cnt'] += 1
|
||||
if not injected:
|
||||
@@ -968,6 +940,44 @@ class banking_import_transaction(orm.Model):
|
||||
else:
|
||||
info[transaction.local_account][currency_code] = account_info
|
||||
|
||||
# Link accounting period
|
||||
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:
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if transaction.statement_line_id:
|
||||
if transaction.statement_line_id.state == 'confirmed':
|
||||
raise orm.except_orm(
|
||||
_("Cannot perform match"),
|
||||
_("Cannot perform match on a confirmed transction"))
|
||||
else:
|
||||
values = {
|
||||
'name': '%s.%s' % (transaction.statement, transaction.transaction),
|
||||
'date': transaction.effective_date,
|
||||
'amount': transaction.transferred_amount,
|
||||
'statement_id': transaction.statement_id.id,
|
||||
'note': transaction.message,
|
||||
'ref': transaction.reference,
|
||||
'period_id': period_id,
|
||||
'currency': account_info.currency_id.id,
|
||||
'import_transaction_id': transaction.id,
|
||||
'account_id': (
|
||||
transaction.transferred_amount < 0 and
|
||||
account_info.default_credit_account_id.id or
|
||||
account_info.default_debit_account_id.id),
|
||||
}
|
||||
statement_line_id = statement_line_obj.create(cr, uid, values, context)
|
||||
results['trans_loaded_cnt'] += 1
|
||||
transaction.write({'statement_line_id': statement_line_id})
|
||||
transaction.refresh()
|
||||
if transaction.statement_id.id not in imported_statement_ids:
|
||||
imported_statement_ids.append(transaction.statement_id.id)
|
||||
|
||||
# Final check: no coercion of currencies!
|
||||
if transaction.local_currency \
|
||||
and account_info.currency_id.name != transaction.local_currency:
|
||||
@@ -977,8 +987,8 @@ class banking_import_transaction(orm.Model):
|
||||
' uses different currency than the defined bank journal.'
|
||||
) % {
|
||||
'bank_account': transactions.local_account,
|
||||
'transaction_id': transaction.statement,
|
||||
'statement_id': transaction.transaction,
|
||||
'statement_id': transaction.statement,
|
||||
'transaction_id': transaction.transaction,
|
||||
}
|
||||
)
|
||||
error_accounts[transaction.local_account] = True
|
||||
@@ -987,16 +997,6 @@ class banking_import_transaction(orm.Model):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Link accounting period
|
||||
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:
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# When bank costs are part of transaction itself, split it.
|
||||
if transaction.type != bt.BANK_COSTS and transaction.provision_costs:
|
||||
# Create new transaction for bank costs
|
||||
@@ -1080,7 +1080,7 @@ class banking_import_transaction(orm.Model):
|
||||
|
||||
# Credit means payment... isn't it?
|
||||
if (not move_info
|
||||
and transaction.transferred_amount < 0 and payment_lines):
|
||||
and transaction.statement_line_id.amount < 0 and payment_lines):
|
||||
# Link open payment - if any
|
||||
# Note that _match_payment is defined in the
|
||||
# account_banking_payment module which should be installed
|
||||
@@ -1111,7 +1111,7 @@ class banking_import_transaction(orm.Model):
|
||||
# settings to overrule this. Note that you need to change
|
||||
# the internal type of these accounts to either 'payable'
|
||||
# or 'receivable' to enable usage like this.
|
||||
if transaction.transferred_amount < 0:
|
||||
if transaction.statement_line_id.amount < 0:
|
||||
if len(partner_banks) == 1:
|
||||
account_id = (
|
||||
partner_banks[0].partner_id.property_account_payable and
|
||||
@@ -1127,7 +1127,7 @@ class banking_import_transaction(orm.Model):
|
||||
if len(partner_banks) != 1 or not account_id or account_id == def_rec_account_id:
|
||||
account_id = (account_info.default_debit_account_id and
|
||||
account_info.default_debit_account_id.id)
|
||||
values = {}
|
||||
values = {'account_id': account_id}
|
||||
self_values = {}
|
||||
if move_info:
|
||||
results['trans_matched_cnt'] += 1
|
||||
@@ -1145,28 +1145,8 @@ class banking_import_transaction(orm.Model):
|
||||
len(partner_banks) == 1):
|
||||
values['partner_bank_id'] = partner_banks[0].id
|
||||
|
||||
if not transaction.statement_line_id:
|
||||
values.update(dict(
|
||||
name = '%s.%s' % (transaction.statement, transaction.transaction),
|
||||
date = transaction.effective_date,
|
||||
amount = transaction.transferred_amount,
|
||||
statement_id = transaction.statement_id.id,
|
||||
note = transaction.message,
|
||||
ref = transaction.reference,
|
||||
period_id = period_id,
|
||||
currency = account_info.currency_id.id,
|
||||
account_id = account_id,
|
||||
import_transaction_id = transaction.id,
|
||||
))
|
||||
|
||||
statement_line_id = statement_line_obj.create(cr, uid, values, context)
|
||||
results['trans_loaded_cnt'] += 1
|
||||
self_values['statement_line_id'] = statement_line_id
|
||||
if transaction.statement_id.id not in imported_statement_ids:
|
||||
imported_statement_ids.append(transaction.statement_id.id)
|
||||
else:
|
||||
statement_line_obj.write(
|
||||
cr, uid, transaction.statement_line_id.id, values, context)
|
||||
statement_line_obj.write(
|
||||
cr, uid, transaction.statement_line_id.id, values, context)
|
||||
self.write(cr, uid, transaction.id, self_values, context)
|
||||
if not injected:
|
||||
i += 1
|
||||
|
||||
@@ -44,7 +44,7 @@ class banking_import_transaction(orm.Model):
|
||||
sign = -1
|
||||
total = payment_order.total + sign * transferred_amount
|
||||
return self.pool.get('res.currency').is_zero(
|
||||
cr, uid, trans.statement_id.currency, total)
|
||||
cr, uid, trans.statement_line_id.statement_id.currency, total)
|
||||
|
||||
payment_order_obj = self.pool.get('payment.order')
|
||||
|
||||
@@ -56,7 +56,7 @@ class banking_import_transaction(orm.Model):
|
||||
limit=0, context=context)
|
||||
orders = payment_order_obj.browse(cr, uid, order_ids, context)
|
||||
candidates = [x for x in orders if
|
||||
equals_order_amount(x, trans.transferred_amount)]
|
||||
equals_order_amount(x, trans.statement_line_id.amount)]
|
||||
if len(candidates) > 0:
|
||||
# retrieve the common account_id, if any
|
||||
account_id = False
|
||||
@@ -89,7 +89,7 @@ class banking_import_transaction(orm.Model):
|
||||
# stornos MUST have an exact match
|
||||
if len(line_ids) == 1:
|
||||
account_id = payment_line_obj.get_storno_account_id(
|
||||
cr, uid, line_ids[0], trans.transferred_amount,
|
||||
cr, uid, line_ids[0], trans.statement_line_id.amount,
|
||||
trans.statement_id.currency, context=None)
|
||||
if account_id:
|
||||
return dict(
|
||||
@@ -121,7 +121,7 @@ class banking_import_transaction(orm.Model):
|
||||
x for x in payment_lines
|
||||
if x.communication == trans.reference
|
||||
and round(x.amount, digits) == -round(
|
||||
trans.transferred_amount, digits)
|
||||
trans.statement_line_id.amount, digits)
|
||||
and trans.remote_account in (x.bank_id.acc_number,
|
||||
x.bank_id.acc_number_domestic)
|
||||
]
|
||||
@@ -326,15 +326,14 @@ class banking_import_transaction(orm.Model):
|
||||
return res
|
||||
|
||||
def clear_and_write(self, cr, uid, ids, vals=None, context=None):
|
||||
super(banking_import_transaction, self).clear_and_write(
|
||||
write_vals = {
|
||||
'payment_line_id': False,
|
||||
'payment_order_id': False,
|
||||
'payment_order_ids': [(6, 0, [])],
|
||||
}
|
||||
write_vals.update(vals or {})
|
||||
return super(banking_import_transaction, self).clear_and_write(
|
||||
cr, uid, ids, vals=vals, context=context)
|
||||
return self.write(
|
||||
cr, uid, ids, {
|
||||
'payment_line_id': False,
|
||||
'payment_order_id': False,
|
||||
'payment_order_ids': [(6, 0, [])],
|
||||
},
|
||||
context=context)
|
||||
|
||||
def move_info2values(self, move_info):
|
||||
vals = super(banking_import_transaction, self).move_info2values(
|
||||
@@ -376,7 +375,7 @@ class banking_import_transaction(orm.Model):
|
||||
"""
|
||||
super(banking_import_transaction, self).__init__(pool, cr)
|
||||
|
||||
banking_import_transaction.confirm_map.update({
|
||||
self.confirm_map.update({
|
||||
'storno': banking_import_transaction._confirm_storno,
|
||||
'payment_order': banking_import_transaction._confirm_payment_order,
|
||||
'payment': banking_import_transaction._confirm_payment,
|
||||
@@ -384,7 +383,7 @@ class banking_import_transaction(orm.Model):
|
||||
'payment_manual': banking_import_transaction._confirm_payment,
|
||||
})
|
||||
|
||||
banking_import_transaction.cancel_map.update({
|
||||
self.cancel_map.update({
|
||||
'storno': banking_import_transaction._cancel_storno,
|
||||
'payment_order': banking_import_transaction._cancel_payment_order,
|
||||
'payment': banking_import_transaction._cancel_payment,
|
||||
|
||||
@@ -54,9 +54,9 @@ class banking_transaction_wizard(orm.TransientModel):
|
||||
else:
|
||||
sign = -1
|
||||
total = (payment_order.total + sign *
|
||||
transaction_id.transferred_amount)
|
||||
transaction_id.statement_line_id.amount)
|
||||
if not self.pool.get('res.currency').is_zero(
|
||||
cr, uid, transaction_id.statement_id.currency, total):
|
||||
cr, uid, transaction_id.statement_line_id.statement_id.currency, total):
|
||||
raise orm.except_orm(
|
||||
_('Error'),
|
||||
_('When matching a payment order, the amounts have to '
|
||||
|
||||
Reference in New Issue
Block a user