diff --git a/bank_transaction_period_fix/model/__init__.py b/bank_transaction_period_fix/model/__init__.py index 708e6440..bfabed5b 100644 --- a/bank_transaction_period_fix/model/__init__.py +++ b/bank_transaction_period_fix/model/__init__.py @@ -25,6 +25,7 @@ # along with this program. If not, see . # ############################################################################## +from . import account_bank_statement from . import account_bank_statement_line from . import account_move_line diff --git a/bank_transaction_period_fix/model/account_bank_statement.py b/bank_transaction_period_fix/model/account_bank_statement.py new file mode 100644 index 00000000..23dc675c --- /dev/null +++ b/bank_transaction_period_fix/model/account_bank_statement.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +"""Extend account.bank.statement to use transaction date in moves.""" +############################################################################## +# +# 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 +# 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.osv import orm + + +class AccountBankStatement(orm.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): + """Put marker in context to use period from date in move line.""" + 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] + return res + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bank_transaction_period_fix/model/account_move_line.py b/bank_transaction_period_fix/model/account_move_line.py index 70a38971..81ed5bda 100644 --- a/bank_transaction_period_fix/model/account_move_line.py +++ b/bank_transaction_period_fix/model/account_move_line.py @@ -28,13 +28,13 @@ class AccountMoveLine(orm.Model): def create(self, cr, uid, vals, context=None, check=True): """If requested, override period from date.""" - ctx = context and context.copy() or {} - if (('override_period_from_date' in ctx or + 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 = 'date' in vals and vals['date'] or None period_ids = period_model.find( - cr, uid, dt=search_date, context=ctx) + cr, uid, dt=search_date, context=context) if period_ids: vals['period_id'] = period_ids[0] return super(AccountMoveLine, self).create(