summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2012-07-04 18:33:07 +0200
committerOlivier Dony <odo@openerp.com>2012-07-04 18:33:07 +0200
commitc2aaad1dd3164cedcd48aec4aa8d1a4e50024d8b (patch)
tree77e4c9f03f26b8d35138435dd6960326ca8f6a13
parent1e75f9db2f74823c9732fd78e2ef00bf1c1d0e54 (diff)
[FIX] OPW 576006: account.period.find() should not select opening/special periods in some cases
The cases where we filter out special periods should in fact be the default, but this is a risky change, so we turn this filtering on via an extra context flag instead, which can be added by callers as needed. bzr revid: odo@openerp.com-20120704163307-bvu454y7if8vck8j
-rw-r--r--addons/account/account.py21
-rw-r--r--addons/account/account_invoice.py3
-rw-r--r--addons/account/account_move_line.py3
3 files changed, 15 insertions, 12 deletions
diff --git a/addons/account/account.py b/addons/account/account.py
index b7c76ac892a..57e53aa55c5 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -1047,13 +1047,15 @@ class account_period(osv.osv):
else:
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
args.append(('company_id', '=', company_id))
- ids = self.search(cr, uid, args, context=context)
- if not ids:
+ result = []
+ if context.get('account_period_prefer_normal'):
+ # look for non-special periods first, and fallback to all if no result is found
+ result = self.search(cr, uid, args + [('special', '=', False)], context=context)
+ if not result:
+ result = self.search(cr, uid, args, context=context)
+ if not result:
raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create one.')%dt)
- for period in self.browse(cr, uid, ids, context=context):
- if period.date_start == period.date_stop:
- ids.remove(period.id)
- return ids
+ return result
def action_draft(self, cr, uid, ids, *args):
mode = 'draft'
@@ -1226,10 +1228,9 @@ class account_move(osv.osv):
return res
def _get_period(self, cr, uid, context=None):
- periods = self.pool.get('account.period').find(cr, uid)
- if periods:
- return periods[0]
- return False
+ ctx = dict(context or {}, account_period_prefer_normal=True)
+ period_ids = self.pool.get('account.period').find(cr, uid, context=ctx)
+ return period_ids[0]
def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
if not ids: return {}
diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py
index b7def8efde5..bbb002c232e 100644
--- a/addons/account/account_invoice.py
+++ b/addons/account/account_invoice.py
@@ -933,7 +933,8 @@ class account_invoice(osv.osv):
'narration':inv.comment
}
period_id = inv.period_id and inv.period_id.id or False
- ctx.update({'company_id': inv.company_id.id})
+ ctx.update(company_id=inv.company_id.id,
+ account_period_prefer_normal=True)
if not period_id:
period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx)
period_id = period_ids and period_ids[0] or False
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index c6182d9e61b..48726b9e522 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -952,7 +952,8 @@ class account_move_line(osv.osv):
if context is None:
context = {}
period_pool = self.pool.get('account.period')
- pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
+ ctx = dict(context, account_period_prefer_normal=True)
+ pids = period_pool.find(cr, user, date, context=ctx)
if pids:
res.update({
'period_id':pids[0]