diff --git a/addons/account/account.py b/addons/account/account.py index 95b32eac17f..9d64d291a91 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -568,6 +568,15 @@ class account_journal_period(osv.osv): account_journal_period() +class account_fiscalyear(osv.osv): + _inherit = "account.fiscalyear" + _description = "Fiscal Year" + _columns = { + 'start_journal_period_id':fields.many2one('account.journal.period','New Entries Journal'), + 'end_journal_period_id':fields.many2one('account.journal.period','End of Year Entries Journal', readonly=True), + } + +account_fiscalyear() #---------------------------------------------------------- # Entries #---------------------------------------------------------- diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index a0388bab89a..70cf9dfb613 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -19,6 +19,8 @@ + +
diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml index dd27b2c5935..56b47cb7b25 100644 --- a/addons/account/account_wizard.xml +++ b/addons/account/account_wizard.xml @@ -24,17 +24,31 @@ + + + - @@ -47,7 +46,6 @@ _transaction_fields = { 'fy2_id': {'string':'New Fiscal Year', 'type':'many2one', 'relation': 'account.fiscalyear', 'domain':[('state','=','draft')], 'required':True}, 'report_new': {'string':'Create new entries', 'type':'boolean', 'required':True, 'default': lambda *a:True}, 'report_name': {'string':'Name of new entries', 'type':'char', 'size': 64, 'required':True}, - 'report_journal': {'string':'New Entries Journal', 'type':'many2one', 'relation': 'account.journal', 'required':True}, 'sure': {'string':'Check this box', 'type':'boolean'}, } @@ -64,13 +62,21 @@ def _data_save(self, cr, uid, data, context): fy_id = data['form']['fy_id'] if data['form']['report_new']: period = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id']).period_ids[0] - journal = pool.get('account.journal').browse(cr, uid, data['form']['report_journal']) - if not journal.default_credit_account_id or not journal.default_debit_account_id: + new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id']) + start_jp = new_fyear.start_journal_period_id + if not start_jp: + raise wizard.except_wizard('UserError', + 'The new fiscal year should have a journal for new entries define on it') + + new_journal = start_jp.journal_id + + if not new_journal.default_credit_account_id or not new_journal.default_debit_account_id: raise wizard.except_wizard('UserError', 'The journal must have default credit and debit account') - if not journal.centralisation: + if not new_journal.centralisation: raise wizard.except_wizard('UserError', 'The journal must have centralised counterpart') + query_line = pool.get('account.move.line')._query_get(cr, uid, obj='account_move_line', context={'fiscalyear': fy_id}) cr.execute('select id from account_account WHERE active') @@ -86,10 +92,10 @@ def _data_save(self, cr, uid, data, context): 'credit': account.balance<0 and -account.balance, 'name': data['form']['report_name'], 'date': period.date_start, - 'journal_id': data['form']['report_journal'], + 'journal_id': new_journal.id, 'period_id': period.id, 'account_id': account.id - }, {'journal_id': data['form']['report_journal'], 'period_id':period.id}) + }, {'journal_id': new_journal.id, 'period_id':period.id}) if account.close_method=='unreconciled': offset = 0 limit = 100 @@ -109,11 +115,11 @@ def _data_save(self, cr, uid, data, context): for move in result: move.update({ 'date': period.date_start, - 'journal_id': data['form']['report_journal'], + 'journal_id': new_journal.id, 'period_id': period.id, }) pool.get('account.move.line').create(cr, uid, move, { - 'journal_id': data['form']['report_journal'], + 'journal_id': new_journal.id, 'period_id': period.id, }) offset += limit @@ -135,7 +141,7 @@ def _data_save(self, cr, uid, data, context): for move in result: move.update({ 'date': period.date_start, - 'journal_id': data['form']['report_journal'], + 'journal_id': new_journal.id, 'period_id': period.id, }) pool.get('account.move.line').create(cr, uid, move) @@ -148,8 +154,8 @@ def _data_save(self, cr, uid, data, context): cr.execute('UPDATE account_period SET state = %s ' \ 'WHERE fiscalyear_id = %d', ('done',fy_id)) cr.execute('UPDATE account_fiscalyear ' \ - 'SET state = %s ' \ - 'WHERE id = %d', ('done',fy_id)) + 'SET state = %s, end_journal_period_id = %d' \ + 'WHERE id = %d', ('done',start_jp,fy_id)) return {} class wiz_journal_close(wizard.interface): diff --git a/addons/account/wizard/wizard_open_closed_fiscalyear.py b/addons/account/wizard/wizard_open_closed_fiscalyear.py new file mode 100644 index 00000000000..bfaed974e48 --- /dev/null +++ b/addons/account/wizard/wizard_open_closed_fiscalyear.py @@ -0,0 +1,53 @@ +import wizard +import netsvc +import pooler +from osv import fields, osv + +form = """ + + + +""" + +fields = { + 'fyear_id': {'string': 'Fiscal Year to Open', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True}, +} + +def _remove_entries(self, cr, uid, data, context): + pool = pooler.get_pool(cr.dbname) + data_fyear = pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear_id']) + if not data_fyear.end_journal_period_id: + raise wizard.except_wizard('Error', 'No journal for ending writings have been defined for the fiscal year') + period_journal = data_fyear.end_journal_period_id + if not period_journal.journal_id.centralisation: + raise wizard.except_wizard('UserError', 'The journal must have centralised counterpart') + ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)]) + pool.get('account.move').unlink(cr,uid,ids_move) + cr.execute('UPDATE account_period SET state = %s ' \ + 'WHERE fiscalyear_id = %d', ('draft',data_fyear)) + cr.execute('UPDATE account_fiscalyear ' \ + 'SET state = %s, end_journal_period_id = null '\ + 'WHERE id = %d', ('draft',data_fyear)) + return {} + +class open_closed_fiscal(wizard.interface): + states = { + 'init' : { + 'actions' : [], + 'result': { + 'type': 'form', + 'arch': form, + 'fields': fields, + 'state':[('end','Cancel'),('open','Open')] + } + }, + 'open': { + 'actions': [], + 'result': { + 'type':'action', + 'action':_remove_entries, + 'state':'end' + }, + }, + } +open_closed_fiscal("account.open_closed_fiscalyear")