From 319790b5a9882e0fd6d7b6dc818acb0ad82f0da6 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sun, 28 Aug 2016 14:11:57 +0200 Subject: [PATCH 1/3] account_payment_transfer_reconcile_batch (#226) [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 `_ 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. --- .../README.rst | 80 +++++++++++++++++++ .../__init__.py | 5 ++ .../__openerp__.py | 20 +++++ .../models/__init__.py | 5 ++ .../models/payment_order.py | 46 +++++++++++ .../tests/__init__.py | 4 + ...ccount_payment_transfer_reconcile_batch.py | 68 ++++++++++++++++ .../wizard/__init__.py | 4 + .../wizard/payment_order_create.py | 33 ++++++++ 9 files changed, 265 insertions(+) create mode 100644 account_payment_transfer_reconcile_batch/README.rst create mode 100644 account_payment_transfer_reconcile_batch/__init__.py create mode 100644 account_payment_transfer_reconcile_batch/__openerp__.py create mode 100644 account_payment_transfer_reconcile_batch/models/__init__.py create mode 100644 account_payment_transfer_reconcile_batch/models/payment_order.py create mode 100644 account_payment_transfer_reconcile_batch/tests/__init__.py create mode 100644 account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py create mode 100644 account_payment_transfer_reconcile_batch/wizard/__init__.py create mode 100644 account_payment_transfer_reconcile_batch/wizard/payment_order_create.py diff --git a/account_payment_transfer_reconcile_batch/README.rst b/account_payment_transfer_reconcile_batch/README.rst new file mode 100644 index 000000000..13d404a62 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/README.rst @@ -0,0 +1,80 @@ +.. 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 `_ + +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/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 + +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. diff --git a/account_payment_transfer_reconcile_batch/__init__.py b/account_payment_transfer_reconcile_batch/__init__.py new file mode 100644 index 000000000..7b4f2e16c --- /dev/null +++ b/account_payment_transfer_reconcile_batch/__init__.py @@ -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 diff --git a/account_payment_transfer_reconcile_batch/__openerp__.py b/account_payment_transfer_reconcile_batch/__openerp__.py new file mode 100644 index 000000000..3c6968b5a --- /dev/null +++ b/account_payment_transfer_reconcile_batch/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2015-2016 Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + 'name': "Batch Reconciliation for transfer moves", + 'version': '8.0.1.0.0', + 'author': "Tecnativa, " + "Odoo Community Association (OCA)", + 'license': 'AGPL-3', + 'category': 'Accounting & Finance', + 'depends': [ + 'account_banking_payment_transfer', + 'connector', + ], + 'website': 'https://www.tecnativa.com', + 'data': [ + ], + 'installable': True, +} diff --git a/account_payment_transfer_reconcile_batch/models/__init__.py b/account_payment_transfer_reconcile_batch/models/__init__.py new file mode 100644 index 000000000..0552eea1c --- /dev/null +++ b/account_payment_transfer_reconcile_batch/models/__init__.py @@ -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 payment_order diff --git a/account_payment_transfer_reconcile_batch/models/payment_order.py b/account_payment_transfer_reconcile_batch/models/payment_order.py new file mode 100644 index 000000000..a1c2d5758 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/models/payment_order.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# © 2015-2016 Pedro M. Baeza +# 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') diff --git a/account_payment_transfer_reconcile_batch/tests/__init__.py b/account_payment_transfer_reconcile_batch/tests/__init__.py new file mode 100644 index 000000000..0814743fe --- /dev/null +++ b/account_payment_transfer_reconcile_batch/tests/__init__.py @@ -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 diff --git a/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py b/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py new file mode 100644 index 000000000..ce7ee250f --- /dev/null +++ b/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# 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.journal = self.env['account.journal'].create({ + 'name': 'Test journal', + 'type': 'general', + 'code': 'TEST', + }) + self.bank_account = self.env['res.partner.bank'].create({ + 'state': 'bank', + 'acc_number': 'TEST', + }) + self.partner = self.env['res.partner'].create({ + 'name': 'Test partner', + 'supplier': True, + }) + self.mode = self.env['payment.mode'].create({ + 'name': 'Test payment mode', + 'journal': self.journal.id, + 'bank_id': self.bank_account.id, + 'transfer_journal_id': self.journal.id, + 'transfer_account_id': self.partner.property_account_payable.id, + 'type': self.env.ref( + 'account_banking_payment_export.manual_bank_tranfer').id, + }) + self.product = self.env['product.product'].create({ + 'name': 'Test product', + }) + self.invoice = self.env['account.invoice'].create({ + 'type': 'in_invoice', + 'partner_id': self.partner.id, + 'account_id': self.partner.property_account_payable.id, + 'invoice_line': [ + (0, 0, { + 'product_id': self.product.id, + 'name': self.product.name, + 'price_unit': 20, + }), + ] + }) + self.invoice.signal_workflow('invoice_open') + self.payment_order = self.env['payment.order'].create({ + 'mode': self.mode.id, + }) + line = self.invoice.move_id.line_id.filtered( + lambda x: x.account_id == self.invoice.account_id) + wizard = self.env['payment.order.create'].with_context( + active_model='payment.order', active_id=self.payment_order.id + ).create({}) + line_vals = wizard._prepare_payment_line(self.payment_order, line) + self.payment_line = self.env['payment.line'].create(line_vals) + + def test_enqueue(self): + self.payment_order.signal_workflow('open') + self.payment_order.action_open() + self.payment_order.with_context(test_connector=True).action_sent() + func = "openerp.addons.account_payment_transfer_reconcile_batch." \ + "models.payment_order.reconcile_one_move('bank.payment.line', " + job = self.env['queue.job'].sudo().search( + [('func_string', 'like', "%s%%" % func)]) + self.assertTrue(job) diff --git a/account_payment_transfer_reconcile_batch/wizard/__init__.py b/account_payment_transfer_reconcile_batch/wizard/__init__.py new file mode 100644 index 000000000..572331a63 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import payment_order_create diff --git a/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py b/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py new file mode 100644 index 000000000..9ac9a7b86 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, models + + +class PaymentOrderCreate(models.TransientModel): + _inherit = 'payment.order.create' + + @api.multi + def filter_lines(self, lines): + """Filter move lines before proposing them for inclusion in the payment + order (inherited). This one removes the move lines that aren't still + being processed in the connector queue. + + :param lines: recordset of move lines + :returns: list of move line ids + """ + filtered_line_ids = super(PaymentOrderCreate, self).filter_lines(lines) + func = "openerp.addons.account_payment_transfer_reconcile_batch." \ + "models.payment_order.reconcile_one_move('bank.payment.line', " + jobs = self.env['queue.job'].sudo().search( + [('func_string', 'like', "%s%%" % func), ('state', '!=', 'done')]) + if not jobs: + return filtered_line_ids + pline_ids = jobs.mapped(lambda x: int(x.func_string[len(func):-1])) + # With this, we remove non existing records + plines = self.env['bank.payment.line'].search( + [('id', 'in', pline_ids)]) + to_exclude = plines.mapped('payment_line_ids.move_line_id') + return [line_id for line_id in filtered_line_ids if + line_id not in to_exclude.ids] From 121dc230114ac477b6b5896544fc309666384cff Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sat, 3 Sep 2016 00:59:21 -0400 Subject: [PATCH 2/3] OCA Transbot updated translations from Transifex OCA Transbot updated translations from Transifex OCA Transbot updated translations from Transifex --- .../i18n/de.po | 30 +++++++++++++++++++ .../i18n/es.po | 30 +++++++++++++++++++ .../i18n/fr.po | 30 +++++++++++++++++++ .../i18n/it.po | 30 +++++++++++++++++++ .../i18n/nl.po | 30 +++++++++++++++++++ .../i18n/pt_BR.po | 30 +++++++++++++++++++ .../i18n/sl.po | 30 +++++++++++++++++++ 7 files changed, 210 insertions(+) create mode 100644 account_payment_transfer_reconcile_batch/i18n/de.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/es.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/fr.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/it.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/nl.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/pt_BR.po create mode 100644 account_payment_transfer_reconcile_batch/i18n/sl.po diff --git a/account_payment_transfer_reconcile_batch/i18n/de.po b/account_payment_transfer_reconcile_batch/i18n/de.po new file mode 100644 index 000000000..f4f7d2e11 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/de.po @@ -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 , 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 , 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/es.po b/account_payment_transfer_reconcile_batch/i18n/es.po new file mode 100644 index 000000000..ee6480802 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/es.po @@ -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 , 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 , 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 "" + +#. 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/fr.po b/account_payment_transfer_reconcile_batch/i18n/fr.po new file mode 100644 index 000000000..b7f1e8ea6 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/fr.po @@ -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) , 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) , 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/it.po b/account_payment_transfer_reconcile_batch/i18n/it.po new file mode 100644 index 000000000..cdc42abd3 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/it.po @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_transfer_reconcile_batch +# +# Translators: +# Stefano , 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 , 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/nl.po b/account_payment_transfer_reconcile_batch/i18n/nl.po new file mode 100644 index 000000000..fb3db286a --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/nl.po @@ -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 , 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 , 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/pt_BR.po b/account_payment_transfer_reconcile_batch/i18n/pt_BR.po new file mode 100644 index 000000000..58a8f72db --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/pt_BR.po @@ -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 , 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 , 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" diff --git a/account_payment_transfer_reconcile_batch/i18n/sl.po b/account_payment_transfer_reconcile_batch/i18n/sl.po new file mode 100644 index 000000000..d75a9a2a2 --- /dev/null +++ b/account_payment_transfer_reconcile_batch/i18n/sl.po @@ -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č , 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č , 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" From 4a12b7a908f8c7925539f6bb134e3e4a59088d9f Mon Sep 17 00:00:00 2001 From: Sergio Teruel Albert Date: Sat, 10 Dec 2016 03:51:51 +0100 Subject: [PATCH 3/3] [9.0][WIP] account_payment_transfer_reconcile_batch: Migration to v9. --- .../README.rst | 3 +- .../__openerp__.py | 4 +- .../i18n/es.po | 2 +- .../models/__init__.py | 2 +- ...{payment_order.py => bank_payment_line.py} | 17 ++--- ...ccount_payment_transfer_reconcile_batch.py | 73 ++++++++++++++----- .../wizard/__init__.py | 2 +- .../wizard/account_payment_line_create.py | 25 +++++++ .../wizard/payment_order_create.py | 33 --------- oca_dependencies.txt | 3 + 10 files changed, 96 insertions(+), 68 deletions(-) rename account_payment_transfer_reconcile_batch/models/{payment_order.py => bank_payment_line.py} (72%) create mode 100644 account_payment_transfer_reconcile_batch/wizard/account_payment_line_create.py delete mode 100644 account_payment_transfer_reconcile_batch/wizard/payment_order_create.py create mode 100644 oca_dependencies.txt diff --git a/account_payment_transfer_reconcile_batch/README.rst b/account_payment_transfer_reconcile_batch/README.rst index 13d404a62..b87b84ca4 100644 --- a/account_payment_transfer_reconcile_batch/README.rst +++ b/account_payment_transfer_reconcile_batch/README.rst @@ -46,7 +46,7 @@ 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/8.0 + :target: https://runbot.odoo-community.org/runbot/173/9.0 Bug Tracker =========== @@ -63,6 +63,7 @@ Contributors ------------ * Pedro M. Baeza +* Sergio Teruel Maintainer ---------- diff --git a/account_payment_transfer_reconcile_batch/__openerp__.py b/account_payment_transfer_reconcile_batch/__openerp__.py index 3c6968b5a..149e8b485 100644 --- a/account_payment_transfer_reconcile_batch/__openerp__.py +++ b/account_payment_transfer_reconcile_batch/__openerp__.py @@ -4,13 +4,13 @@ { 'name': "Batch Reconciliation for transfer moves", - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': "Tecnativa, " "Odoo Community Association (OCA)", 'license': 'AGPL-3', 'category': 'Accounting & Finance', 'depends': [ - 'account_banking_payment_transfer', + 'account_payment_order', 'connector', ], 'website': 'https://www.tecnativa.com', diff --git a/account_payment_transfer_reconcile_batch/i18n/es.po b/account_payment_transfer_reconcile_batch/i18n/es.po index ee6480802..9dd0a53bf 100644 --- a/account_payment_transfer_reconcile_batch/i18n/es.po +++ b/account_payment_transfer_reconcile_batch/i18n/es.po @@ -22,7 +22,7 @@ msgstr "" #: 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 "" +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 diff --git a/account_payment_transfer_reconcile_batch/models/__init__.py b/account_payment_transfer_reconcile_batch/models/__init__.py index 0552eea1c..e39ffa1f2 100644 --- a/account_payment_transfer_reconcile_batch/models/__init__.py +++ b/account_payment_transfer_reconcile_batch/models/__init__.py @@ -2,4 +2,4 @@ # © 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from . import payment_order +from . import bank_payment_line diff --git a/account_payment_transfer_reconcile_batch/models/payment_order.py b/account_payment_transfer_reconcile_batch/models/bank_payment_line.py similarity index 72% rename from account_payment_transfer_reconcile_batch/models/payment_order.py rename to account_payment_transfer_reconcile_batch/models/bank_payment_line.py index a1c2d5758..62ddc0bbd 100644 --- a/account_payment_transfer_reconcile_batch/models/payment_order.py +++ b/account_payment_transfer_reconcile_batch/models/bank_payment_line.py @@ -20,19 +20,19 @@ except ImportError: job = empty_decorator_factory -class PaymentOrder(models.Model): - _inherit = 'payment.order' +class BankPaymentLine(models.Model): + _inherit = 'bank.payment.line' @api.multi - def _reconcile_payment_lines(self, bank_payment_lines): + 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(PaymentOrder, self)._reconcile_payment_lines( - bank_payment_lines) + return super(BankPaymentLine, self).reconcile_payment_lines() session = ConnectorSession.from_env(self.env) - for bline in bank_payment_lines: - reconcile_one_move.delay(session, bline._name, bline.id) + 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') @@ -40,7 +40,6 @@ 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) + bline.with_context(no_connector=True).reconcile() else: return _(u'Nothing to do because the record has been deleted') diff --git a/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py b/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py index ce7ee250f..d2e7b92b3 100644 --- a/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py +++ b/account_payment_transfer_reconcile_batch/tests/test_account_payment_transfer_reconcile_batch.py @@ -8,61 +8,94 @@ 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({ - 'state': 'bank', 'acc_number': 'TEST', }) self.partner = self.env['res.partner'].create({ 'name': 'Test partner', 'supplier': True, }) - self.mode = self.env['payment.mode'].create({ + self.mode = self.env['account.payment.mode'].create({ 'name': 'Test payment mode', - 'journal': self.journal.id, - 'bank_id': self.bank_account.id, + '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, - 'type': self.env.ref( - 'account_banking_payment_export.manual_bank_tranfer').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, - 'invoice_line': [ + '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['payment.order'].create({ - 'mode': self.mode.id, + self.payment_order = self.env['account.payment.order'].create({ + 'payment_type': 'outbound', + 'payment_mode_id': self.mode.id, }) - line = self.invoice.move_id.line_id.filtered( + + line = self.invoice.move_id.line_ids.filtered( lambda x: x.account_id == self.invoice.account_id) - wizard = self.env['payment.order.create'].with_context( - active_model='payment.order', active_id=self.payment_order.id + + wizard = self.env['account.payment.line.create'].with_context( + active_model='account.payment.order', + active_id=self.payment_order.id ).create({}) - line_vals = wizard._prepare_payment_line(self.payment_order, line) - self.payment_line = self.env['payment.line'].create(line_vals) + wizard.move_line_ids = line + wizard.move_line_ids = line + wizard.create_payment_lines() def test_enqueue(self): - self.payment_order.signal_workflow('open') - self.payment_order.action_open() - self.payment_order.with_context(test_connector=True).action_sent() + self.payment_order.draft2open() + self.payment_order.with_context(test_connector=True).generate_move() func = "openerp.addons.account_payment_transfer_reconcile_batch." \ - "models.payment_order.reconcile_one_move('bank.payment.line', " + "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) diff --git a/account_payment_transfer_reconcile_batch/wizard/__init__.py b/account_payment_transfer_reconcile_batch/wizard/__init__.py index 572331a63..88586a32d 100644 --- a/account_payment_transfer_reconcile_batch/wizard/__init__.py +++ b/account_payment_transfer_reconcile_batch/wizard/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from . import payment_order_create +from . import account_payment_line_create diff --git a/account_payment_transfer_reconcile_batch/wizard/account_payment_line_create.py b/account_payment_transfer_reconcile_batch/wizard/account_payment_line_create.py new file mode 100644 index 000000000..647287d5b --- /dev/null +++ b/account_payment_transfer_reconcile_batch/wizard/account_payment_line_create.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# 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 diff --git a/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py b/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py deleted file mode 100644 index 9ac9a7b86..000000000 --- a/account_payment_transfer_reconcile_batch/wizard/payment_order_create.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html - -from openerp import api, models - - -class PaymentOrderCreate(models.TransientModel): - _inherit = 'payment.order.create' - - @api.multi - def filter_lines(self, lines): - """Filter move lines before proposing them for inclusion in the payment - order (inherited). This one removes the move lines that aren't still - being processed in the connector queue. - - :param lines: recordset of move lines - :returns: list of move line ids - """ - filtered_line_ids = super(PaymentOrderCreate, self).filter_lines(lines) - func = "openerp.addons.account_payment_transfer_reconcile_batch." \ - "models.payment_order.reconcile_one_move('bank.payment.line', " - jobs = self.env['queue.job'].sudo().search( - [('func_string', 'like', "%s%%" % func), ('state', '!=', 'done')]) - if not jobs: - return filtered_line_ids - pline_ids = jobs.mapped(lambda x: int(x.func_string[len(func):-1])) - # With this, we remove non existing records - plines = self.env['bank.payment.line'].search( - [('id', 'in', pline_ids)]) - to_exclude = plines.mapped('payment_line_ids.move_line_id') - return [line_id for line_id in filtered_line_ids if - line_id not in to_exclude.ids] diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 000000000..c2f242000 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1,3 @@ +# list the OCA project dependencies, one per line +# add a github url if you need a forked version +connector