[IMP, ADD] account:Improve the logic to create period so it can create one more period and add two journals for opening entries

bzr revid: psi@tinyerp.co.in-20110128105818-ptd5vk4xsaowmnec
This commit is contained in:
psi (Open ERP) 2011-01-28 16:28:18 +05:30
parent e45d6bbe05
commit 18bcd1c980
5 changed files with 90 additions and 7 deletions

View File

@ -805,19 +805,28 @@ class account_fiscalyear(osv.osv):
(_check_fiscal_year, 'Error! You cannot define overlapping fiscal years',['date_start', 'date_stop'])
]
def create_period3(self,cr, uid, ids, context=None):
def create_period3(self, cr, uid, ids, context=None):
return self.create_period(cr, uid, ids, context, 3)
def create_period(self,cr, uid, ids, context=None, interval=1):
def create_period(self, cr, uid, ids, context=None, interval=1):
period_obj = self.pool.get('account.period')
for fy in self.browse(cr, uid, ids, context=context):
ds = datetime.strptime(fy.date_start, '%Y-%m-%d')
while ds.strftime('%Y-%m-%d')<fy.date_stop:
period_obj.create(cr, uid, {
'name': 'Opening Period',
'code': ds.strftime('00/%Y'),
'date_start': ds + relativedelta(years=-1, days=-1),
'date_stop': ds + relativedelta(years=-1),
'special': True,
'fiscalyear_id': fy.id,
})
while ds.strftime('%Y-%m-%d') < fy.date_stop:
de = ds + relativedelta(months=interval, days=-1)
if de.strftime('%Y-%m-%d')>fy.date_stop:
if de.strftime('%Y-%m-%d') > fy.date_stop:
de = datetime.strptime(fy.date_stop, '%Y-%m-%d')
self.pool.get('account.period').create(cr, uid, {
period_obj.create(cr, uid, {
'name': ds.strftime('%m/%Y'),
'code': ds.strftime('%m/%Y'),
'date_start': ds.strftime('%Y-%m-%d'),
@ -2449,6 +2458,8 @@ class account_chart_template(osv.osv):
'property_account_expense': fields.many2one('account.account.template','Expense Account on Product Template'),
'property_account_income': fields.many2one('account.account.template','Income Account on Product Template'),
'property_reserve_and_surplus_account': fields.many2one('account.account.template', 'Reserve and Profit/Loss Account', domain=[('type', '=', 'payable')], help='This Account is used for transferring Profit/Loss(If It is Profit: Amount will be added, Loss: Amount will be deducted.), Which is calculated from Profilt & Loss Report'),
'property_account_income_opening': fields.many2one('account.account.template','Opening Entries Income Account'),
'property_account_expense_opening': fields.many2one('account.account.template','Opening Entries Expense Account'),
}
account_chart_template()
@ -2681,6 +2692,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
obj_data = self.pool.get('ir.model.data')
analytic_journal_obj = self.pool.get('account.analytic.journal')
obj_tax_code = self.pool.get('account.tax.code')
obj_tax_code_template = self.pool.get('account.tax.code.template')
# Creating Account
obj_acc_root = obj_multi.chart_template_id.account_root_id
tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id
@ -2693,9 +2705,9 @@ class wizard_multi_charts_accounts(osv.osv_memory):
todo_dict = {}
#create all the tax code
children_tax_code_template = self.pool.get('account.tax.code.template').search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
children_tax_code_template = obj_tax_code_template.search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
children_tax_code_template.sort()
for tax_code_template in self.pool.get('account.tax.code.template').browse(cr, uid, children_tax_code_template, context=context):
for tax_code_template in obj_tax_code_template.browse(cr, uid, children_tax_code_template, context=context):
vals={
'name': (tax_code_root_id == tax_code_template.id) and obj_multi.company_id.name or tax_code_template.name,
'code': tax_code_template.code,
@ -2806,11 +2818,15 @@ class wizard_multi_charts_accounts(osv.osv_memory):
seq_id_purchase_refund = obj_sequence.search(cr, uid, [('name','=','Purchase Refund Journal')])
if seq_id_purchase_refund:
seq_id_purchase_refund = seq_id_purchase_refund[0]
seq_id_opening = obj_sequence.search(cr, uid, [('name','=','Opening Entries Journal')])
if seq_id_opening:
seq_id_opening = seq_id_opening[0]
else:
seq_id_sale = seq_id
seq_id_purchase = seq_id
seq_id_sale_refund = seq_id
seq_id_purchase_refund = seq_id
seq_id_opening = seq_id
vals_journal['view_id'] = view_id
@ -2903,6 +2919,21 @@ class wizard_multi_charts_accounts(osv.osv_memory):
# })
obj_journal.create(cr, uid, vals_journal, context=context)
# Opening Entries Journal
if obj_multi.chart_template_id.property_account_income_opening and obj_multi.chart_template_id.property_account_expense_opening:
vals_journal = {
'view_id': view_id,
'name': _('Opening Entries Journal'),
'type': 'situation',
'code': _('TOEJ'),
'sequence_id': seq_id_opening,
'analytic_journal_id': analitical_journal_purchase,
'company_id': company_id,
'default_credit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_income_opening.id],
'default_debit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_expense_opening.id]
}
obj_journal.create(cr, uid, vals_journal, context=context)
# Bank Journals
data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')])
data = obj_data.browse(cr, uid, data_id[0], context=context)

View File

@ -2150,6 +2150,8 @@
<field name="property_account_income_categ" domain="[('id', 'child_of', [account_root_id])]" />
<field name="property_account_expense" domain="[('id', 'child_of', [account_root_id])]"/>
<field name="property_account_income" domain="[('id', 'child_of', [account_root_id])]"/>
<field name="property_account_income_opening" domain="[('id', 'child_of', [account_root_id])]"/>
<field name="property_account_expense_opening" domain="[('id', 'child_of', [account_root_id])]"/>
<field name="property_reserve_and_surplus_account" />
</group>
</form>

View File

@ -191,6 +191,14 @@
<field name="user_type" ref="conf_account_type_asset"/>
</record>
<record id="conf_o_income" model="account.account.template">
<field name="code">1106</field>
<field name="name">Opening Income Account</field>
<field ref="conf_cas" name="parent_id"/>
<field name="type">closed</field>
<field name="user_type" ref="conf_account_type_income"/>
</record>
<record id="conf_cli" model="account.account.template">
<field name="code">111</field>
<field name="name">Current Liabilities</field>
@ -225,6 +233,13 @@
<field name="user_type" ref="conf_account_type_liability"/>
</record>
<record id="conf_o_expense" model="account.account.template">
<field name="code">1114</field>
<field name="name">Opening Expense Account</field>
<field ref="conf_cli" name="parent_id"/>
<field name="type">closed</field>
<field name="user_type" ref="conf_account_type_expense"/>
</record>
<!-- Profit and Loss -->
@ -431,6 +446,8 @@
<field name="property_account_payable" ref="conf_a_pay"/>
<field name="property_account_expense_categ" ref="conf_a_expense"/>
<field name="property_account_income_categ" ref="conf_a_sale"/>
<field name="property_account_income_opening" ref="conf_o_income"/>
<field name="property_account_expense_opening" ref="conf_o_expense"/>
<field name="property_reserve_and_surplus_account" ref="conf_a_reserve_and_surplus"/>
</record>

View File

@ -421,6 +421,15 @@
<field name="analytic_journal_id" ref="sit"/>
<field name="user_id" ref="base.user_root"/>
</record>
<record id="miscellaneous_journal" model="account.journal">
<field name="name">Miscellaneous Journal - (test)</field>
<field name="code">TMIS</field>
<field name="type">general</field>
<field name="view_id" ref="account_journal_bank_view"/>
<field name="sequence_id" ref="sequence_journal"/>
<field name="analytic_journal_id" ref="sit"/>
<field name="user_id" ref="base.user_root"/>
</record>
<!--
Product income and expense accounts, default parameters

View File

@ -416,11 +416,20 @@ class account_installer(osv.osv_memory):
'company_id': company_id.id
}
seq_id_purchase_refund = obj_sequence.create(cr, uid, seq_refund_purchase, context=context)
seq_opening_journal = {
'name': 'Opening Entries Journal',
'code': 'account.journal',
'prefix': 'TOEJ/%(year)s/',
'padding': 3,
'company_id': company_id.id
}
seq_id_opening = obj_sequence.create(cr, uid, seq_opening_journal, context=context)
else:
seq_id_sale = seq_id
seq_id_purchase = seq_id
seq_id_sale_refund = seq_id
seq_id_purchase_refund = seq_id
seq_id_opening = seq_id
vals_journal['view_id'] = view_id
@ -508,6 +517,21 @@ class account_installer(osv.osv_memory):
})
obj_journal.create(cr, uid, vals_journal, context=context)
# Opening Entries Journal
if obj_multi.property_account_income_opening and obj_multi.property_account_expense_opening:
vals_journal = {
'view_id': view_id,
'name': _('Opening Entries Journal'),
'type': 'situation',
'code': _('TOEJ'),
'sequence_id': seq_id_opening,
'analytic_journal_id': analitical_journal_purchase,
'company_id': company_id.id,
'default_credit_account_id': acc_template_ref[obj_multi.property_account_income_opening.id],
'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_opening.id]
}
obj_journal.create(cr, uid, vals_journal, context=context)
# Bank Journals
view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #TOFIX: Why put fixed name ?
view_id_cur = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal (Multi-Currency) View')], context=context)[0] #TOFIX: why put fixed name?