diff --git a/account_bank_statement_period_from_line_date/README.rst b/account_bank_statement_period_from_line_date/README.rst new file mode 100644 index 00000000..a67fde7e --- /dev/null +++ b/account_bank_statement_period_from_line_date/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Use bank transaction date to determine move period +================================================== + +By default, a bank statement in Odoo has its own period, and this period +will be assigned to all the moves generated from the bank statement lines, +regardless of their effective dates. + +The desirability of this behaviour depends on the jurisdiction and may be +illegal. + +This module was written to make sure that when reconciliation moves are +generated for a bank transaction, the period for the moves is determined from +the transaction (bank statement line) date, and not taken from the bank +statement. + +Usage +===== + +Just enter any bank statement with transactions on dates outside the accounting +period on the bank statement itself. When the moves are created, you will find +that these have the correct period set. + +.. 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 + +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 `_. + +Contributors +------------ + +* Stefan Rijnhart +* Ronald Portier + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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_bank_statement_period_from_line_date/__init__.py b/account_bank_statement_period_from_line_date/__init__.py new file mode 100644 index 00000000..6adba3fc --- /dev/null +++ b/account_bank_statement_period_from_line_date/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## +from . import model diff --git a/account_bank_statement_period_from_line_date/__openerp__.py b/account_bank_statement_period_from_line_date/__openerp__.py new file mode 100644 index 00000000..87abdb06 --- /dev/null +++ b/account_bank_statement_period_from_line_date/__openerp__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## +{ + 'name': 'Use bank transaction (line) date to determine move period', + 'version': '1.0', + 'author': 'Therp BV, Odoo Community Association (OCA)', + 'category': 'Banking addons', + 'depends': [ + 'account', + ], + 'website': 'https://github.com/OCA/bank-statement-reconcile', + 'data': [], + 'test': [], + 'installable': True, + 'images': [], + 'auto_install': False, + 'license': 'AGPL-3', +} diff --git a/account_bank_statement_period_from_line_date/model/__init__.py b/account_bank_statement_period_from_line_date/model/__init__.py new file mode 100644 index 00000000..a81d7cc0 --- /dev/null +++ b/account_bank_statement_period_from_line_date/model/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Therp BV - http://therp.nl. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# +# 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 +from . import account_bank_statement +from . import account_move_line diff --git a/account_bank_statement_period_from_line_date/model/account_bank_statement.py b/account_bank_statement_period_from_line_date/model/account_bank_statement.py new file mode 100644 index 00000000..affcda7d --- /dev/null +++ b/account_bank_statement_period_from_line_date/model/account_bank_statement.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## +from openerp import models, api + + +class AccountBankStatement(models.Model): + """Extend account.bank.statement to use transaction date in moves.""" + _inherit = 'account.bank.statement' + + @api.model + def _prepare_move(self, st_line, st_line_number): + """If requested, override period from date.""" + res = super(AccountBankStatement, self)._prepare_move( + st_line, st_line_number) + if self.env.context.get('force_period_id'): + res['period_id'] = self.env.context['force_period_id'] + return res diff --git a/account_bank_statement_period_from_line_date/model/account_bank_statement_line.py b/account_bank_statement_period_from_line_date/model/account_bank_statement_line.py new file mode 100644 index 00000000..668c7e10 --- /dev/null +++ b/account_bank_statement_period_from_line_date/model/account_bank_statement_line.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## +from openerp import models, api + + +class AccountBankStatementLine(models.Model): + """Extend account.bank.statement.line to use transaction date in moves.""" + _inherit = 'account.bank.statement.line' + + @api.one + def process_reconciliation(self, mv_line_dicts): + """ Retrieve the period derived from the statement line and store in + the context for further use """ + periods = self.env['account.period'].find(dt=self.date) + if periods: + return super(AccountBankStatementLine, + self.with_context(force_period_id=periods[0].id)).\ + process_reconciliation(mv_line_dicts) + return super(AccountBankStatementLine, self).process_reconciliation( + mv_line_dicts) diff --git a/account_bank_statement_period_from_line_date/model/account_move_line.py b/account_bank_statement_period_from_line_date/model/account_move_line.py new file mode 100644 index 00000000..d620b5fd --- /dev/null +++ b/account_bank_statement_period_from_line_date/model/account_move_line.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## +from openerp import models, api + + +class AccountMoveLine(models.Model): + """Extend account.move.line to use date for period, when requested.""" + _inherit = 'account.move.line' + + @api.model + def create(self, vals, check=True): + """If requested, override period from date.""" + if self.env.context.get('force_period_id'): + vals['period_id'] = self.env.context['force_period_id'] + return super(AccountMoveLine, self).create(vals, check=check) diff --git a/account_bank_statement_period_from_line_date/static/description/icon.png b/account_bank_statement_period_from_line_date/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_bank_statement_period_from_line_date/static/description/icon.png differ diff --git a/account_bank_statement_period_from_line_date/tests/__init__.py b/account_bank_statement_period_from_line_date/tests/__init__.py new file mode 100644 index 00000000..c4c08562 --- /dev/null +++ b/account_bank_statement_period_from_line_date/tests/__init__.py @@ -0,0 +1,23 @@ +############################################################################## +# +# Copyright (C) 2015 Therp BV - http://therp.nl. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# +# 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 test_reconciliation diff --git a/account_bank_statement_period_from_line_date/tests/test_reconciliation.py b/account_bank_statement_period_from_line_date/tests/test_reconciliation.py new file mode 100644 index 00000000..85094c98 --- /dev/null +++ b/account_bank_statement_period_from_line_date/tests/test_reconciliation.py @@ -0,0 +1,98 @@ +"""Unit test to check wether period taken from transaction date.""" +############################################################################## +# +# 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 . +# +############################################################################## +from openerp.tests.common import TransactionCase +import time + + +class TestReconciliation(TransactionCase): + """Tests to make sure that transactions take period from statement line.""" + + def test_period_from_transaction(self): + """Move line for reconciliation should take period from transaction. + + Setup a bank statement and a bank statement line (transaction) with + dates from different period. Created moves produced by reconciliation + should take the period from the line date, not from the statement date. + """ + # Setup dates for testing: + current_year = time.strftime('%Y') + invoice_date = '%s-07-01' % current_year # July + statement_date = '%s-09-01' % current_year # September + transaction_date = '%s-08-01' % current_year # August + # Get references to demo data + partner_agrolait = self.env.ref('base.res_partner_2') + account_rcv = self.env.ref('account.a_recv') + currency_usd = self.env.ref('base.USD') + bank_journal_usd = self.env.ref('account.bank_journal_usd') + # Get other models from registry: + account_invoice_model = self.env['account.invoice'] + statement_line_model = self.env['account.bank.statement.line'] + # Create invoice in dollars: + invoice = account_invoice_model.create({ + 'partner_id': partner_agrolait.id, + 'currency_id': currency_usd.id, + 'reference_type': 'none', + 'name': 'invoice to client', + 'account_id': account_rcv.id, + 'type': 'out_invoice', + 'date_invoice': invoice_date, + }) + self.env['account.invoice.line'].create({ + 'name': 'product that cost 100.00', + 'quantity': 1.0, + 'price_unit': 100.0, + 'invoice_id': invoice.id, + }) + # Validate sale: + invoice.signal_workflow('invoice_open') + # Bank statement from September: + bank_stmt = self.env['account.bank.statement'].create({ + 'journal_id': bank_journal_usd.id, + 'date': statement_date, + }) + # Transaction from August: + bank_stmt_line = statement_line_model.create({ + 'name': 'complete payment', + 'statement_id': bank_stmt.id, + 'partner_id': partner_agrolait.id, + 'amount': 100.00, + 'date': transaction_date, + }) + # Reconcile the payment with the invoice: + for l in invoice.move_id.line_id: + if l.account_id == account_rcv: + line = l + break + statement_line_model.process_reconciliation( + bank_stmt_line.id, [{ + 'counterpart_move_line_id': line.id, + 'credit': 100.0, + 'debit': 0.0, + 'name': line.name, + }]) + # Get period for transaction date: + test_period = self.env['account.period'].find(dt=transaction_date)[0] + # Period in move line for bank transaction, and for move should equal + # period from transaction: + for move_line in bank_stmt.move_line_ids: + self.assertEquals( + move_line.period_id, test_period) + self.assertEquals( + move_line.move_id.period_id, test_period)