~akretion-team/banking-addons/bank-statement-reconcile-7.0-file-exchange

« back to all changes in this revision

Viewing changes to account_statement_ext/statement.py

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-*- coding: utf-8 -*-
 
1
# -*- coding: utf-8 -*-
2
2
##############################################################################
3
3
#
4
4
#    Author: Nicolas Bessi, Joel Grand-Guillaume
125
125
 
126
126
    _inherit = "account.bank.statement"
127
127
 
 
128
    def _default_period(self, cr, uid, context=None):
 
129
        """
 
130
        Statement default period
 
131
        """
 
132
        if context is None:
 
133
            context = {}
 
134
        period_obj = self.pool.get('account.period')
 
135
        periods = period_obj.find(cr, uid, dt=context.get('date'), context=context)
 
136
        return periods and periods[0] or False
 
137
 
128
138
    _columns = {
129
139
        'profile_id': fields.many2one(
130
140
            'account.statement.profile',
156
166
                        store=True,
157
167
                        readonly=True),
158
168
        'period_id': fields.many2one(
159
 
            'account.period', 'Period', required=False, readonly=True),
 
169
                        'account.period',
 
170
                        'Period',
 
171
                        required=False,
 
172
                        readonly=False,
 
173
                        invisible=True),
160
174
    }
161
175
 
162
176
    _defaults = {
163
 
        'period_id': False,
 
177
        'period_id': _default_period,
164
178
    }
165
179
 
166
180
    def create(self, cr, uid, vals, context=None):
536
550
        """
537
551
        Return a period from a given date in the context.
538
552
        """
539
 
        date = context.get('date', None)
 
553
        if context is None:
 
554
            context = {}
 
555
        date = context.get('date')
540
556
        periods = self.pool.get('account.period').find(cr, uid, dt=date)
541
557
        return periods and periods[0] or False
542
558