From 4a12b7a908f8c7925539f6bb134e3e4a59088d9f Mon Sep 17 00:00:00 2001 From: Sergio Teruel Albert Date: Sat, 10 Dec 2016 03:51:51 +0100 Subject: [PATCH] [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