mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] Inject period if the move line is created without a date
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
# 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_bank_statement_line
|
||||
from . import account_move_line
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user