[RFR] Port to API and conformity

This commit is contained in:
Stefan Rijnhart
2015-07-03 11:10:05 +02:00
parent 4303347f5e
commit 0b1a0c10bf
9 changed files with 74 additions and 112 deletions

View File

@@ -4,10 +4,17 @@
Module name
===========
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, that the period for the moves is determined
from the transaction (bank statement line), and not from the bank statement
period.
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.
Contributors
------------

View File

@@ -3,11 +3,6 @@
##############################################################################
#
# Copyright (C) 2015 Therp BV - http://therp.nl.
# All Rights Reserved
#
# 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
@@ -24,5 +19,3 @@
#
##############################################################################
from . import model
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -2,7 +2,6 @@
##############################################################################
#
# Copyright (C) 2015 Therp BV - http://therp.nl.
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as

View File

@@ -25,7 +25,6 @@
##############################################################################
from . import account_bank_statement_line
from . import account_bank_statement
from . import account_bank_statement_line
from . import account_move_line
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -3,7 +3,6 @@
##############################################################################
#
# Copyright (C) 2015 Therp BV - http://therp.nl.
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -19,20 +18,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
from openerp import models, api
class AccountBankStatement(orm.Model):
class AccountBankStatement(models.Model):
"""Extend account.bank.statement to use transaction date in moves."""
_inherit = 'account.bank.statement'
def _prepare_move(
self, cr, uid, st_line, st_line_number, context=None):
@api.model
def _prepare_move(self, st_line, st_line_number):
"""If requested, override period from date."""
res = super(AccountBankStatement, self)._prepare_move(
cr, uid, st_line, st_line_number, context=context)
if (context or {}).get('force_period_id'):
res['period_id'] = context['force_period_id']
st_line, st_line_number)
if self.env.context.get('force_period_id'):
res['period_id'] = self.env.context['force_period_id']
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -33,6 +33,6 @@ class AccountBankStatementLine(models.Model):
if periods:
return super(AccountBankStatementLine,
self.with_context(force_period_id=periods[0].id)).\
process_reconciliation(mv_line_dicts)
process_reconciliation(mv_line_dicts)
return super(AccountBankStatementLine, self).process_reconciliation(
mv_line_dicts)

View File

@@ -3,7 +3,6 @@
##############################################################################
#
# Copyright (C) 2015 Therp BV - http://therp.nl.
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -19,18 +18,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
from openerp import models, api
class AccountMoveLine(orm.Model):
class AccountMoveLine(models.Model):
"""Extend account.move.line to use date for period, when requested."""
_inherit = 'account.move.line'
def create(self, cr, uid, vals, context=None, check=True):
@api.model
def create(self, vals, check=True):
"""If requested, override period from date."""
if (context or {}).get('force_period_id'):
vals['period_id'] = context['force_period_id']
return super(AccountMoveLine, self).create(
cr, uid, vals, context=context, check=check)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
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

@@ -2,11 +2,6 @@
##############################################################################
#
# Copyright (C) 2015 Therp BV - http://therp.nl.
# All Rights Reserved
#
# 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
@@ -36,93 +31,68 @@ class TestReconciliation(TransactionCase):
dates from different period. Created moves produced by reconciliation
should take the period from the line date, not from the statement date.
"""
cr, uid = self.cr, self.uid
# 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
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
data_model = self.registry('ir.model.data')
partner_agrolait_id = data_model.get_object_reference(
cr, uid, 'base', 'res_partner_2')[1]
account_rcv_id = data_model.get_object_reference(
cr, uid, 'account', 'a_recv')[1]
currency_usd_id = data_model.get_object_reference(
cr, uid, 'base', 'USD')[1]
bank_journal_usd_id = data_model.get_object_reference(
cr, uid, 'account', 'bank_journal_usd')[1]
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:
period_model = self.registry('account.period')
account_invoice_model = self.registry('account.invoice')
account_invoice_line_model = self.registry('account.invoice.line')
statement_model = self.registry('account.bank.statement')
statement_line_model = self.registry('account.bank.statement.line')
account_invoice_model = self.env['account.invoice']
statement_line_model = self.env['account.bank.statement.line']
# Create invoice in dollars:
invoice_id = account_invoice_model.create(
cr, uid, {
'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,
}
)
account_invoice_line_model.create(
cr, uid, {
'name': 'product that cost 100.00',
'quantity': 1.0,
'price_unit': 100.0,
'invoice_id': invoice_id,
}
)
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:
account_invoice_model.signal_workflow(
cr, uid, [invoice_id], 'invoice_open')
invoice_record = account_invoice_model.browse(cr, uid, [invoice_id])
# Bank statement from september:
bank_stmt_id = statement_model.create(
cr, uid, {
'journal_id': bank_journal_usd_id,
'date': statement_date,
}
)
# Transaction from august:
bank_stmt_line_id = statement_line_model.create(
cr, uid, {
'name': 'complete payment',
'statement_id': bank_stmt_id,
'partner_id': partner_agrolait_id,
'amount': 100.00,
'date': transaction_date,
}
)
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_record.move_id.line_id:
if l.account_id.id == account_rcv_id:
line_id = l
for l in invoice.move_id.line_id:
if l.account_id == account_rcv:
line = l
break
statement_line_model.process_reconciliation(
cr, uid, bank_stmt_line_id, [{
'counterpart_move_line_id': line_id.id,
bank_stmt_line.id, [{
'counterpart_move_line_id': line.id,
'credit': 100.0,
'debit': 0.0,
'name': line_id.name,
}]
)
'name': line.name,
}])
# Get period for transaction date:
test_period_id = period_model.find(cr, uid, dt=transaction_date)[0]
# Get move lines for bank statement:
move_line_ids = statement_model.browse(
cr, uid, bank_stmt_id).move_line_ids
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 move_line_ids:
for move_line in bank_stmt.move_line_ids:
self.assertEquals(
move_line.period_id.id, test_period_id)
move_line.period_id, test_period)
self.assertEquals(
move_line.move_id.period_id.id, test_period_id)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
move_line.move_id.period_id, test_period)