[FIX] account* modules: added 'account_period_prefer_normal':True in context when trying to find the period related to a date.
This patch will be forward ported in trunk by changing the behaviour of account_period.find() in order to fetch the normal periods by default (account_period_prefer_normal will be True by default) because there are no business case i could think of where you'd like to get the opening period (except in the closure but it's held in a different way there). On the other hand, it's pretty easy to forget to put that key in the context and introduce a new bug that will select the opening period instead of the wanted one bzr revid: qdp-launchpad@openerp.com-20130418102433-t52uj23trkpr8vnb
This commit is contained in:
parent
56b5446431
commit
c46929268d
|
@ -1006,8 +1006,7 @@ class account_period(osv.osv):
|
|||
def find(self, cr, uid, dt=None, context=None):
|
||||
if context is None: context = {}
|
||||
if not dt:
|
||||
dt = fields.date.context_today(self,cr,uid,context=context)
|
||||
#CHECKME: shouldn't we check the state of the period?
|
||||
dt = fields.date.context_today(self, cr, uid, context=context)
|
||||
args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
|
||||
if context.get('company_id', False):
|
||||
args.append(('company_id', '=', context['company_id']))
|
||||
|
@ -1015,6 +1014,7 @@ class account_period(osv.osv):
|
|||
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
|
||||
args.append(('company_id', '=', company_id))
|
||||
result = []
|
||||
#WARNING: in next version the default value for account_periof_prefer_normal will be True
|
||||
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)
|
||||
|
@ -1167,7 +1167,7 @@ class account_move(osv.osv):
|
|||
context = {}
|
||||
#put the company in context to find the good period
|
||||
ctx = context.copy()
|
||||
ctx.update({'company_id': company_id})
|
||||
ctx.update({'company_id': company_id, 'account_period_prefer_normal': True})
|
||||
return {
|
||||
'journal_id': journal_id,
|
||||
'date': date,
|
||||
|
@ -1796,7 +1796,8 @@ class account_tax_code(osv.osv):
|
|||
if context.get('period_id', False):
|
||||
period_id = context['period_id']
|
||||
else:
|
||||
period_id = self.pool.get('account.period').find(cr, uid)
|
||||
ctx = dict(context, account_period_prefer_normal=True)
|
||||
period_id = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
if not period_id:
|
||||
return dict.fromkeys(ids, 0.0)
|
||||
period_id = period_id[0]
|
||||
|
@ -2313,7 +2314,7 @@ class account_model(osv.osv):
|
|||
move_date = datetime.strptime(move_date,"%Y-%m-%d")
|
||||
for model in self.browse(cr, uid, ids, context=context):
|
||||
ctx = context.copy()
|
||||
ctx.update({'company_id': model.company_id.id})
|
||||
ctx.update({'company_id': model.company_id.id, 'account_period_prefer_normal': True})
|
||||
period_ids = period_obj.find(cr, uid, dt=context.get('date', False), context=ctx)
|
||||
period_id = period_ids and period_ids[0] or False
|
||||
ctx.update({'journal_id': model.journal_id.id,'period_id': period_id})
|
||||
|
|
|
@ -61,7 +61,8 @@ class account_bank_statement(osv.osv):
|
|||
return res
|
||||
|
||||
def _get_period(self, cr, uid, context=None):
|
||||
periods = self.pool.get('account.period').find(cr, uid,context=context)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
if periods:
|
||||
return periods[0]
|
||||
return False
|
||||
|
@ -159,7 +160,7 @@ class account_bank_statement(osv.osv):
|
|||
if context is None:
|
||||
context = {}
|
||||
ctx = context.copy()
|
||||
ctx.update({'company_id': company_id})
|
||||
ctx.update({'company_id': company_id, 'account_period_prefer_normal': True})
|
||||
pids = period_pool.find(cr, uid, dt=date, context=ctx)
|
||||
if pids:
|
||||
res.update({'period_id': pids[0]})
|
||||
|
|
|
@ -513,7 +513,8 @@ class account_move_line(osv.osv):
|
|||
if context.get('period_id', False):
|
||||
return context['period_id']
|
||||
account_period_obj = self.pool.get('account.period')
|
||||
ids = account_period_obj.find(cr, uid, context=context)
|
||||
ctx = dict(context, account_period_prefer_normal=True)
|
||||
ids = account_period_obj.find(cr, uid, context=ctx)
|
||||
period_id = False
|
||||
if ids:
|
||||
period_id = ids[0]
|
||||
|
|
|
@ -81,7 +81,8 @@ class account_entries_report(osv.osv):
|
|||
period_obj = self.pool.get('account.period')
|
||||
for arg in args:
|
||||
if arg[0] == 'period_id' and arg[2] == 'current_period':
|
||||
current_period = period_obj.find(cr, uid)[0]
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
current_period = period_obj.find(cr, uid, context=ctx)[0]
|
||||
args.append(['period_id','in',[current_period]])
|
||||
break
|
||||
elif arg[0] == 'period_id' and arg[2] == 'current_year':
|
||||
|
@ -100,7 +101,8 @@ class account_entries_report(osv.osv):
|
|||
fiscalyear_obj = self.pool.get('account.fiscalyear')
|
||||
period_obj = self.pool.get('account.period')
|
||||
if context.get('period', False) == 'current_period':
|
||||
current_period = period_obj.find(cr, uid)[0]
|
||||
ctx = dict(context, account_period_prefer_normal=True)
|
||||
current_period = period_obj.find(cr, uid, context=ctx)[0]
|
||||
domain.append(['period_id','in',[current_period]])
|
||||
elif context.get('year', False) == 'current_year':
|
||||
current_year = fiscalyear_obj.find(cr, uid)
|
||||
|
|
|
@ -84,7 +84,8 @@ class account_move_line_reconcile(osv.osv_memory):
|
|||
context = {}
|
||||
|
||||
date = time.strftime('%Y-%m-%d')
|
||||
ids = period_obj.find(cr, uid, dt=date, context=context)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
ids = period_obj.find(cr, uid, dt=date, context=ctx)
|
||||
if ids:
|
||||
period_id = ids[0]
|
||||
account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
|
||||
|
@ -149,7 +150,7 @@ class account_move_line_reconcile_writeoff(osv.osv_memory):
|
|||
context['analytic_id'] = data['analytic_id'][0]
|
||||
if context['date_p']:
|
||||
date = context['date_p']
|
||||
|
||||
context['account_period_prefer_normal'] = True
|
||||
ids = period_obj.find(cr, uid, dt=date, context=context)
|
||||
if ids:
|
||||
period_id = ids[0]
|
||||
|
|
|
@ -38,7 +38,8 @@ class account_tax_chart(osv.osv_memory):
|
|||
|
||||
def _get_period(self, cr, uid, context=None):
|
||||
"""Return default period value"""
|
||||
period_ids = self.pool.get('account.period').find(cr, uid)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
period_ids = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
return period_ids and period_ids[0] or False
|
||||
|
||||
def account_tax_chart_open_window(self, cr, uid, ids, context=None):
|
||||
|
|
|
@ -83,7 +83,8 @@ class account_asset_asset(osv.osv):
|
|||
return super(account_asset_asset, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
def _get_period(self, cr, uid, context=None):
|
||||
periods = self.pool.get('account.period').find(cr, uid)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
if periods:
|
||||
return periods[0]
|
||||
else:
|
||||
|
@ -399,7 +400,8 @@ class account_asset_depreciation_line(osv.osv):
|
|||
asset_ids = []
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
depreciation_date = context.get('depreciation_date') or time.strftime('%Y-%m-%d')
|
||||
period_ids = period_obj.find(cr, uid, depreciation_date, context=context)
|
||||
ctx = dict(context, account_period_prefer_normal=True)
|
||||
period_ids = period_obj.find(cr, uid, depreciation_date, context=ctx)
|
||||
company_currency = line.asset_id.company_id.currency_id.id
|
||||
current_currency = line.asset_id.currency_id.id
|
||||
context.update({'date': depreciation_date})
|
||||
|
|
|
@ -30,7 +30,8 @@ class asset_depreciation_confirmation_wizard(osv.osv_memory):
|
|||
}
|
||||
|
||||
def _get_period(self, cr, uid, context=None):
|
||||
periods = self.pool.get('account.period').find(cr, uid)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
if periods:
|
||||
return periods[0]
|
||||
return False
|
||||
|
|
|
@ -86,7 +86,8 @@ class account_voucher(osv.osv):
|
|||
if context is None: context = {}
|
||||
if context.get('period_id', False):
|
||||
return context.get('period_id')
|
||||
periods = self.pool.get('account.period').find(cr, uid)
|
||||
ctx = dict(context, account_period_prefer_normal=True)
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=ctx)
|
||||
return periods and periods[0] or False
|
||||
|
||||
def _make_journal_search(self, cr, uid, ttype, context=None):
|
||||
|
@ -791,7 +792,7 @@ class account_voucher(osv.osv):
|
|||
period_pool = self.pool.get('account.period')
|
||||
currency_obj = self.pool.get('res.currency')
|
||||
ctx = context.copy()
|
||||
ctx.update({'company_id': company_id})
|
||||
ctx.update({'company_id': company_id, 'account_period_prefer_normal': True})
|
||||
pids = period_pool.find(cr, uid, date, context=ctx)
|
||||
if pids:
|
||||
res['value'].update({'period_id':pids[0]})
|
||||
|
|
|
@ -94,7 +94,8 @@ class hr_payslip(osv.osv):
|
|||
debit_sum = 0.0
|
||||
credit_sum = 0.0
|
||||
if not slip.period_id:
|
||||
search_periods = period_pool.find(cr, uid, slip.date_to, context=context)
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
search_periods = period_pool.find(cr, uid, slip.date_to, context=ctx)
|
||||
period_id = search_periods[0]
|
||||
else:
|
||||
period_id = slip.period_id.id
|
||||
|
|
|
@ -911,7 +911,8 @@ class pos_order(osv.osv):
|
|||
property_obj = self.pool.get('ir.property')
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
|
||||
period = account_period_obj.find(cr, uid, context=context)[0]
|
||||
ctx = dict(context or {}, account_period_prefer_normal=True)
|
||||
period = account_period_obj.find(cr, uid, context=ctx)[0]
|
||||
|
||||
#session_ids = set(order.session_id for order in self.browse(cr, uid, ids, context=context))
|
||||
|
||||
|
|
Loading…
Reference in New Issue