Merge pull request #124 from pedrobaeza/8.0-account_reconcile_payment_order

[8.0] account_reconcile_payment_order
This commit is contained in:
Pedro M. Baeza
2015-10-06 16:37:53 +02:00
7 changed files with 224 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
.. 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
========================
Reconcile payment orders
========================
Payment orders that show up as one big transaction can be difficult for the
accounting to handle if a transfer account is used. In this case, we need to
reconcile this transaction with possibly hundreds of move lines, which can be a
bit tiresome. This module tries to recognize transactions deriving from payment
orders and propose the unreconciled move lines from this payment order.
Installation
============
This module requires the module **account_banking_payment_transfer**, available
in https://github.com/OCA/bank-payment.
Usage
=====
It should just work. What the module does is to search for a payment order in
state 'sent' (for orders transferred to an intermediate account) or done (for
orders non transferred) that has the same amount as the statement line, and the
same bank account than the statement. If any, all move lines are automatically
proposed for the reconcile.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/98/8.0
Known issues / Roadmap
======================
* it would be good to check references too, but at least the bank in use here
changes some characters, so this doesn't seem to be a general solution.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-reconcile/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
`here <https://github.com/OCA/bank-statement-reconcile/issues/new?body=module:%20account_reconcile_payment_order%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 http://odoo-community.org.

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import models

View File

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Reconcile payment orders",
"version": "8.0.1.0.0",
"author": "Therp BV,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Accounting & Finance",
"summary": "Automatically reconcile all lines from payment orders",
"depends": [
'account_banking_payment_transfer',
],
"auto_install": False,
"installable": True,
"application": False,
}

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import account_bank_statement_line

View File

@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from decimal import Decimal
from openerp import models, api
from openerp.tools.float_utils import float_repr
class AccountBankStatementLine(models.Model):
_inherit = 'account.bank.statement.line'
@api.model
def get_possible_payment_orders_for_statement_line(self, this):
"""find orders that might be candidates for matching a statement
line"""
digits = self.env['decimal.precision'].precision_get('Account')
self.env.cr.execute(
'''with order_sums as (
select order_id, sum(amount_currency) as amount
from payment_line
join payment_order o on o.id=order_id
where o.state in ('sent', 'done')
group by order_id)
select order_id from order_sums where amount = %s''',
(Decimal(float_repr(abs(this.amount), digits)),))
order_ids = [i for i, in self.env.cr.fetchall()]
# verify that this ids are accessible to the user and from the
# right bank account if applicable
domain = [
('id', 'in', order_ids),
]
if this.bank_account_id.acc_number:
domain.append(
('mode.bank_id.acc_number', '=',
this.bank_account_id.acc_number))
return self.env['payment.order'].search(domain)
@api.model
def get_reconcile_lines_from_order(self, this, orders, excluded_ids=None):
"""return lines to reconcile our statement line with"""
order = orders[0]
if order.state == 'sent':
move_lines_list = list(set(order._get_transfer_move_lines()))
else:
move_lines = order.line_ids.mapped('move_line_id').filtered(
lambda x: not x.reconcile_id)
move_lines_list = [x for x in move_lines]
return self.env['account.move.line']\
.prepare_move_lines_for_reconciliation_widget(move_lines_list)
@api.model
def get_reconciliation_proposition(self, this, excluded_ids=None):
"""See if we find a set payment order that matches our line. If yes,
return all unreconciled lines from there"""
orders = self.get_possible_payment_orders_for_statement_line(this)
if orders:
reconcile_lines = self.get_reconcile_lines_from_order(
this, orders, excluded_ids=None)
if reconcile_lines:
return reconcile_lines
return super(AccountBankStatementLine, self)\
.get_reconciliation_proposition(this, excluded_ids=excluded_ids)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

1
oca_dependencies.txt Normal file
View File

@@ -0,0 +1 @@
bank-payment