Skip to content

Commit

Permalink
Merge 72f6a89 into f8b96b2
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed May 23, 2019
2 parents f8b96b2 + 72f6a89 commit 8ea392b
Show file tree
Hide file tree
Showing 15 changed files with 636 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -19,8 +19,10 @@ env:

matrix:
- LINT_CHECK="1"
- TESTS="1" ODOO_REPO="OCA/OCB"
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="account_payment_order_background"
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1" EXCLUDE="account_payment_order_background"
- TESTS="1" ODOO_REPO="OCA/OCB" INCLUDE="account_payment_order_background"
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1" INCLUDE="account_payment_order_background"


install:
Expand Down
94 changes: 94 additions & 0 deletions account_payment_order_background/README.rst
@@ -0,0 +1,94 @@
===================================
Account Payment Order in Background
===================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github
:target: https://github.com/OCA/bank-payment/tree/12.0/account_payment_order_background
:alt: OCA/bank-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-payment-12-0/bank-payment-12-0-account_payment_order_background
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/97/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

When a Payment Order goes from state "File generated" to "File uploaded" ("File
successfully uploaded" button), payment lines are reconciled with their
counterparts. This step is very slow for hundreds of lines and locks many
records for the whole duration of the process, including sales orders when the
'invoiced' quantity is updated.

When this module is installed, the reconciliations are processed as jobs, so
the locks are short and the UI doesn't stay stuck for too long.

**Table of contents**

.. contents::
:local:

Installation
============

Queue Job is required and must be started.

Configuration
=============

It is advised to configure the job runner to run one job at once for
the channel used for reconciliations, otherwise they'll issue many locks::

ODOO_QUEUE_JOB_CHANNELS: root:4,root.background.move_reconcile:1

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 <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_order_background%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Bejaoui Souheil <souheil.bejaoui@acsone.eu>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/12.0/account_payment_order_background>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_payment_order_background/__init__.py
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions account_payment_order_background/__manifest__.py
@@ -0,0 +1,19 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Account Payment Order in Background',
'summary': 'The reconciliation of move lines from payment order '
'is processed in jobs.',
'version': '12.0.1.0.0',
'author': 'Camptocamp, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Sales',
'depends': [
'account_payment_order',
'queue_job',
],
'website': 'https://www.camptocamp.com',
'data': [],
'installable': True,
}
2 changes: 2 additions & 0 deletions account_payment_order_background/models/__init__.py
@@ -0,0 +1,2 @@
from . import account_move_line
from . import bank_payment_line
33 changes: 33 additions & 0 deletions account_payment_order_background/models/account_move_line.py
@@ -0,0 +1,33 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, exceptions, models
from odoo.addons.queue_job.job import job


class AccountMoveLine(models.Model):
_inherit = 'account.move.line'

@job(default_channel='root.background.move_reconcile')
@api.multi
def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
if self.env.context.get('__reconcile_as_job'):
self.with_delay().reconcile(
writeoff_acc_id=writeoff_acc_id,
writeoff_journal_id=writeoff_journal_id,
)
else:
try:
super(AccountMoveLine, self).reconcile(
writeoff_acc_id=writeoff_acc_id,
writeoff_journal_id=writeoff_journal_id,
)
except exceptions.UserError as err:
if self.env.context.get('job_uuid'):
# Processed in a job. We ignore failures, if they could
# not be reconciled it means it was already reconciled or
# not meant to be reconciled together (different accounts,
# company, ...). In such case a failed job would be
# useless.
return _('Not reconciled because of: %s') % (err.name,)
raise
21 changes: 21 additions & 0 deletions account_payment_order_background/models/bank_payment_line.py
@@ -0,0 +1,21 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class BankPaymentLine(models.Model):
_inherit = 'bank.payment.line'

@api.multi
def reconcile(self):
# Propagate __reconcile_as_job when the reconcile is done
# from a payment order so the lines will be reconciled in jobs
# (one per one).
# The reconciliation is slow and might update sale.order.line's
# invoiced field, locking the sale.order.line table for all the
# duration of the AccountPaymentOrder.generated2uploaded method
# so this shorten the duration of the locks.
return super(
BankPaymentLine, self.with_context(__reconcile_as_job=True)
).reconcile()
4 changes: 4 additions & 0 deletions account_payment_order_background/readme/CONFIGURE.rst
@@ -0,0 +1,4 @@
It is advised to configure the job runner to run one job at once for
the channel used for reconciliations, otherwise they'll issue many locks::

ODOO_QUEUE_JOB_CHANNELS: root:4,root.background.move_reconcile:1
1 change: 1 addition & 0 deletions account_payment_order_background/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
8 changes: 8 additions & 0 deletions account_payment_order_background/readme/DESCRIPTION.rst
@@ -0,0 +1,8 @@
When a Payment Order goes from state "File generated" to "File uploaded" ("File
successfully uploaded" button), payment lines are reconciled with their
counterparts. This step is very slow for hundreds of lines and locks many
records for the whole duration of the process, including sales orders when the
'invoiced' quantity is updated.

When this module is installed, the reconciliations are processed as jobs, so
the locks are short and the UI doesn't stay stuck for too long.
1 change: 1 addition & 0 deletions account_payment_order_background/readme/INSTALL.rst
@@ -0,0 +1 @@
Queue Job is required and must be started.

0 comments on commit 8ea392b

Please sign in to comment.