From 944a8f501efbac9eee2f57c6542a17efd8488b07 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Mon, 27 Dec 2010 11:10:32 +0530 Subject: [PATCH] [REF] account :In balance sheet report wizard add reserve_account_id as per xrg patch bzr revid: ara@tinyerp.com-20101227054032-8ic2n16ahkwnzo2u --- .../wizard/account_report_balance_sheet.py | 45 ++++++++++++------- .../account_report_balance_sheet_view.xml | 8 +++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/addons/account/wizard/account_report_balance_sheet.py b/addons/account/wizard/account_report_balance_sheet.py index 890b22421e4..da021f12d8e 100644 --- a/addons/account/wizard/account_report_balance_sheet.py +++ b/addons/account/wizard/account_report_balance_sheet.py @@ -32,36 +32,47 @@ class account_bs_report(osv.osv_memory): _inherit = "account.common.account.report" _description = 'Account Balance Sheet Report' + def _get_def_reserve_account(self, cr, uid, context=None): + chart_id = self._get_account(cr, uid, context=context) + # Reuse the onchange function, for symmetry + res = self.onchange_chart_id(cr, uid, chart_id, context=context) + if not res: + return False + return res['value']['reserve_account_id'] + _columns = { 'display_type': fields.boolean("Landscape Mode"), - 'reserve_account_id': fields.many2one('account.account', 'Reserve & Profit/Loss Account',required = True, - help='This Account is used for transferring Profit/Loss(If It is Profit: Amount will be added, Loss : Amount will be duducted.), Which is calculated from Profilt & Loss Report', domain = [('type','=','payable')]), + 'reserve_account_id': fields.many2one('account.account', 'Reserve & Profit/Loss Account', + required=True, + help='This Account is used for transfering Profit/Loss ' \ + '(Profit: Amount will be added, Loss: Amount will be duducted), ' \ + 'which is calculated from Profilt & Loss Report', + domain = [('type','=','payable')]), } _defaults={ 'display_type': True, 'journal_ids': [], + 'reserve_account_id': _get_def_reserve_account, } - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - res = super(account_bs_report, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) - doc = etree.XML(res['arch']) - nodes = doc.xpath("//field[@name='journal_ids']") - for node in nodes: - node.set('readonly', '1') - node.set('required', '0') - res['arch'] = etree.tostring(doc) - return res + def onchange_chart_id(self, cr, uid, chart_id, context=None): + if not chart_id: + return False + account = self.pool.get('account.account').browse(cr, uid, chart_id , context=context) + if not account.company_id.property_reserve_and_surplus_account: + return False # We cannot raise an exception, because that's before the wizard + return { 'value': {'reserve_account_id': account.company_id.property_reserve_and_surplus_account.id}} + def _print_report(self, cr, uid, ids, data, context=None): if context is None: context = {} - data = self.pre_print_report(cr, uid, ids, data, context=context) - account = self.pool.get('account.account').browse(cr, uid, data['form']['chart_account_id'], context=context) - if not account.company_id.property_reserve_and_surplus_account: + data['form'].update(self.read(cr, uid, ids, ['display_type','reserve_account_id'])[0]) + if not data['form']['reserve_account_id']: + # only in < v6.1, where orm_memory does not honor required fields raise osv.except_osv(_('Warning'),_('Please define the Reserve and Profit/Loss account for current user company !')) - data['form']['reserve_account_id'] = account.company_id.property_reserve_and_surplus_account.id - data['form'].update(self.read(cr, uid, ids, ['display_type'])[0]) + data = self.pre_print_report(cr, uid, ids, data, context=context) if data['form']['display_type']: return { 'type': 'ir.actions.report.xml', @@ -77,4 +88,4 @@ class account_bs_report(osv.osv_memory): account_bs_report() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_report_balance_sheet_view.xml b/addons/account/wizard/account_report_balance_sheet_view.xml index 97b73784f43..f6335a3b9cf 100644 --- a/addons/account/wizard/account_report_balance_sheet_view.xml +++ b/addons/account/wizard/account_report_balance_sheet_view.xml @@ -9,6 +9,12 @@ + + + + + +