[MRG] [FIX] Restore default period in bank statement by taking context in account

This commit is contained in:
unknown
2013-05-24 11:38:35 +02:00
committed by Alexandre Fayolle

View File

@@ -125,6 +125,16 @@ class AccountBankSatement(Model):
_inherit = "account.bank.statement" _inherit = "account.bank.statement"
def _default_period(self, cr, uid, context=None):
"""
Statement default period
"""
if context is None:
context = {}
period_obj = self.pool.get('account.period')
periods = period_obj.find(cr, uid, dt=context.get('date'), context=context)
return periods and periods[0] or False
_columns = { _columns = {
'profile_id': fields.many2one( 'profile_id': fields.many2one(
'account.statement.profile', 'account.statement.profile',
@@ -156,11 +166,15 @@ class AccountBankSatement(Model):
store=True, store=True,
readonly=True), readonly=True),
'period_id': fields.many2one( 'period_id': fields.many2one(
'account.period', 'Period', required=False, readonly=True), 'account.period',
'Period',
required=False,
readonly=False,
invisible=True),
} }
_defaults = { _defaults = {
'period_id': False, 'period_id': _default_period,
} }
def create(self, cr, uid, vals, context=None): def create(self, cr, uid, vals, context=None):
@@ -536,7 +550,9 @@ class AccountBankSatementLine(Model):
""" """
Return a period from a given date in the context. Return a period from a given date in the context.
""" """
date = context.get('date', None) if context is None:
context = {}
date = context.get('date')
periods = self.pool.get('account.period').find(cr, uid, dt=date) periods = self.pool.get('account.period').find(cr, uid, dt=date)
return periods and periods[0] or False return periods and periods[0] or False