Merge pull request #323 from Tecnativa/9.0-mig-account_banking_mandate-account_payment_transfer_reconcile_batch

[9.0][MIG] account_payment_transfer_reconcile_batch: Migrate to v9
This commit is contained in:
Pedro M. Baeza
2017-01-14 12:06:56 +01:00
committed by GitHub
17 changed files with 503 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License AGPL-3
=================================================================
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.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/173/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/bank-payment/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Sergio Teruel <sergio.teruel@tecnativa.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import models
from . import wizard

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
'name': "Batch Reconciliation for transfer moves",
'version': '9.0.1.0.0',
'author': "Tecnativa, "
"Odoo Community Association (OCA)",
'license': 'AGPL-3',
'category': 'Accounting & Finance',
'depends': [
'account_payment_order',
'connector',
],
'website': 'https://www.tecnativa.com',
'data': [
],
'installable': True,
}

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# Philipp Hug <philipp@hug.cx>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-21 10:50+0000\n"
"PO-Revision-Date: 2016-09-21 10:50+0000\n"
"Last-Translator: Philipp Hug <philipp@hug.cx>, 2016\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr ""
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Zahlungsauftrag"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-29 02:41+0000\n"
"PO-Revision-Date: 2016-08-29 02:41+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr "El registro ha sido eliminado, no hay nada que hacer"
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Orden de pago"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# Sébastien LANGE (SYLEAM) <sebastien.lange@syleam.fr>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-11-20 00:07+0000\n"
"PO-Revision-Date: 2016-11-20 00:07+0000\n"
"Last-Translator: Sébastien LANGE (SYLEAM) <sebastien.lange@syleam.fr>, 2016\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr ""
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Ordre de paiement"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# Stefano <stefano.sforzi@agilebg.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-29 02:41+0000\n"
"PO-Revision-Date: 2016-08-29 02:41+0000\n"
"Last-Translator: Stefano <stefano.sforzi@agilebg.com>, 2016\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: it\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr ""
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Ordine di pagamento"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-29 02:41+0000\n"
"PO-Revision-Date: 2016-08-29 02:41+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
"Language-Team: Dutch (https://www.transifex.com/oca/teams/23907/nl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: nl\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr ""
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Betalingsopdracht"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-29 02:41+0000\n"
"PO-Revision-Date: 2016-08-29 02:41+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: pt_BR\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr ""
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Ordem de Pagamento"

View File

@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_transfer_reconcile_batch
#
# Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2016
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-29 02:41+0000\n"
"PO-Revision-Date: 2016-08-29 02:41+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>, 2016\n"
"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#. module: account_payment_transfer_reconcile_batch
#: code:addons/account_payment_transfer_reconcile_batch/models/payment_order.py:46
#, python-format
msgid "Nothing to do because the record has been deleted"
msgstr "Ničesar ni za narediti, ker je bil zapis izbrisan"
#. module: account_payment_transfer_reconcile_batch
#: model:ir.model,name:account_payment_transfer_reconcile_batch.model_payment_order
msgid "Payment Order"
msgstr "Plačilni nalog"

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import bank_payment_line

View File

@@ -0,0 +1,45 @@
# -*- 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 BankPaymentLine(models.Model):
_inherit = 'bank.payment.line'
@api.multi
def reconcile_payment_lines(self):
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(BankPaymentLine, self).reconcile_payment_lines()
session = ConnectorSession.from_env(self.env)
for bline in self:
if all([pline.move_line_id for pline in bline.payment_line_ids]):
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():
bline.with_context(no_connector=True).reconcile()
else:
return _(u'Nothing to do because the record has been deleted')

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import test_account_payment_transfer_reconcile_batch

View File

@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp.tests import common
class TestAccountPaymentTransferReconcileBatch(common.TransactionCase):
def setUp(self):
super(TestAccountPaymentTransferReconcileBatch, self).setUp()
self.method = self.env['account.payment.method'].create({
'name': 'Test Transfer',
'code': 'test_code_transfer',
'payment_type': 'outbound',
})
self.journal = self.env['account.journal'].create({
'name': 'Test journal',
'type': 'general',
'code': 'TEST',
'outbound_payment_method_ids': [(6, 0, self.method.ids)]
})
self.account_type = self.env['account.account.type'].create({
'name': 'Test account type',
'type': 'other',
})
self.account_expenses = self.env['account.account'].create({
'name': 'Test expenses account',
'code': 'test_account',
'user_type_id': self.account_type.id,
})
self.bank_account = self.env['res.partner.bank'].create({
'acc_number': 'TEST',
})
self.partner = self.env['res.partner'].create({
'name': 'Test partner',
'supplier': True,
})
self.mode = self.env['account.payment.mode'].create({
'name': 'Test payment mode',
'bank_account_link': 'fixed',
'offsetting_account': 'transfer_account',
'payment_method_id': self.method.id,
'fixed_journal_id': self.journal.id,
'transfer_journal_id': self.journal.id,
'transfer_account_id': self.partner.property_account_payable_id.id,
})
self.product = self.env['product.product'].create({
'name': 'Test product',
'property_account_expense_id': 1,
})
self.invoice = self.env['account.invoice'].create({
'type': 'in_invoice',
'partner_id': self.partner.id,
'account_id': self.partner.property_account_payable_id.id,
'invoice_line_ids': [
(0, 0, {
'product_id': self.product.id,
'name': self.product.name,
'price_unit': 20,
'account_id': self.account_expenses.id,
}),
]
})
self.invoice.signal_workflow('invoice_open')
self.payment_order = self.env['account.payment.order'].create({
'payment_type': 'outbound',
'payment_mode_id': self.mode.id,
})
line = self.invoice.move_id.line_ids.filtered(
lambda x: x.account_id == self.invoice.account_id)
wizard = self.env['account.payment.line.create'].with_context(
active_model='account.payment.order',
active_id=self.payment_order.id
).create({})
wizard.move_line_ids = line
wizard.move_line_ids = line
wizard.create_payment_lines()
def test_enqueue(self):
self.payment_order.draft2open()
self.payment_order.with_context(test_connector=True).generate_move()
func = "openerp.addons.account_payment_transfer_reconcile_batch." \
"models.bank_payment_line.reconcile_one_move(" \
"'bank.payment.line'"
job = self.env['queue.job'].sudo().search(
[('func_string', 'like', "%s%%" % func)])
self.assertTrue(job)
# Check domain queued moves
other_payment_order = self.env['account.payment.order'].create({
'payment_type': 'outbound',
'payment_mode_id': self.mode.id,
})
wizard = self.env['account.payment.line.create'].with_context(
active_model='account.payment.order',
active_id=other_payment_order.id
).create({})
domain = wizard._prepare_move_line_domain()
lines = self.env['account.move.line'].search(domain)
self.assertFalse(lines)

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import account_payment_line_create

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import api, models
from openerp.models import expression
class PaymentOrderCreate(models.TransientModel):
_inherit = 'account.payment.line.create'
@api.multi
def _prepare_move_line_domain(self):
domain = super(PaymentOrderCreate, self)._prepare_move_line_domain()
func = "openerp.addons.account_payment_transfer_reconcile_batch." \
"models.bank_payment_line.reconcile_one_move(" \
"'bank.payment.line',"
jobs = self.env['queue.job'].sudo().search(
[('func_string', 'like', "%s%%" % func), ('state', '!=', 'done')])
if not jobs:
return domain
pline_ids = jobs.mapped(lambda x: int(x.func_string[len(func):-1]))
# With this, we remove non existing records
batch_domain = expression.AND([[('id', 'not in', pline_ids)], domain])
return batch_domain

3
oca_dependencies.txt Normal file
View File

@@ -0,0 +1,3 @@
# list the OCA project dependencies, one per line
# add a github url if you need a forked version
connector