mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[ADD] account_payment_transfer_reconcile_batch ================================================================= Batch reconciliation for transfer lines created in payment orders ================================================================= This module allows to process with the connector technology the heavy task of reconciliation of the receivable/payable journal entries of a payment order against the created entries in transfer accounts. This approach provides many advantages, similar to the ones we get using that connector for e-commerce: - Asynchronous: the operation is done in background, and users can continue to work. - Dedicated workers: the queued jobs are performed by specific workers (processes). This is good for a long task, since the main workers are busy handling HTTP requests and can be killed if operations take too long, for example. - Multiple transactions: this is an operation that doesn't need to be atomic, and if a line out of 100,000 fails, it is possible to catch it, see the error message, and fix the situation. Meanwhile, all other jobs can proceed. Inspired on *account_move_batch_validate* module from Camptocamp and ACSONE. Installation ============ This module requires the connector module, hosted on `OCA/connector <https://github.com/OCA/connector>`_ Configuration ============= This will only work for payment modes that have a transfer account set. Usage ===== When exporting the payment order, click on *Validate* to generate the transfer move. One connector job will be created for each payment line for a deferred conciliation of this line.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# © 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
|
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
import logging
|
|
from openerp import models, api, _
|
|
from openerp.tools import config
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
from openerp.addons.connector.queue.job import job
|
|
from openerp.addons.connector.session import ConnectorSession
|
|
except ImportError:
|
|
_logger.debug('Can not `import connector`.')
|
|
import functools
|
|
|
|
def empty_decorator_factory(*argv, **kwargs):
|
|
return functools.partial
|
|
job = empty_decorator_factory
|
|
|
|
|
|
class PaymentOrder(models.Model):
|
|
_inherit = 'payment.order'
|
|
|
|
@api.multi
|
|
def _reconcile_payment_lines(self, bank_payment_lines):
|
|
test_condition = (config['test_enable'] and
|
|
not self.env.context.get('test_connector'))
|
|
if test_condition or self.env.context.get('no_connector'):
|
|
return super(PaymentOrder, self)._reconcile_payment_lines(
|
|
bank_payment_lines)
|
|
session = ConnectorSession.from_env(self.env)
|
|
for bline in bank_payment_lines:
|
|
reconcile_one_move.delay(session, bline._name, bline.id)
|
|
|
|
|
|
@job(default_channel='root.account_payment_transfer_reconcile_batch')
|
|
def reconcile_one_move(session, model_name, bank_payment_line_id):
|
|
bline_model = session.env[model_name]
|
|
bline = bline_model.browse(bank_payment_line_id)
|
|
if bline.exists():
|
|
obj = session.env['payment.order'].with_context(no_connector=True)
|
|
obj._reconcile_payment_lines(bline)
|
|
else:
|
|
return _(u'Nothing to do because the record has been deleted')
|