diff --git a/account_reconcile_payment_order/README.rst b/account_reconcile_payment_order/README.rst new file mode 100644 index 00000000..d16c8eae --- /dev/null +++ b/account_reconcile_payment_order/README.rst @@ -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 `_. +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 `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn +* Pedro M. Baeza + +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. diff --git a/account_reconcile_payment_order/__init__.py b/account_reconcile_payment_order/__init__.py new file mode 100644 index 00000000..cdb7d736 --- /dev/null +++ b/account_reconcile_payment_order/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +from . import models diff --git a/account_reconcile_payment_order/__openerp__.py b/account_reconcile_payment_order/__openerp__.py new file mode 100644 index 00000000..84e2a80d --- /dev/null +++ b/account_reconcile_payment_order/__openerp__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +{ + "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, +} diff --git a/account_reconcile_payment_order/models/__init__.py b/account_reconcile_payment_order/models/__init__.py new file mode 100644 index 00000000..33afdc17 --- /dev/null +++ b/account_reconcile_payment_order/models/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +from . import account_bank_statement_line diff --git a/account_reconcile_payment_order/models/account_bank_statement_line.py b/account_reconcile_payment_order/models/account_bank_statement_line.py new file mode 100644 index 00000000..ece9f634 --- /dev/null +++ b/account_reconcile_payment_order/models/account_bank_statement_line.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# 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 . +# +############################################################################## +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) diff --git a/account_reconcile_payment_order/static/description/icon.png b/account_reconcile_payment_order/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_reconcile_payment_order/static/description/icon.png differ diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 00000000..34f82ae9 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +bank-payment