[IMP] account:

* Replaced the current selection field (P&L/BS Category on account type) by a functional field that will simulate the old behavior (for the user it will be the same) but that will read and write into the m2m field between financial reports and account types

bzr revid: uco@tinyerp.com-20111201100420-jsw584v4lemuzhca
This commit is contained in:
Ujjvala Collins (OpenERP) 2011-12-01 15:34:20 +05:30
parent bf578591fe
commit 0920c044fd
2 changed files with 55 additions and 15 deletions

View File

@ -130,6 +130,21 @@ account_payment_term_line()
class account_account_type(osv.osv):
_name = "account.account.type"
_description = "Account Type"
def _get_report_type(self, cr, uid, context=None):
report_obj = self.pool.get('account.financial.report')
report_ids = report_obj.search(cr, uid, [], context=context)
report_type = [('none','/')]
for report in report_obj.browse(cr, uid, report_ids, context=context):
type = report.account_type_ids and report.account_type_ids[0] or False
if type:
if type.code in ('income', 'expense'):
report_name = 'Profit & Loss ('+type.code+' accounts)'
elif type.code in ('asset','liability'):
report_name = 'Balance Sheet ('+type.code+' accounts)'
report_type.append((type.code, report_name))
return report_type
_columns = {
'name': fields.char('Account Type', size=64, required=True),
'code': fields.char('Code', size=32, required=True),
@ -140,13 +155,7 @@ class account_account_type(osv.osv):
'Detail' will copy each existing journal item of the previous year, even the reconciled ones.
'Unreconciled' will copy only the journal items that were unreconciled on the first day of the new fiscal year."""),
'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'),
'report_type':fields.selection([
('none','/'),
('income','Profit & Loss (Income Accounts)'),
('expense','Profit & Loss (Expense Accounts)'),
('asset','Balance Sheet (Asset Accounts)'),
('liability','Balance Sheet (Liability Accounts)')
],'P&L / BS Category', select=True, readonly=False, help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True),
'report_type': fields.selection(_get_report_type, 'P&L / BS Category', help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True),
'note': fields.text('Description'),
}
_defaults = {
@ -156,6 +165,16 @@ class account_account_type(osv.osv):
}
_order = "code"
def write(self, cr, uid, ids, vals, context=None):
report_obj = self.pool.get('account.financial.report')
if vals.get('report_type'):
type_ids = self.search(cr, uid, [('code','=',vals['report_type'])], context=context)
report_ids = report_obj.search(cr, uid, [('account_type_ids','in',ids)])
for report in report_obj.browse(cr, uid, report_ids, context=context):
type_ids += [x.id for x in report.account_type_ids if x.id not in type_ids]
report_obj.write(cr, uid, [report.id], {'account_type_ids': [(6,0,type_ids)]}, context=context)
return super(account_account_type, self).write(cr, uid, ids, vals, context)
account_account_type()
def _code_get(self, cr, uid, context=None):

View File

@ -13,49 +13,41 @@
<record id="account_type_asset" model="account.account.type">
<field name="name">Asset</field>
<field name="code">asset</field>
<field name="report_type">asset</field>
<field name="close_method">balance</field>
</record>
<record id="account_type_receivable" model="account.account.type">
<field name="name">Receivable</field>
<field name="code">receivable</field>
<field name="report_type">asset</field>
<field name="close_method">unreconciled</field>
</record>
<record id="account_type_liability" model="account.account.type">
<field name="name">Liability</field>
<field name="code">liability</field>
<field name="report_type">liability</field>
<field name="close_method">balance</field>
</record>
<record id="account_type_payable" model="account.account.type">
<field name="name">Payable</field>
<field name="code">payable</field>
<field name="report_type">liability</field>
<field name="close_method">unreconciled</field>
</record>
<record id="account_type_income" model="account.account.type">
<field name="name">Income</field>
<field name="code">income</field>
<field name="report_type">income</field>
<field name="close_method">none</field>
</record>
<record id="account_type_expense" model="account.account.type">
<field name="name">Expense</field>
<field name="code">expense</field>
<field name="report_type">expense</field>
<field name="close_method">none</field>
</record>
<record id="account_type_cash_equity" model="account.account.type">
<field name="name">Equity</field>
<field name="code">equity</field>
<field name="report_type">liability</field>
<field name="close_method">balance</field>
</record>
<record id="account_type_cash_moves" model="account.account.type">
<field name="name">Cash</field>
<field name="code">cash</field>
<field name="report_type">asset</field>
<field name="close_method">balance</field>
</record>
@ -513,5 +505,34 @@
<field name="type">account_type</field>
</record>
<!--
Update Account Type
-->
<record id="account.account_type_asset" model="account.account.type">
<field name="report_type">asset</field>
</record>
<record id="account.account_type_liability" model="account.account.type">
<field name="report_type">liability</field>
</record>
<record id="account.account_type_income" model="account.account.type">
<field name="report_type">income</field>
</record>
<record id="account.account_type_expense" model="account.account.type">
<field name="report_type">expense</field>
</record>
<record id="account.account_type_receivable" model="account.account.type">
<field name="report_type">asset</field>
</record>
<record id="account.account_type_payable" model="account.account.type">
<field name="report_type">liability</field>
</record>
<record id="account.account_type_cash_equity" model="account.account.type">
<field name="report_type">liability</field>
</record>
<record id="account.account_type_cash_moves" model="account.account.type">
<field name="report_type">asset</field>
</record>
</data>
</openerp>