mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] Create import transactions instantly on manually encoded statements when matching wizard is run
This commit is contained in:
committed by
Guewen Baconnier @ Camptocamp
commit
91317fa43d
@@ -606,7 +606,7 @@ class banking_import_transaction(osv.osv):
|
||||
payment_line_obj.write(
|
||||
cr, uid, transaction.payment_line_id.id, {
|
||||
'export_state': 'done',
|
||||
'date_done': transaction.effective_date,
|
||||
'date_done': transaction.statement_line_id.date,
|
||||
}
|
||||
)
|
||||
self._confirm_move(cr, uid, transaction_id, context=context)
|
||||
@@ -961,9 +961,14 @@ class banking_import_transaction(osv.osv):
|
||||
]
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
"""
|
||||
Search for duplicates of the newly created transaction
|
||||
and mark them as such unless a context key
|
||||
'transaction_no_duplicate_search' is defined and true.
|
||||
"""
|
||||
res = super(banking_import_transaction, self).create(
|
||||
cr, uid, vals, context)
|
||||
if res:
|
||||
if res and not context.get('transaction_no_duplicate_search'):
|
||||
me = self.browse(cr, uid, res, context)
|
||||
search_vals = [(key, '=', me[key])
|
||||
for key in self.signal_duplicate_keys]
|
||||
@@ -1556,8 +1561,16 @@ class banking_import_transaction(osv.osv):
|
||||
|
||||
if transaction.move_line_id:
|
||||
move_line_amount = transaction.move_line_id.amount_residual_currency
|
||||
to_curr_id = transaction.statement_id.journal_id.currency and transaction.statement_id.journal_id.currency.id or transaction.statement_line_id.statement_id.company_id.currency_id.id
|
||||
from_curr_id = transaction.move_line_id.currency_id and transaction.move_line_id.currency_id.id or transaction.statement_id.company_id.currency_id.id
|
||||
to_curr_id = (
|
||||
transaction.statement_line_id.statement_id.journal_id.currency
|
||||
and transaction.statement_line_id.statement_id.journal_id.currency.id
|
||||
or transaction.statement_line_id.statement_id.company_id.currency_id.id
|
||||
)
|
||||
from_curr_id = (
|
||||
transaction.move_line_id.currency_id
|
||||
and transaction.move_line_id.currency_id.id
|
||||
or transaction.statement_line_id.statement_id.company_id.currency_id.id
|
||||
)
|
||||
if from_curr_id != to_curr_id:
|
||||
amount_currency = stline_pool._convert_currency(cr, uid, from_curr_id, to_curr_id, move_line_amount, round=True,
|
||||
date=time.strftime('%Y-%m-%d'), context=context)
|
||||
@@ -1871,6 +1884,42 @@ class account_bank_statement_line(osv.osv):
|
||||
return super(account_bank_statement_line, self).unlink(
|
||||
cr, uid, ids, context=context)
|
||||
|
||||
def create_instant_transaction(
|
||||
self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Check for existance of import transaction on the
|
||||
bank statement lines. Create instant items if appropriate.
|
||||
|
||||
This way, the matching wizard works on manually
|
||||
encoded statements.
|
||||
|
||||
The transaction is only filled with the most basic
|
||||
information. The use of the transaction at this point
|
||||
is rather to store matching data rather than to
|
||||
provide data about the transaction which have all been
|
||||
transferred to the bank statement line.
|
||||
"""
|
||||
import_transaction_pool = self.pool.get('banking.import.transaction')
|
||||
if ids and isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
if context is None:
|
||||
context = {}
|
||||
localcontext = context.copy()
|
||||
localcontext['transaction_no_duplicate_search'] = True
|
||||
for line in self.browse(
|
||||
cr, uid, ids, context=context):
|
||||
if line.state != 'confirmed' and not line.import_transaction_id:
|
||||
res = import_transaction_pool.create(
|
||||
cr, uid, {
|
||||
'company_id': line.statement_id.company_id.id,
|
||||
'statement_line_id': line.id,
|
||||
},
|
||||
context=localcontext)
|
||||
self.write(
|
||||
cr, uid, line.id, {
|
||||
'import_transaction_id': res},
|
||||
context=context)
|
||||
|
||||
account_bank_statement_line()
|
||||
|
||||
class account_bank_statement(osv.osv):
|
||||
|
||||
@@ -35,6 +35,18 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
_name = 'banking.transaction.wizard'
|
||||
_description = 'Match transaction'
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
"""
|
||||
Make sure that the statement line has an import transaction
|
||||
"""
|
||||
res = super(banking_transaction_wizard, self).create(
|
||||
cr, uid, vals, context=context)
|
||||
if res and vals.get('statement_line_id'):
|
||||
line_pool = self.pool.get('account.bank.statement.line')
|
||||
line_pool.create_instant_transaction(
|
||||
cr, uid, vals['statement_line_id'], context=context)
|
||||
return res
|
||||
|
||||
def create_act_window(self, cr, uid, ids, nodestroy=True, context=None):
|
||||
"""
|
||||
Return a popup window for this model
|
||||
|
||||
Reference in New Issue
Block a user