From 04ffb47636576c49f0fa9224cfcb9d347a163b3f Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Wed, 14 Jul 2010 12:51:10 +0530 Subject: [PATCH] [IMP] profit and loss wizard with common inheritancy bzr revid: mra@mra-laptop-20100714072110-l0jz5263f5fmqvth --- addons/account/wizard/account_pl_report.py | 124 ++++-------------- .../account/wizard/account_pl_report_view.xml | 81 +++--------- 2 files changed, 41 insertions(+), 164 deletions(-) diff --git a/addons/account/wizard/account_pl_report.py b/addons/account/wizard/account_pl_report.py index f507226fefd..79a1fd4e74a 100644 --- a/addons/account/wizard/account_pl_report.py +++ b/addons/account/wizard/account_pl_report.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # ############################################################################## -import time from osv import osv, fields from tools.translate import _ @@ -27,129 +26,56 @@ class account_pl_report(osv.osv_memory): """ This wizard will provide the account profit and loss report by periods, between any two dates. """ - _name = 'account.pl.report' - _description = 'Account Profit And Loss Report' + _inherit = "account.common.report" + _name = "account.pl.report" + _description = "Account Profit And Loss Report" _columns = { - 'Account_list': fields.many2one('account.account', 'Chart account', - required=True, domain = [('parent_id','=',False)]), - 'company_id': fields.many2one('res.company', 'Company', required=True), +# 'company_id': fields.many2one('res.company', 'Company', required=True), 'display_account': fields.selection([('bal_movement','With movements'), ('bal_solde','With balance is not equal to 0'), ('bal_all','All'), ],'Display accounts'), 'display_type': fields.boolean("Landscape Mode"), - 'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Keep empty for all open fiscal year'), - 'state': fields.selection([('bydate','By Date'), - ('byperiod','By Period'), - ('all','By Date and Period'), - ('none','No Filter') - ],'Date/Period Filter'), - 'periods': fields.many2many('account.period', 'period_account_balance_rel', - 'report_id', 'period_id', 'Periods', - help='Keep empty for all open fiscal year'), - 'date_from': fields.date('Start date', required=True), - 'date_to': fields.date('End date', required=True), - } + } - def _get_company(self, cr, uid, context=None): - user_obj = self.pool.get('res.users') - company_obj = self.pool.get('res.company') - user = user_obj.browse(cr, uid, uid, context=context) - if user.company_id: - return user.company_id.id - else: - return company_obj.search(cr, uid, [('parent_id', '=', False)])[0] - - _defaults={ - 'state' : 'none', - 'date_from' : time.strftime('%Y-01-01'), - 'date_to' : time.strftime('%Y-%m-%d'), - 'company_id' : _get_company, - 'fiscalyear' : False, + _defaults = { 'display_account': 'bal_all', 'display_type': True, - } - - def next_view(self, cr, uid, ids, context=None): - obj_model = self.pool.get('ir.model.data') - if context is None: - context = {} - data = self.read(cr, uid, ids, [])[0] - context.update({'Account_list': data['Account_list']}) - model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_pl_report_view')]) - resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id'] - return { - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'account.pl.report', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - 'context': context - } - - def check_state(self, cr, uid, ids, context=None): - if context is None: - context = {} - data={} - data['ids'] = context['active_ids'] - data['form'] = self.read(cr, uid, ids, ['date_from', 'company_id', 'state', 'periods', 'date_to', 'display_account', 'display_type', 'fiscalyear'])[0] - data['form']['Account_list'] = context.get('Account_list',[]) - data['form']['context'] = context - if data['form']['Account_list']: - data['model'] = 'ir.ui.menu' - else: - data['model'] = 'account.account' - - if data['form']['state'] == 'bydate' : - return self._check_date(cr, uid, data, context) - elif data['form']['state'] == 'byperiod': - if not data['form']['periods']: - raise osv.except_osv(_('Warning'),_('Please Enter Periods ! ')) - if data['form']['display_type']: - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'pl.account.horizontal', - 'datas': data, - 'nodestroy':True, } - else: - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'pl.account', - 'datas': data, - 'nodestroy':True, - } - + def _check_date(self, cr, uid, data, context=None): if context is None: context = {} - sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ - cr.execute(sql,(data['form']['date_from'],)) + sql = """ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date_from'])) res = cr.dictfetchall() if res: - if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']): raise osv.except_osv(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop'])) - else: - if data['form']['display_type']: - return { - 'type': 'ir.actions.report.xml', + else: + raise osv.except_osv(_('UserError'),_('Date not in a defined fiscal year')) + return True + + def _print_report(self, cr, uid, ids, data, query_line, context=None): + if context is None: + context = {} + data['form'].update(self.read(cr, uid, ids, ['display_account', 'display_type'])[0]) + data['form']['query_line'] = query_line + if data['form']['state'] == 'bydate': + return self._check_date(cr, uid, data, context=context) + if data['form']['landscape']: + return { 'type': 'ir.actions.report.xml', 'report_name': 'pl.account.horizontal', 'datas': data, 'nodestroy':True, } - else: - return { - 'type': 'ir.actions.report.xml', + else: + return { 'type': 'ir.actions.report.xml', 'report_name': 'pl.account', 'datas': data, 'nodestroy':True, } - else: - raise osv.except_osv(_('UserError'),_('Date not in a defined fiscal year')) account_pl_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_pl_report_view.xml b/addons/account/wizard/account_pl_report_view.xml index b1104df8d25..1692e0d4577 100644 --- a/addons/account/wizard/account_pl_report_view.xml +++ b/addons/account/wizard/account_pl_report_view.xml @@ -2,42 +2,18 @@ - - Select period - account.pl.report - form - -
- - - - -