← Back to team overview

banking-addons-team team mailing list archive

lp:~therp-nl/banking-addons/ba70-lp1231174-default_method_should_not_raise_at_module_installation_time into lp:banking-addons

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/banking-addons/ba70-lp1231174-default_method_should_not_raise_at_module_installation_time into lp:banking-addons.

Requested reviews:
  Banking Addons Core Editors (banking-addons-team)
Related bugs:
  Bug #1231174 in Banking Addons: "Can't install module account_banking with new DB"
  https://bugs.launchpad.net/banking-addons/+bug/1231174

For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/ba70-lp1231174-default_method_should_not_raise_at_module_installation_time/+merge/187677
-- 
https://code.launchpad.net/~therp-nl/banking-addons/ba70-lp1231174-default_method_should_not_raise_at_module_installation_time/+merge/187677
Your team Banking Addons Core Editors is requested to review the proposed merge of lp:~therp-nl/banking-addons/ba70-lp1231174-default_method_should_not_raise_at_module_installation_time into lp:banking-addons.
=== modified file 'account_banking/account_banking.py'
--- account_banking/account_banking.py	2013-06-25 15:40:51 +0000
+++ account_banking/account_banking.py	2013-09-26 07:03:25 +0000
@@ -63,6 +63,7 @@
 '''
 
 from openerp.osv import orm, fields
+from openerp.osv.osv import except_osv
 from openerp.tools.translate import _
 from openerp import netsvc, SUPERUSER_ID
 from openerp.addons.decimal_precision import decimal_precision as dp
@@ -468,9 +469,27 @@
     _description = 'Bank Transaction'
 
     def _get_period(self, cr, uid, context=None):
-        date = context.get('date', None)
-        periods = self.pool.get('account.period').find(cr, uid, dt=date)
-        return periods and periods[0] or False
+        """
+        Get a non-opening period for today or a date specified in
+        the context.
+
+        Used in this model's _defaults, so it is always triggered
+        on installation or module upgrade. For that reason, we need
+        to be tolerant and allow for the situation in which no period
+        exists for the current date (i.e. when no date is specified).
+        """
+        if context is None:
+            context = {}
+        date = context.get('date', False)
+        local_ctx = dict(context)
+        local_ctx['account_period_prefer_normal'] = True
+        try:
+            return self.pool.get('account.period').find(
+                cr, uid, dt=date, context=local_ctx)[0]
+        except except_osv:
+            if date:
+                raise
+        return False
 
     def _get_currency(self, cr, uid, context=None):
         '''


Follow ups