diff --git a/account_move_reconcile_helper/README.rst b/account_move_reconcile_helper/README.rst new file mode 100644 index 00000000..71cf6611 --- /dev/null +++ b/account_move_reconcile_helper/README.rst @@ -0,0 +1,64 @@ +.. 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 + +============================= +Account Move Reconcile Helper +============================= + +Provides tools to facilitate reconciliation. + +* Display a button on Journal entries list to show reconciled lines. +* Added Balance field in Journal entries list (this feature + is provided by account_balance_line). + +.. image:: ./static/docs/journal_entries_1.png + :alt: Journal entries + :scale: 50 % + +.. image:: ./static/docs/journal_entries_2.png + :alt: Reconciled lines view + :scale: 50 % + +Usage +===== + +.. 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/10.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Benjamin Willig + +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 https://odoo-community.org. diff --git a/account_move_reconcile_helper/__init__.py b/account_move_reconcile_helper/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_move_reconcile_helper/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_reconcile_helper/__manifest__.py b/account_move_reconcile_helper/__manifest__.py new file mode 100644 index 00000000..48b6ca2f --- /dev/null +++ b/account_move_reconcile_helper/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Move Reconcile Helper', + 'summary': "Provides tools to facilitate reconciliation", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/account-reconcile', + 'depends': [ + 'account_balance_line', + ], + 'data': [ + 'views/account_move_line.xml', + ], + 'demo': [ + ], +} diff --git a/account_move_reconcile_helper/models/__init__.py b/account_move_reconcile_helper/models/__init__.py new file mode 100644 index 00000000..8795b3be --- /dev/null +++ b/account_move_reconcile_helper/models/__init__.py @@ -0,0 +1 @@ +from . import account_move_line diff --git a/account_move_reconcile_helper/models/account_move_line.py b/account_move_reconcile_helper/models/account_move_line.py new file mode 100644 index 00000000..3846c2da --- /dev/null +++ b/account_move_reconcile_helper/models/account_move_line.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + + _inherit = 'account.move.line' + + partial_reconciliation_in_progress = fields.Boolean( + compute='_compute_partial_reconciliation_in_progress') + reconcile_line_ids = fields.One2many( + compute='_compute_reconciled_lines', + comodel_name='account.move.line', + string="Reconciled lines") + + @api.multi + @api.depends('matched_debit_ids', 'matched_credit_ids') + def _compute_partial_reconciliation_in_progress(self): + for rec in self: + rec.partial_reconciliation_in_progress = ( + bool(rec.matched_debit_ids) or bool(rec.matched_credit_ids)) + + @api.multi + def _compute_reconciled_lines(self): + for rec in self: + rec.reconcile_line_ids = rec._get_reconciled_lines() + + @api.multi + def _get_reconciled_lines(self, move_lines=None): + """ + Returns lines which were reconciled directly or indirectly with + current lines given in self. + + If A has been reconciled (or partially) with B, and B with C. This + method will returns A, B, and C. + + :param move_lines: found moves lines to avoid recursivity + :return: recordset('account.move.line') + """ + move_lines = move_lines or self.env[self._name] + + for line in self: + if line.full_reconcile_id: + matched_lines = line.full_reconcile_id.reconciled_line_ids + elif line.credit > 0: + matched_lines = line.matched_debit_ids.mapped('debit_move_id') + else: + matched_lines = line.matched_credit_ids.mapped( + 'credit_move_id') + + if not matched_lines: + continue + + move_lines |= line + + for matched_line in matched_lines: + if matched_line not in move_lines: + move_lines |= matched_line + move_lines |= matched_line._get_reconciled_lines( + move_lines) + + return move_lines + + @api.multi + def open_full_reconcile_view(self): + action = self.env.ref('account.action_account_moves_all_a').read()[0] + action['domain'] = [ + ('id', 'in', self.mapped('reconcile_line_ids').ids)] + return action diff --git a/account_move_reconcile_helper/static/description/icon.png b/account_move_reconcile_helper/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_move_reconcile_helper/static/description/icon.png differ diff --git a/account_move_reconcile_helper/static/docs/journal_entries_1.png b/account_move_reconcile_helper/static/docs/journal_entries_1.png new file mode 100644 index 00000000..abad0b04 Binary files /dev/null and b/account_move_reconcile_helper/static/docs/journal_entries_1.png differ diff --git a/account_move_reconcile_helper/static/docs/journal_entries_2.png b/account_move_reconcile_helper/static/docs/journal_entries_2.png new file mode 100644 index 00000000..0d4e995f Binary files /dev/null and b/account_move_reconcile_helper/static/docs/journal_entries_2.png differ diff --git a/account_move_reconcile_helper/tests/__init__.py b/account_move_reconcile_helper/tests/__init__.py new file mode 100644 index 00000000..135a0ef4 --- /dev/null +++ b/account_move_reconcile_helper/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_reconcile_helper diff --git a/account_move_reconcile_helper/tests/test_account_move_reconcile_helper.py b/account_move_reconcile_helper/tests/test_account_move_reconcile_helper.py new file mode 100644 index 00000000..5c692b22 --- /dev/null +++ b/account_move_reconcile_helper/tests/test_account_move_reconcile_helper.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestAccountMoveReconcileHelper(TransactionCase): + + def setUp(self): + super(TestAccountMoveReconcileHelper, self).setUp() + self.AccountObj = self.env['account.account'] + self.AccountJournalObj = self.env['account.journal'] + self.AccountMoveObj = self.env['account.move'] + self.AccountMoveLineObj = self.env['account.move.line'] + + self.account_type_recv = self.env.ref( + 'account.data_account_type_receivable') + self.account_type_rev = self.env.ref( + 'account.data_account_type_revenue') + + self.account_recv = self.AccountObj.create({ + 'code': 'MRH-RECVT', + 'name': "Receivable (test)", + 'reconcile': True, + 'user_type_id': self.account_type_recv.id, + }) + self.account_sale = self.AccountObj.create({ + 'code': 'MRH-SALET', + 'name': "Receivable (sale)", + 'reconcile': True, + 'user_type_id': self.account_type_rev.id, + }) + + self.sales_journal = self.AccountJournalObj.create({ + 'name': "Sales journal", + 'code': 'MRH-SAJT', + 'type': 'sale', + 'default_credit_account_id': self.account_sale.id, + 'default_debit_account_id': self.account_sale.id, + }) + + def create_account_move(self, amount, debit_account, credit_account): + return self.AccountMoveObj.create({ + 'journal_id': self.sales_journal.id, + 'line_ids': [ + (0, 0, { + 'name': "Receivable line", + 'account_id': debit_account.id, + 'debit': amount, + }), + (0, 0, { + 'name': "Sales line", + 'account_id': credit_account.id, + 'credit': amount, + }), + ] + }) + + def test_01_partial_reconcile(self): + base_move = self.create_account_move( + 5000, self.account_recv, self.account_sale) + + move1 = self.create_account_move( + 1000, self.account_sale, self.account_recv) + + move2 = self.create_account_move( + 1000, self.account_sale, self.account_recv) + + lines = self.AccountMoveLineObj.search([ + ('move_id', 'in', [base_move.id, move1.id, move2.id]), + ('account_id', '=', self.account_recv.id) + ]) + + lines.reconcile() + + for line in lines: + self.assertEquals(line.reconcile_line_ids, lines) + + def test_02_full_reconcile(self): + base_move = self.create_account_move( + 5000, self.account_recv, self.account_sale) + + move2 = self.create_account_move( + 2500, self.account_sale, self.account_recv) + move3 = self.create_account_move( + 2500, self.account_sale, self.account_recv) + + lines = self.AccountMoveLineObj.search([ + ('move_id', 'in', [base_move.id, move2.id, move3.id]), + ('account_id', '=', self.account_recv.id) + ]) + + lines.reconcile() + + for line in lines: + self.assertEquals(line.reconcile_line_ids, lines) + self.assertEquals( + line.full_reconcile_id.reconciled_line_ids, + line.reconcile_line_ids) diff --git a/account_move_reconcile_helper/views/account_move_line.xml b/account_move_reconcile_helper/views/account_move_line.xml new file mode 100644 index 00000000..bd274d46 --- /dev/null +++ b/account_move_reconcile_helper/views/account_move_line.xml @@ -0,0 +1,23 @@ + + + + + + + account.move.line.tree (in account_move_reconcile_helper) + account.move.line + + + + + +