from operator import itemgetter
from os.path import join as opj
-from tools.translate import _
-from osv import osv, fields
-import tools
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF
+from openerp.tools.translate import _
+from openerp.osv import fields, osv
+from openerp import tools
class account_config_settings(osv.osv_memory):
_name = 'account.config.settings'
'module_account_check_writing': fields.boolean('Pay your suppliers by check',
help="""This allows you to check writing and printing.
-This installs the module account_check_writing."""),
+ This installs the module account_check_writing."""),
'module_account_accountant': fields.boolean('Full accounting features: journals, legal statements, chart of accounts, etc.',
help="""If you do not check this box, you will be able to do invoicing & payments, but not accounting (Journal Items, Chart of Accounts, ...)"""),
'module_account_asset': fields.boolean('Assets management',
help="""This allows you to manage the assets owned by a company or a person.
-It keeps track of the depreciation occurred on those assets, and creates account move for those depreciation lines.
-This installs the module account_asset. If you do not check this box, you will be able to do invoicing & payments, but not accounting (Journal Items, Chart of Accounts, ...)"""),
+ It keeps track of the depreciation occurred on those assets, and creates account move for those depreciation lines.
+ This installs the module account_asset. If you do not check this box, you will be able to do invoicing & payments,
+ but not accounting (Journal Items, Chart of Accounts, ...)"""),
'module_account_budget': fields.boolean('Budget management',
help="""This allows accountants to manage analytic and crossovered budgets.
-Once the master budgets and the budgets are defined, the project managers
-can set the planned amount on each analytic account.
-This installs the module account_budget."""),
+ Once the master budgets and the budgets are defined,
+ the project managers can set the planned amount on each analytic account.
+ This installs the module account_budget."""),
'module_account_payment': fields.boolean('Manage payment orders',
help="""This allows you to create and manage your payment orders, with purposes to
-* serve as base for an easy plug-in of various automated payment mechanisms, and
-* provide a more efficient way to manage invoice payments.
-This installs the module account_payment."""),
+ * serve as base for an easy plug-in of various automated payment mechanisms, and
+ * provide a more efficient way to manage invoice payments.
+ This installs the module account_payment."""),
'module_account_voucher': fields.boolean('Manage customer payments',
help="""This includes all the basic requirements of voucher entries for bank, cash, sales, purchase, expense, contra, etc.
-This installs the module account_voucher."""),
+ This installs the module account_voucher."""),
'module_account_followup': fields.boolean('Manage customer payment follow-ups',
help="""This allows to automate letters for unpaid invoices, with multi-level recalls.
-This installs the module account_followup."""),
+ This installs the module account_followup."""),
'group_proforma_invoices': fields.boolean('Allow pro-forma invoices',
implied_group='account.group_proforma_invoices',
help="Allows you to put invoices in pro-forma state."),
count = self.pool.get('res.company').search_count(cr, uid, [], context=context)
return bool(count == 1)
+ 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:
+ # is in a current fiscal year, use this one
+ fiscalyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context)
+ 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, 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)
+ 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'), 'month')
+
+
_defaults = {
'company_id': _default_company,
'has_default_company': _default_has_default_company,
- 'date_start': lambda *a: time.strftime('%Y-01-01'),
- 'date_stop': lambda *a: time.strftime('%Y-12-31'),
- 'period': 'month',
}
def create(self, cr, uid, values, context=None):
self.write(cr, uid, [id], vals, context)
return id
- def onchange_company_id(self, cr, uid, ids, company_id):
+ def onchange_company_id(self, cr, uid, ids, company_id, context=None):
# update related fields
values = {}
values['currency_id'] = False
if company_id:
- company = self.pool.get('res.company').browse(cr, uid, company_id)
+ company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
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, 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,
'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,
+ 'period': period,
}
# update journals and sequences
for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):