*added the wizard for reopenning a closed fiscal year.
bzr revid: qdp-715a579b63f8382f24c121898102e879ab56b8cd
This commit is contained in:
parent
b75d700a0b
commit
5571c6b405
|
@ -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
|
||||
#----------------------------------------------------------
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
<field name="code" select="1"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_stop"/>
|
||||
<field name="start_journal_period_id"/>
|
||||
<field name="end_journal_period_id"/>
|
||||
<separator string="Periods" colspan="4"/>
|
||||
<field name="period_ids" colspan="4" widget="one2many_list" nolable="1">
|
||||
<form string="Period">
|
||||
|
|
|
@ -24,17 +24,31 @@
|
|||
|
||||
<!-- close year, period, journal -->
|
||||
<wizard
|
||||
string="Close a fiscal year"
|
||||
string="Close a Fiscal Year"
|
||||
model="account.fiscalyear"
|
||||
name="account.fiscalyear.close"
|
||||
menu="False"
|
||||
id="wizard_fiscalyear_close"/>
|
||||
<menuitem
|
||||
name="Financial Management/End of Year Treatments/Close a Fiscal Year"
|
||||
sequence="11"
|
||||
action="wizard_fiscalyear_close"
|
||||
type="wizard"
|
||||
id="menu_wizard_fy_close"/>
|
||||
|
||||
<wizard
|
||||
string="Open a Closed Fiscal Year"
|
||||
model="account.fiscalyear"
|
||||
name="account.open_closed_fiscalyear"
|
||||
menu="False"
|
||||
id="wizard_open_closed_fiscalyear"/>
|
||||
<menuitem
|
||||
name="Financial Management/End of Year Treatments/Open a Closed Fiscal Year"
|
||||
sequence="12"
|
||||
action="wizard_open_closed_fiscalyear"
|
||||
type="wizard"
|
||||
id="menu_wizard_open_closed_fy"/>
|
||||
|
||||
<wizard
|
||||
string="Close Period"
|
||||
model="account.period"
|
||||
|
|
|
@ -49,6 +49,7 @@ import wizard_partner_balance_report
|
|||
|
||||
import wizard_period_close
|
||||
import wizard_fiscalyear_close
|
||||
import wizard_open_closed_fiscalyear
|
||||
|
||||
import wizard_vat
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ _transaction_form = '''<?xml version="1.0"?>
|
|||
<field name="fy2_id"/>
|
||||
<field name="report_new"/>
|
||||
<field name="report_name" colspan="3"/>
|
||||
<field name="report_journal" colspan="3"/>
|
||||
|
||||
<separator string="Are you sure ?" colspan="4"/>
|
||||
<field name="sure"/>
|
||||
|
@ -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):
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import wizard
|
||||
import netsvc
|
||||
import pooler
|
||||
from osv import fields, osv
|
||||
|
||||
form = """<?xml version="1.0"?>
|
||||
<form string="Choose Fiscal Year">
|
||||
<field name="fyear_id" domain="[('state','=','done')]"/>
|
||||
</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")
|
Loading…
Reference in New Issue