[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
This commit is contained in:
parent
1e75f9db2f
commit
c2aaad1dd3
|
@ -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 {}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue