diff --git a/move_period_from_transaction_date/model/__init__.py b/move_period_from_transaction_date/model/__init__.py
index a3fb3c75..68abc999 100644
--- a/move_period_from_transaction_date/model/__init__.py
+++ b/move_period_from_transaction_date/model/__init__.py
@@ -23,6 +23,7 @@
# along with this program. If not, see .
#
##############################################################################
+from . import account_bank_statement_line
from . import account_bank_statement
from . import account_bank_statement_line
from . import account_move_line
diff --git a/move_period_from_transaction_date/model/account_bank_statement.py b/move_period_from_transaction_date/model/account_bank_statement.py
index 03f4420b..8ed4c6bc 100644
--- a/move_period_from_transaction_date/model/account_bank_statement.py
+++ b/move_period_from_transaction_date/model/account_bank_statement.py
@@ -28,18 +28,11 @@ class AccountBankStatement(orm.Model):
def _prepare_move(
self, cr, uid, st_line, st_line_number, context=None):
- """Put marker in context to use period from date in move line."""
+ """If requested, override period from date."""
res = super(AccountBankStatement, self)._prepare_move(
cr, uid, st_line, st_line_number, context=context)
- context = context or {}
- if (('override_period_from_date' in context or
- 'period_id' not in res) and 'date' in res):
- period_model = self.pool['account.period']
- search_date = 'date' in res and res['date'] or None
- period_ids = period_model.find(
- cr, uid, dt=search_date, context=context)
- if period_ids:
- res['period_id'] = period_ids[0]
+ if (context or {}).get('force_period_id'):
+ res['period_id'] = context['force_period_id']
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/move_period_from_transaction_date/model/account_bank_statement_line.py b/move_period_from_transaction_date/model/account_bank_statement_line.py
index 849b2a40..4af54ce8 100644
--- a/move_period_from_transaction_date/model/account_bank_statement_line.py
+++ b/move_period_from_transaction_date/model/account_bank_statement_line.py
@@ -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,19 +18,21 @@
# along with this program. If not, see .
#
##############################################################################
-from openerp.osv import orm
+from openerp import models, api
-class AccountBankStatementLine(orm.Model):
+class AccountBankStatementLine(models.Model):
"""Extend account.bank.statement.line to use transaction date in moves."""
_inherit = 'account.bank.statement.line'
- def process_reconciliation(
- self, cr, uid, statement_line_id, mv_line_dicts, context=None):
- """Put marker in context to use period from date in move line."""
- ctx = context and context.copy() or {}
- ctx['override_period_from_date'] = True
+ @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(
- cr, uid, statement_line_id, mv_line_dicts, context=ctx)
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+ mv_line_dicts)
diff --git a/move_period_from_transaction_date/model/account_move_line.py b/move_period_from_transaction_date/model/account_move_line.py
index 5e7cb32f..c647cd83 100644
--- a/move_period_from_transaction_date/model/account_move_line.py
+++ b/move_period_from_transaction_date/model/account_move_line.py
@@ -28,15 +28,8 @@ class AccountMoveLine(orm.Model):
def create(self, cr, uid, vals, context=None, check=True):
"""If requested, override period from date."""
- context = context or {}
- if (('override_period_from_date' in context or
- 'period_id' not in vals) and 'date' in vals):
- period_model = self.pool['account.period']
- search_date = vals.get('date')
- period_ids = period_model.find(
- cr, uid, dt=search_date, context=context)
- if period_ids:
- vals['period_id'] = period_ids[0]
+ 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)