[IMP] account: use DEFAULT_SERVER_DATETIME_FORMAT and merging in one method

bzr revid: mat@openerp.com-20130508125520-kf0pbgfislf34vay
This commit is contained in:
Martin Trigaux 2013-05-08 14:55:20 +02:00
parent f2c5aee290
commit e15811a6a1
1 changed files with 10 additions and 31 deletions

View File

@ -133,42 +133,20 @@ class account_config_settings(osv.osv_memory):
count = self.pool.get('res.company').search_count(cr, uid, [], context=context)
return bool(count == 1)
def _default_start_date(self, cr, uid, context=None):
"""Compute default starting date for fiscalyear
def _get_default_fiscalyear_dates(self, cr, uid, company_id, context=None):
"""Compute default starting and ending date for fiscalyear
- if no fiscal year, use 1st jan of this year
- if in a fiscal year, use its starting date
- if past fiscal year, use the ending date of the latest +1 day
:return: (date_start, date_stop) at format DEFAULT_SERVER_DATETIME_FORMAT
"""
company_id = self._default_company(cr, uid, context=context)
fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
[('date_start', '<=', time.strftime(DF)), ('date_stop', '>=', time.strftime(DF)),
('company_id', '=', company_id)])
if fiscalyear_ids:
# has a current fiscal year, use this one
return self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context).date_start
else:
past_fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
[('date_stop', '<=', time.strftime(DF)), ('company_id', '=', company_id)])
if past_fiscalyear_ids:
# use the latest fiscal year+1 day, sorted by start_date
latest_stop = self.pool.get('account.fiscalyear').browse(cr, uid, past_fiscalyear_ids[-1], context=context).date_stop
return (datetime.datetime.strptime(latest_stop, DF) + datetime.timedelta(days=1)).strftime(DF)
else:
return time.strftime('%Y-01-01')
def _default_stop_date(self, cr, uid, context=None):
"""Compute default ending date for fiscalyear
- if no fiscal year, use 31th dec of this year
- if in a fiscal year, use its ending date
- if past fiscal year, use the ending date of latest fiscalyear +1 year
"""
company_id = self._default_company(cr, uid, context=context)
fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
[('date_start', '<=', time.strftime(DF)), ('date_stop', '>=', time.strftime(DF)),
('company_id', '=', company_id)])
if fiscalyear_ids:
# has a current fiscal year, use this one
return self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context).date_stop
fiscalyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context)
return (fiscalyear.date_start, fiscalyear.date_stop)
else:
past_fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
[('date_stop', '<=', time.strftime(DF)), ('company_id', '=', company_id)])
@ -176,16 +154,14 @@ class account_config_settings(osv.osv_memory):
# use the latest fiscal year+1 day, sorted by start_date
latest_year = self.pool.get('account.fiscalyear').browse(cr, uid, past_fiscalyear_ids[-1], context=context)
latest_stop = datetime.datetime.strptime(latest_year.date_stop, DF)
return latest_stop.replace(year=latest_stop.year+1).strftime(DF)
return ((latest_stop+datetime.timedelta(days=1)).strftime(DF), latest_stop.replace(year=latest_stop.year+1).strftime(DF))
else:
return time.strftime('%Y-12-31')
return (time.strftime('%Y-01-01'), time.strftime('%Y-12-31'))
_defaults = {
'company_id': _default_company,
'has_default_company': _default_has_default_company,
'date_start': _default_start_date,
'date_stop': _default_stop_date,
'period': 'month',
}
@ -210,6 +186,7 @@ class account_config_settings(osv.osv_memory):
fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
[('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
('company_id', '=', company_id)])
date_start, date_stop = self._get_default_fiscalyear_dates(cr, uid, company_id, context=context)
values = {
'expects_chart_of_accounts': company.expects_chart_of_accounts,
'currency_id': company.currency_id.id,
@ -219,6 +196,8 @@ class account_config_settings(osv.osv_memory):
'has_fiscal_year': bool(fiscalyear_count),
'chart_template_id': False,
'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
'date_start': date_start,
'date_stop': date_stop,
}
# update journals and sequences
for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):