From de19604dc0926ec4ab516b411950ac4a884c9ffa Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 13:48:51 +0100 Subject: [PATCH 1/4] [fix] on the first/last day on the year, avoid choosing the opening/closing period. --- account_statement_ext/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 80edbfcc..4c249a37 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -213,7 +213,10 @@ class AccountBankSatement(Model): """ Find matching period for date, used in the statement line creation. """ + if context is None: + context = {} period_obj = self.pool.get('account.period') + context['account_period_prefer_normal'] = True periods = period_obj.find(cr, uid, dt=date, context=context) return periods and periods[0] or False From 12c51fa3c47bf2d001ce907ea61571bfdc437ea8 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:01:20 +0100 Subject: [PATCH 2/4] [fix] copy the context before modifying it: safer upstream --- account_statement_ext/statement.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 4c249a37..e2c7cddd 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -216,8 +216,9 @@ class AccountBankSatement(Model): if context is None: context = {} period_obj = self.pool.get('account.period') - context['account_period_prefer_normal'] = True - periods = period_obj.find(cr, uid, dt=date, context=context) + local_context = context.copy() + local_context['account_period_prefer_normal'] = True + periods = period_obj.find(cr, uid, dt=date, context=local_context) return periods and periods[0] or False def _check_company_id(self, cr, uid, ids, context=None): From 0eb7bf7825c63bf6d038d72a3c11463db21ca820 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:06:24 +0100 Subject: [PATCH 3/4] [imp] docstring --- account_statement_ext/statement.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index e2c7cddd..a41038ea 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -210,9 +210,7 @@ class AccountBankSatement(Model): return super(AccountBankSatement, self).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): - """ - Find matching period for date, used in the statement line creation. - """ + """Return matching period for a date.""" if context is None: context = {} period_obj = self.pool.get('account.period') @@ -575,9 +573,7 @@ class AccountBankSatementLine(Model): _inherit = "account.bank.statement.line" def _get_period(self, cr, uid, context=None): - """ - Return a period from a given date in the context. - """ + """Return matching period for a date.""" if context is None: context = {} date = context.get('date') From 5c728ccd481c087186c5fe5470175d926b8692d7 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:11:58 +0100 Subject: [PATCH 4/4] [fix] similarly fix another _get_period --- account_statement_ext/statement.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index a41038ea..3a5a95cf 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -576,9 +576,12 @@ class AccountBankSatementLine(Model): """Return matching period for a date.""" if context is None: context = {} + period_obj = self.pool['account.period'] date = context.get('date') + local_context = context.copy() + local_context['account_period_prefer_normal'] = True try: - periods = self.pool.get('account.period').find(cr, uid, dt=date) + periods = period_obj.find(cr, uid, dt=date, context=local_context) except osv.except_osv: # if no period defined, we are certainly at installation time return False