Merge pull request #115 from StefanRijnhart/8.0_transaction_period_fix_therp

8.0 transaction period fix therp
This commit is contained in:
Pedro M. Baeza
2015-08-19 20:00:12 +02:00
10 changed files with 362 additions and 0 deletions

View File

@@ -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 <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_bank_statement_period_from_line_date%0Aversion:%201.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Contributors
------------
* Stefan Rijnhart <stefan@therp.nl>
* Ronald Portier <ronald@therp.nl>
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.

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import account_bank_statement_line
from . import account_bank_statement
from . import account_move_line

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_reconciliation

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)