mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[9.0][WIP] account_payment_transfer_reconcile_batch: Migration to v9.
This commit is contained in:
@@ -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 <pedro.baeza@tecnativa.com>
|
||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -1,33 +0,0 @@
|
||||
# -*- 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
|
||||
|
||||
|
||||
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]
|
||||
3
oca_dependencies.txt
Normal file
3
oca_dependencies.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# list the OCA project dependencies, one per line
|
||||
# add a github url if you need a forked version
|
||||
connector
|
||||
Reference in New Issue
Block a user