diff --git a/account_reconcile_payment_order/README.rst b/account_reconcile_payment_order/README.rst new file mode 100644 index 00000000..9ce5ae5f --- /dev/null +++ b/account_reconcile_payment_order/README.rst @@ -0,0 +1,51 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 +Reconcile payment orders +======================== + +Payment orders that show up as as one big transaction can be difficult for the accounting to handle if a transfer acount is used. In this case, we need to reconcile this transaction with possibly hunderds 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. + +Usage +===== + +It should just work. What the module does is to search for a payment order in state 'sent' that has the same amount as the statement line, and the same bank account than the statement. + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +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 + +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..3b45c14e --- /dev/null +++ b/account_reconcile_payment_order/__openerp__.py @@ -0,0 +1,33 @@ +# -*- 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": "1.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Accounting & Finance", + "summary": "Automatically reconcile all lines from sent 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..759f3aee --- /dev/null +++ b/account_reconcile_payment_order/models/account_bank_statement_line.py @@ -0,0 +1,73 @@ +# -*- 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 = 'sent' + 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] + return self.env['account.move.line']\ + .prepare_move_lines_for_reconciliation_widget( + list(set(order._get_transfer_move_lines()))) + + @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