[IMP] account: compute default period for fiscal year
bzr revid: mat@openerp.com-20130508131438-nyzi49wbn61giecf
This commit is contained in:
parent
e15811a6a1
commit
b9ee794a2b
|
@ -133,36 +133,43 @@ class account_config_settings(osv.osv_memory):
|
|||
count = self.pool.get('res.company').search_count(cr, uid, [], context=context)
|
||||
return bool(count == 1)
|
||||
|
||||
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
|
||||
def _get_default_fiscalyear_data(self, cr, uid, company_id, context=None):
|
||||
"""Compute default period, starting and ending date for fiscalyear
|
||||
- if in a fiscal year, use its period, starting and ending date
|
||||
- if past fiscal year, use its period, and new dates [ending date of the latest +1 day ; ending date of the latest +1 year]
|
||||
- if no fiscal year, use monthly, 1st jan, 31th dec of this year
|
||||
:return: (date_start, date_stop, period) at format DEFAULT_SERVER_DATETIME_FORMAT
|
||||
"""
|
||||
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
|
||||
# is in a current fiscal year, use this one
|
||||
fiscalyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context)
|
||||
return (fiscalyear.date_start, fiscalyear.date_stop)
|
||||
if len(fiscalyear.period_ids) == 5: # 4 periods of 3 months + opening period
|
||||
period = '3months'
|
||||
else:
|
||||
period = 'month'
|
||||
return (fiscalyear.date_start, fiscalyear.date_stop, period)
|
||||
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
|
||||
# use the latest fiscal, sorted by (start_date, id)
|
||||
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+datetime.timedelta(days=1)).strftime(DF), latest_stop.replace(year=latest_stop.year+1).strftime(DF))
|
||||
if len(latest_year.period_ids) == 5:
|
||||
period = '3months'
|
||||
else:
|
||||
period = 'month'
|
||||
return ((latest_stop+datetime.timedelta(days=1)).strftime(DF), latest_stop.replace(year=latest_stop.year+1).strftime(DF), period)
|
||||
else:
|
||||
return (time.strftime('%Y-01-01'), time.strftime('%Y-12-31'))
|
||||
return (time.strftime('%Y-01-01'), time.strftime('%Y-12-31'), 'month')
|
||||
|
||||
|
||||
_defaults = {
|
||||
'company_id': _default_company,
|
||||
'has_default_company': _default_has_default_company,
|
||||
'period': 'month',
|
||||
}
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
|
@ -186,7 +193,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)
|
||||
date_start, date_stop, period = self._get_default_fiscalyear_data(cr, uid, company_id, context=context)
|
||||
values = {
|
||||
'expects_chart_of_accounts': company.expects_chart_of_accounts,
|
||||
'currency_id': company.currency_id.id,
|
||||
|
@ -198,6 +205,7 @@ class account_config_settings(osv.osv_memory):
|
|||
'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
|
||||
'date_start': date_start,
|
||||
'date_stop': date_stop,
|
||||
'period': period,
|
||||
}
|
||||
# update journals and sequences
|
||||
for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
|
||||
|
|
Loading…
Reference in New Issue