diff --git a/account_financial_report_horizontal/__openerp__.py b/account_financial_report_horizontal/__openerp__.py index 7c04b894..9f7dc6d2 100644 --- a/account_financial_report_horizontal/__openerp__.py +++ b/account_financial_report_horizontal/__openerp__.py @@ -21,9 +21,9 @@ # ############################################################################## { - "name" : "Accounting Financial Reports Horizontal", - "version" : "0.2", - "author" : ["Therp BV", "Agile Business Group"], + "name": "Accounting Financial Reports Horizontal", + "version": "0.2", + "author": ["Therp BV", "Agile Business Group"], "category": 'Accounting & Finance', 'complexity': "normal", "description": """ @@ -31,8 +31,8 @@ This is a port to OpenERP 7.0 of the horizontal financial reports 'Balance sheet' and 'Profit and Loss' as found in OpenERP 6.0. """, 'website': 'https://launchpad.net/account-financial-report', - 'images' : [], - "depends" : ["account"], + 'images': [], + "depends": ["account"], 'data': [ 'menu.xml', 'account_report.xml', @@ -41,7 +41,7 @@ This is a port to OpenERP 7.0 of the horizontal financial reports 'wizard/account_report_profit_loss_view.xml', ], 'demo': [], - 'test': [ ], + 'test': [], 'installable': True, 'active': False, } diff --git a/account_financial_report_horizontal/report/account_balance_sheet.py b/account_financial_report_horizontal/report/account_balance_sheet.py index 7b6c9554..da8c65e7 100644 --- a/account_financial_report_horizontal/report/account_balance_sheet.py +++ b/account_financial_report_horizontal/report/account_balance_sheet.py @@ -26,14 +26,21 @@ import time import pooler from report import report_sxw -from openerp.addons.account_financial_report_horizontal.report import account_profit_loss +from openerp.addons.account_financial_report_horizontal.report import ( + account_profit_loss +) from common_report_header import common_report_header from tools.translate import _ -class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header): + +class report_balancesheet_horizontal( + report_sxw.rml_parse, common_report_header +): def __init__(self, cr, uid, name, context=None): - super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context) - self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context) + super(report_balancesheet_horizontal, self).__init__( + cr, uid, name, context=context) + self.obj_pl = account_profit_loss.report_pl_account_horizontal( + cr, uid, name, context=context) self.result_sum_dr = 0.0 self.result_sum_cr = 0.0 self.result = {} @@ -45,16 +52,16 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) 'get_lines_another': self.get_lines_another, 'sum_dr': self.sum_dr, 'sum_cr': self.sum_cr, - 'get_data':self.get_data, - 'get_pl_balance':self.get_pl_balance, + 'get_data': self.get_data, + 'get_pl_balance': self.get_pl_balance, 'get_fiscalyear': self._get_fiscalyear, 'get_account': self._get_account, 'get_start_period': self.get_start_period, 'get_end_period': self.get_end_period, 'get_sortby': self._get_sortby, 'get_filter': self._get_filter, - 'get_start_date':self._get_start_date, - 'get_end_date':self._get_end_date, + 'get_start_date': self._get_start_date, + 'get_end_date': self._get_end_date, 'get_target_move': self._get_target_move, }) self.context = context @@ -62,11 +69,19 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) def set_context(self, objects, data, ids, report_type=None): new_ids = ids if (data['model'] == 'ir.ui.menu'): - new_ids = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] and [data['form']['chart_account_id'][0]] or [] - objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) - lang_dict = self.pool.get('res.users').read(self.cr,self.uid,self.uid,['context_lang']) + new_ids = 'chart_account_id' in data['form'] and data[ + 'form' + ]['chart_account_id'] and [data[ + 'form' + ]['chart_account_id'][0]] or [] + objects = self.pool.get('account.account').browse( + self.cr, self.uid, new_ids) + lang_dict = self.pool.get('res.users').read( + self.cr, self.uid, self.uid, ['context_lang']) data['lang'] = lang_dict.get('context_lang') or False - return super(report_balancesheet_horizontal, self).set_context(objects, data, new_ids, report_type=report_type) + return super( + report_balancesheet_horizontal, self + ).set_context(objects, data, new_ids, report_type=report_type) def sum_dr(self): if self.res_bl['type'] == _('Net Profit'): @@ -81,7 +96,7 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) def get_pl_balance(self): return self.res_bl - def get_data(self,data): + def get_data(self, data): cr, uid = self.cr, self.uid db_pool = pooler.get_pool(self.cr.dbname) @@ -106,7 +121,7 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) ctx['periods'] = data['form'].get('periods', False) elif data['form']['filter'] == 'filter_date': ctx['date_from'] = data['form'].get('date_from', False) - ctx['date_to'] = data['form'].get('date_to', False) + ctx['date_to'] = data['form'].get('date_to', False) ctx['state'] = data['form'].get('target_move', 'all') cal_list = {} pl_dict = {} @@ -114,7 +129,8 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) account_id = data['form'].get('chart_account_id', False) if account_id: account_id = account_id[0] - account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx) + account_ids = account_pool._get_children_and_consol( + cr, uid, account_id, context=ctx) accounts = account_pool.browse(cr, uid, account_ids, context=ctx) if not self.res_bl: @@ -125,41 +141,66 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) self.res_bl['type'] = _('Net Profit') else: self.res_bl['type'] = _('Net Loss') - pl_dict = { + pl_dict = { 'code': self.res_bl['type'], 'name': self.res_bl['type'], 'level': False, - 'balance':self.res_bl['balance'], - 'type':self.res_bl['type'], + 'balance': self.res_bl['balance'], + 'type': self.res_bl['type'], } for typ in types: accounts_temp = [] for account in accounts: - if (account.user_type.report_type) and (account.user_type.report_type == typ): + if (account.user_type.report_type) and ( + account.user_type.report_type == typ + ): account_dict = { 'id': account.id, 'code': account.code, 'name': account.name, 'level': account.level, - 'balance': (account.balance and typ == 'liability' and -1 or 1 ) * account.balance, + 'balance': ( + account.balance and typ == 'liability' and -1 or 1 + ) * account.balance, 'type': account.type, } - currency = account.currency_id and account.currency_id or account.company_id.currency_id - if typ == 'liability' and account.type <> 'view' and (account.debit <> account.credit): + currency = ( + account.currency_id and account.currency_id + or account.company_id.currency_id + ) + if typ == 'liability' and account.type != 'view' and ( + account.debit != account.credit + ): self.result_sum_dr += account_dict['balance'] - if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit): + if typ == 'asset' and account.type != 'view' and ( + account.debit != account.credit + ): self.result_sum_cr += account_dict['balance'] if data['form']['display_account'] == 'bal_movement': - if (not currency_pool.is_zero(self.cr, self.uid, currency, account.credit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.debit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.balance)): + if ( + not currency_pool.is_zero( + self.cr, self.uid, currency, account.credit + )) or ( + not currency_pool.is_zero( + self.cr, self.uid, currency, account.debit + ) + ) or ( + not currency_pool.is_zero( + self.cr, self.uid, currency, + account.balance + ) + ): accounts_temp.append(account_dict) elif data['form']['display_account'] == 'bal_solde': - if not currency_pool.is_zero(self.cr, self.uid, currency, account.balance): + if not currency_pool.is_zero( + self.cr, self.uid, currency, account.balance + ): accounts_temp.append(account_dict) else: accounts_temp.append(account_dict) self.result[typ] = accounts_temp - cal_list[typ]=self.result[typ] + cal_list[typ] = self.result[typ] if pl_dict['code'] == _('Net Loss'): self.result['asset'].append(pl_dict) @@ -168,49 +209,53 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) if cal_list: temp = {} - for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))): - if i < len(cal_list['liability']) and i < len(cal_list['asset']): - temp={ - 'code': cal_list['liability'][i]['code'], - 'name': cal_list['liability'][i]['name'], - 'level': cal_list['liability'][i]['level'], - 'balance':cal_list['liability'][i]['balance'], - 'type':cal_list['liability'][i]['type'], - 'code1': cal_list['asset'][i]['code'], - 'name1': cal_list['asset'][i]['name'], - 'level1': cal_list['asset'][i]['level'], - 'balance1':cal_list['asset'][i]['balance'], - 'type1':cal_list['asset'][i]['type'], - } + for i in range( + 0, max(len(cal_list['liability']), len(cal_list['asset'])) + ): + if i < len(cal_list['liability']) and i < len( + cal_list['asset'] + ): + temp = { + 'code': cal_list['liability'][i]['code'], + 'name': cal_list['liability'][i]['name'], + 'level': cal_list['liability'][i]['level'], + 'balance': cal_list['liability'][i]['balance'], + 'type': cal_list['liability'][i]['type'], + 'code1': cal_list['asset'][i]['code'], + 'name1': cal_list['asset'][i]['name'], + 'level1': cal_list['asset'][i]['level'], + 'balance1': cal_list['asset'][i]['balance'], + 'type1': cal_list['asset'][i]['type'], + } self.result_temp.append(temp) else: if i < len(cal_list['asset']): - temp={ - 'code': '', - 'name': '', - 'level': False, - 'balance':False, - 'type':False, - 'code1': cal_list['asset'][i]['code'], - 'name1': cal_list['asset'][i]['name'], - 'level1': cal_list['asset'][i]['level'], - 'balance1':cal_list['asset'][i]['balance'], - 'type1':cal_list['asset'][i]['type'], - } + temp = { + 'code': '', + 'name': '', + 'level': False, + 'balance': False, + 'type': False, + 'code1': cal_list['asset'][i]['code'], + 'name1': cal_list['asset'][i]['name'], + 'level1': cal_list['asset'][i]['level'], + 'balance1': cal_list['asset'][i]['balance'], + 'type1': cal_list['asset'][i]['type'], + } self.result_temp.append(temp) - if i < len(cal_list['liability']): - temp={ - 'code': cal_list['liability'][i]['code'], - 'name': cal_list['liability'][i]['name'], - 'level': cal_list['liability'][i]['level'], - 'balance':cal_list['liability'][i]['balance'], - 'type':cal_list['liability'][i]['type'], - 'code1': '', - 'name1': '', - 'level1': False, - 'balance1':False, - 'type1':False, - } + if i < len(cal_list['liability']): + temp = { + 'code': cal_list['liability'][i]['code'], + 'name': cal_list['liability'][i]['name'], + 'level': cal_list['liability'][i]['level'], + 'balance': cal_list['liability'][i]['balance'], + 'type': cal_list['liability'][i]['type'], + 'code1': '', + 'name1': '', + 'level1': False, + 'balance1': False, + 'type1': False, + } self.result_temp.append(temp) return None @@ -220,12 +265,18 @@ class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header) def get_lines_another(self, group): return self.result.get(group, []) -report_sxw.report_sxw('report.account.balancesheet.horizontal', 'account.account', - 'addons/account_financial_report_horizontal/report/account_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal, +report_sxw.report_sxw( + 'report.account.balancesheet.horizontal', 'account.account', + 'addons/account_financial_report_horizontal/report/' + 'account_balance_sheet_horizontal.rml', + parser=report_balancesheet_horizontal, header='internal landscape') -report_sxw.report_sxw('report.account.balancesheet', 'account.account', - 'addons/account_financial_report_horizontal/report/account_balance_sheet.rml',parser=report_balancesheet_horizontal, +report_sxw.report_sxw( + 'report.account.balancesheet', 'account.account', + 'addons/account_financial_report_horizontal/report/' + 'account_balance_sheet.rml', + parser=report_balancesheet_horizontal, header='internal') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_financial_report_horizontal/report/account_profit_loss.py b/account_financial_report_horizontal/report/account_profit_loss.py index 1eabceff..72420962 100644 --- a/account_financial_report_horizontal/report/account_profit_loss.py +++ b/account_financial_report_horizontal/report/account_profit_loss.py @@ -27,16 +27,18 @@ from report import report_sxw from common_report_header import common_report_header from tools.translate import _ + class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): def __init__(self, cr, uid, name, context=None): - super(report_pl_account_horizontal, self).__init__(cr, uid, name, context=context) + super(report_pl_account_horizontal, self).__init__( + cr, uid, name, context=context) self.result_sum_dr = 0.0 self.result_sum_cr = 0.0 self.res_pl = {} self.result = {} self.result_temp = [] - self.localcontext.update( { + self.localcontext.update({ 'time': time, 'get_lines': self.get_lines, 'get_lines_another': self.get_lines_another, @@ -50,22 +52,26 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): 'get_end_period': self.get_end_period, 'get_sortby': self._get_sortby, 'get_filter': self._get_filter, - 'get_start_date':self._get_start_date, - 'get_end_date':self._get_end_date, + 'get_start_date': self._get_start_date, + 'get_end_date': self._get_end_date, 'get_target_move': self._get_target_move, - 'get_trans':self._get_trans + 'get_trans': self._get_trans }) self.context = context def set_context(self, objects, data, ids, report_type=None): new_ids = ids if (data['model'] == 'ir.ui.menu'): - new_ids = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] and [data['form']['chart_account_id'][0]] or [] - objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) - lang_dict = self.pool.get('res.users').read(self.cr,self.uid,self.uid,['context_lang']) + new_ids = 'chart_account_id' in data['form'] and data['form'][ + 'chart_account_id'] and [data['form'][ + 'chart_account_id'][0]] or [] + objects = self.pool.get('account.account').browse( + self.cr, self.uid, new_ids) + lang_dict = self.pool.get('res.users').read( + self.cr, self.uid, self.uid, ['context_lang']) data['lang'] = lang_dict.get('context_lang') or False - return super(report_pl_account_horizontal, self).set_context(objects, data, new_ids, report_type=report_type) - + return super(report_pl_account_horizontal, self).set_context( + objects, data, new_ids, report_type=report_type) def final_result(self): return self.res_pl @@ -82,14 +88,15 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): def _get_trans(self, source): return _(source) - + def get_data(self, data): def get_account_repr(account, account_type): return { 'code': account.code, 'name': account.name, 'level': account.level, - 'balance': account.balance and (account_type == 'income' and -1 or 1) * account.balance, + 'balance': account.balance and ( + account_type == 'income' and -1 or 1) * account.balance, 'type': account.type, } @@ -102,7 +109,7 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): types = [ 'expense', 'income' - ] + ] ctx = self.context.copy() ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False) @@ -110,88 +117,116 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): ctx['fiscalyear'] = ctx['fiscalyear'][0] if data['form']['filter'] == 'filter_period': - ctx['periods'] = data['form'].get('periods', False) + ctx['periods'] = data['form'].get('periods', False) elif data['form']['filter'] == 'filter_date': ctx['date_from'] = data['form'].get('date_from', False) - ctx['date_to'] = data['form'].get('date_to', False) + ctx['date_to'] = data['form'].get('date_to', False) ctx['state'] = data['form'].get('target_move', 'all') cal_list = {} account_id = data['form'].get('chart_account_id', False) if account_id: account_id = account_id[0] - account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx) + account_ids = account_pool._get_children_and_consol( + cr, uid, account_id, context=ctx) accounts = account_pool.browse(cr, uid, account_ids, context=ctx) - + for typ in types: accounts_temp = [] for account in accounts: - if (account.user_type.report_type) and (account.user_type.report_type == typ): - currency = account.currency_id and account.currency_id or account.company_id.currency_id - if typ == 'expense' and account.type <> 'view' and (account.debit <> account.credit): + if (account.user_type.report_type) and ( + account.user_type.report_type == typ + ): + currency = ( + account.currency_id and account.currency_id + or account.company_id.currency_id) + if typ == 'expense' and account.type != 'view' and ( + account.debit != account.credit + ): self.result_sum_dr += account.debit - account.credit - if typ == 'income' and account.type <> 'view' and (account.debit <> account.credit): + if typ == 'income' and account.type != 'view' and ( + account.debit != account.credit + ): self.result_sum_cr += account.credit - account.debit if data['form']['display_account'] == 'bal_movement': - if (not currency_pool.is_zero(self.cr, self.uid, currency, account.credit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.debit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.balance)): - accounts_temp.append(get_account_repr(account, typ)) + if ( + not currency_pool.is_zero( + self.cr, self.uid, currency, account.credit) + ) or ( + not currency_pool.is_zero( + self.cr, self.uid, currency, account.debit) + ) or ( + not currency_pool.is_zero( + self.cr, self.uid, currency, account.balance) + ): + accounts_temp.append( + get_account_repr(account, typ)) elif data['form']['display_account'] == 'bal_solde': - if not currency_pool.is_zero(self.cr, self.uid, currency, account.balance): - accounts_temp.append(get_account_repr(account, typ)) + if not currency_pool.is_zero( + self.cr, self.uid, currency, account.balance + ): + accounts_temp.append( + get_account_repr(account, typ)) else: accounts_temp.append(get_account_repr(account, typ)) if self.result_sum_dr > self.result_sum_cr: self.res_pl['type'] = _('Net Loss') - self.res_pl['balance'] = (self.result_sum_dr - self.result_sum_cr) + self.res_pl['balance'] = ( + self.result_sum_dr - self.result_sum_cr) else: self.res_pl['type'] = _('Net Profit') - self.res_pl['balance'] = (self.result_sum_cr - self.result_sum_dr) + self.res_pl['balance'] = ( + self.result_sum_cr - self.result_sum_dr) self.result[typ] = accounts_temp cal_list[typ] = self.result[typ] if cal_list: temp = {} - for i in range(0,max(len(cal_list['expense']),len(cal_list['income']))): - if i < len(cal_list['expense']) and i < len(cal_list['income']): - temp={ - 'code': cal_list['expense'][i]['code'], - 'name': cal_list['expense'][i]['name'], - 'level': cal_list['expense'][i]['level'], - 'balance':cal_list['expense'][i]['balance'], - 'type':cal_list['expense'][i]['type'], - 'code1': cal_list['income'][i]['code'], - 'name1': cal_list['income'][i]['name'], - 'level1': cal_list['income'][i]['level'], - 'balance1': cal_list['income'][i]['balance'], - 'type1':cal_list['income'][i]['type'], - } + for i in range( + 0, max(len(cal_list['expense']), len(cal_list['income'])) + ): + if i < len(cal_list['expense']) and i < len( + cal_list['income'] + ): + temp = { + 'code': cal_list['expense'][i]['code'], + 'name': cal_list['expense'][i]['name'], + 'level': cal_list['expense'][i]['level'], + 'balance': cal_list['expense'][i]['balance'], + 'type': cal_list['expense'][i]['type'], + 'code1': cal_list['income'][i]['code'], + 'name1': cal_list['income'][i]['name'], + 'level1': cal_list['income'][i]['level'], + 'balance1': cal_list['income'][i]['balance'], + 'type1': cal_list['income'][i]['type'], + } self.result_temp.append(temp) else: if i < len(cal_list['income']): - temp={ - 'code': '', - 'name': '', - 'level': False, - 'balance':False, - 'type':False, - 'code1': cal_list['income'][i]['code'], - 'name1': cal_list['income'][i]['name'], - 'level1': cal_list['income'][i]['level'], - 'balance1': cal_list['income'][i]['balance'], - 'type1':cal_list['income'][i]['type'], - } + temp = { + 'code': '', + 'name': '', + 'level': False, + 'balance': False, + 'type': False, + 'code1': cal_list['income'][i]['code'], + 'name1': cal_list['income'][i]['name'], + 'level1': cal_list['income'][i]['level'], + 'balance1': cal_list['income'][i]['balance'], + 'type1': cal_list['income'][i]['type'], + } self.result_temp.append(temp) - if i < len(cal_list['expense']): - temp={ - 'code': cal_list['expense'][i]['code'], - 'name': cal_list['expense'][i]['name'], - 'level': cal_list['expense'][i]['level'], - 'balance': cal_list['expense'][i]['balance'], - 'type': cal_list['expense'][i]['type'], - 'code1': '', - 'name1': '', - 'level1': False, - 'balance1':False, - 'type1':False, - } + if i < len(cal_list['expense']): + temp = { + 'code': cal_list['expense'][i]['code'], + 'name': cal_list['expense'][i]['name'], + 'level': cal_list['expense'][i]['level'], + 'balance': cal_list['expense'][i]['balance'], + 'type': cal_list['expense'][i]['type'], + 'code1': '', + 'name1': '', + 'level1': False, + 'balance1': False, + 'type1': False, + } self.result_temp.append(temp) return None @@ -201,10 +236,16 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header): def get_lines_another(self, group): return self.result.get(group, []) -report_sxw.report_sxw('report.account.profit_horizontal', 'account.account', - 'addons/account_financial_report_horizontal/report/account_profit_horizontal.rml',parser=report_pl_account_horizontal, header='internal landscape') - -report_sxw.report_sxw('report.account.profit_loss', 'account.account', - 'addons/account_financial_report_horizontal/report/account_profit_loss.rml',parser=report_pl_account_horizontal, header='internal') +report_sxw.report_sxw( + 'report.account.profit_horizontal', 'account.account', + 'addons/account_financial_report_horizontal/report/' + 'account_profit_horizontal.rml', + parser=report_pl_account_horizontal, header='internal landscape') + +report_sxw.report_sxw( + 'report.account.profit_loss', 'account.account', + 'addons/account_financial_report_horizontal/report/' + 'account_profit_loss.rml', + parser=report_pl_account_horizontal, header='internal') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_financial_report_horizontal/report/common_report_header.py b/account_financial_report_horizontal/report/common_report_header.py index f1e5d9a3..e26b97df 100644 --- a/account_financial_report_horizontal/report/common_report_header.py +++ b/account_financial_report_horizontal/report/common_report_header.py @@ -22,6 +22,7 @@ import pooler from tools.translate import _ + class common_report_header(object): def _get_start_date(self, data): @@ -43,17 +44,25 @@ class common_report_header(object): def get_start_period(self, data): if data.get('form', False) and data['form'].get('period_from', False): - return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,data['form']['period_from'][0]).name + return pooler.get_pool(self.cr.dbname).get( + 'account.period').browse(self.cr, self.uid, data[ + 'form']['period_from'][0]).name return '' def get_end_period(self, data): if data.get('form', False) and data['form'].get('period_to', False): - return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr, self.uid, data['form']['period_to'][0]).name + return pooler.get_pool(self.cr.dbname).get( + 'account.period').browse(self.cr, self.uid, data[ + 'form']['period_to'][0]).name return '' def _get_account(self, data): - if data.get('form', False) and data['form'].get('chart_account_id', False): - return pooler.get_pool(self.cr.dbname).get('account.account').browse(self.cr, self.uid, data['form']['chart_account_id'][0]).name + if data.get('form', False) and data['form'].get( + 'chart_account_id', False + ): + return pooler.get_pool(self.cr.dbname).get( + 'account.account').browse(self.cr, self.uid, data[ + 'form']['chart_account_id'][0]).name return '' def _get_sortby(self, data): @@ -68,6 +77,10 @@ class common_report_header(object): return _('No Filter') def _get_fiscalyear(self, data): - if data.get('form', False) and data['form'].get('fiscalyear_id', False): - return pooler.get_pool(self.cr.dbname).get('account.fiscalyear').browse(self.cr, self.uid, data['form']['fiscalyear_id'][0]).name + if data.get('form', False) and data['form'].get( + 'fiscalyear_id', False + ): + return pooler.get_pool(self.cr.dbname).get( + 'account.fiscalyear').browse(self.cr, self.uid, data[ + 'form']['fiscalyear_id'][0]).name return '' diff --git a/account_financial_report_horizontal/wizard/account_report_balance_sheet.py b/account_financial_report_horizontal/wizard/account_report_balance_sheet.py index 4da3f5a2..a46f2d45 100644 --- a/account_financial_report_horizontal/wizard/account_report_balance_sheet.py +++ b/account_financial_report_horizontal/wizard/account_report_balance_sheet.py @@ -22,11 +22,12 @@ ############################################################################## from osv import orm, fields -from tools.translate import _ + class account_bs_report(orm.TransientModel): """ - This wizard will provide the account balance sheet report by periods, between any two dates. + This wizard will provide the account balance sheet report by periods, + between any two dates. """ _name = 'account.bs.report' _inherit = "account_financial_report_horizontal.common.account.report" @@ -36,7 +37,7 @@ class account_bs_report(orm.TransientModel): 'display_type': fields.boolean("Landscape Mode"), } - _defaults={ + _defaults = { 'display_type': True, } diff --git a/account_financial_report_horizontal/wizard/account_report_common.py b/account_financial_report_horizontal/wizard/account_report_common.py index d914e57e..2535e0fe 100644 --- a/account_financial_report_horizontal/wizard/account_report_common.py +++ b/account_financial_report_horizontal/wizard/account_report_common.py @@ -27,105 +27,154 @@ from lxml import etree from osv import fields, orm from tools.translate import _ + class account_common_report(orm.TransientModel): _name = "account_financial_report_horizontal.common.report" _description = "Account Common Report" _columns = { - 'chart_account_id': fields.many2one('account.account', 'Chart of account', help='Select Charts of Accounts', required=True, domain = [('parent_id','=',False)]), - 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Keep empty for all open fiscal year'), - 'filter': fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'), ('filter_period', 'Periods')], "Filter by", required=True), + 'chart_account_id': fields.many2one( + 'account.account', 'Chart of account', + help='Select Charts of Accounts', + required=True, domain=[('parent_id', '=', False)]), + 'fiscalyear_id': fields.many2one( + 'account.fiscalyear', 'Fiscal year', + help='Keep empty for all open fiscal year'), + 'filter': fields.selection([ + ('filter_no', 'No Filters'), ('filter_date', 'Date'), + ('filter_period', 'Periods') + ], + "Filter by", required=True), 'period_from': fields.many2one('account.period', 'Start period'), 'period_to': fields.many2one('account.period', 'End period'), 'date_from': fields.date("Start Date"), 'date_to': fields.date("End Date"), - 'target_move': fields.selection([('posted', 'All Posted Entries'), - ('all', 'All Entries'), - ], 'Target Moves', required=True), + 'target_move': fields.selection([ + ('posted', 'All Posted Entries'), + ('all', 'All Entries'), + ], 'Target Moves', required=True + ), } - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + def fields_view_get( + self, cr, uid, view_id=None, view_type='form', context=None, + toolbar=False, submenu=False + ): if context is None: context = {} - res = super(account_common_report, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) + res = super(account_common_report, self).fields_view_get( + cr, uid, view_id=view_id, view_type=view_type, context=context, + toolbar=toolbar, submenu=False) if context.get('active_model', False) == 'account.account' and view_id: doc = etree.XML(res['arch']) nodes = doc.xpath("//field[@name='chart_account_id']") for node in nodes: node.set('readonly', '1') - node.set('help', 'If you print the report from Account list/form view it will not consider Charts of account') + node.set( + 'help', + 'If you print the report from Account list/form view ' + 'it will not consider Charts of account') res['arch'] = etree.tostring(doc) return res - def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None): + def onchange_filter( + self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, + context=None + ): res = {} if filter == 'filter_no': - res['value'] = {'period_from': False, 'period_to': False, 'date_from': False ,'date_to': False} + res['value'] = { + 'period_from': False, 'period_to': False, + 'date_from': False, 'date_to': False + } if filter == 'filter_date': - res['value'] = {'period_from': False, 'period_to': False, 'date_from': time.strftime('%Y-01-01'), 'date_to': time.strftime('%Y-%m-%d')} + res['value'] = { + 'period_from': False, 'period_to': False, + 'date_from': time.strftime('%Y-01-01'), + 'date_to': time.strftime('%Y-%m-%d') + } if filter == 'filter_period' and fiscalyear_id: start_period = end_period = False cr.execute(''' SELECT * FROM (SELECT p.id FROM account_period p - LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id) + LEFT JOIN account_fiscalyear f + ON (p.fiscalyear_id = f.id) WHERE f.id = %s ORDER BY p.date_start ASC LIMIT 1) AS period_start UNION SELECT * FROM (SELECT p.id FROM account_period p - LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id) + LEFT JOIN account_fiscalyear f + ON (p.fiscalyear_id = f.id) WHERE f.id = %s AND p.date_start < NOW() ORDER BY p.date_stop DESC - LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id)) - periods = [i[0] for i in cr.fetchall()] + LIMIT 1) AS period_stop''', ( + fiscalyear_id, fiscalyear_id + ) + ) + periods = [i[0] for i in cr.fetchall()] if periods and len(periods) > 1: start_period = periods[0] end_period = periods[1] - res['value'] = {'period_from': start_period, 'period_to': end_period, 'date_from': False, 'date_to': False} + res['value'] = { + 'period_from': start_period, 'period_to': end_period, + 'date_from': False, 'date_to': False + } return res def _get_account(self, cr, uid, context=None): - accounts = self.pool.get('account.account').search(cr, uid, [('parent_id', '=', False)], limit=1) + accounts = self.pool.get('account.account').search( + cr, uid, [('parent_id', '=', False)], limit=1) return accounts and accounts[0] or False def _get_fiscalyear(self, cr, uid, context=None): now = time.strftime('%Y-%m-%d') - fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 ) + fiscalyears = self.pool.get('account.fiscalyear').search( + cr, uid, [('date_start', '<', now), ( + 'date_stop', '>', now)], limit=1) return fiscalyears and fiscalyears[0] or False _defaults = { - 'fiscalyear_id': _get_fiscalyear, - 'filter': 'filter_no', - 'chart_account_id': _get_account, - 'target_move': 'posted', + 'fiscalyear_id': _get_fiscalyear, + 'filter': 'filter_no', + 'chart_account_id': _get_account, + 'target_move': 'posted', } def _build_contexts(self, cr, uid, ids, data, context=None): if context is None: context = {} result = {} - result['fiscalyear'] = 'fiscalyear_id' in data['form'] and data['form']['fiscalyear_id'] or False - result['chart_account_id'] = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] or False + result['fiscalyear'] = 'fiscalyear_id' in data['form'] and data[ + 'form']['fiscalyear_id'] or False + result['chart_account_id'] = 'chart_account_id' in data[ + 'form'] and data['form']['chart_account_id'] or False if data['form']['filter'] == 'filter_date': result['date_from'] = data['form']['date_from'] result['date_to'] = data['form']['date_to'] elif data['form']['filter'] == 'filter_period': - if not data['form']['period_from'] or not data['form']['period_to']: - raise osv.except_osv(_('Error'),_('Select a starting and an ending period')) + if not data['form']['period_from'] or not data[ + 'form' + ]['period_to']: + raise orm.except_orm( + _('Error'), _('Select a starting and an ending period')) result['period_from'] = data['form']['period_from'] result['period_to'] = data['form']['period_to'] if data['form']['period_to'] and result['period_to']: - period_from = data['form'].get('period_from', False) and data['form']['period_from'][0] or False - period_to = data['form'].get('period_to', False) and data['form']['period_to'][0] or False + period_from = data['form'].get('period_from', False) and data[ + 'form']['period_from'][0] or False + period_to = data['form'].get('period_to', False) and data[ + 'form']['period_to'][0] or False period_obj = self.pool.get('account.period') - result['periods'] = period_obj.build_ctx_periods(cr, uid, period_from, period_to) + result['periods'] = period_obj.build_ctx_periods( + cr, uid, period_from, period_to) return result - + def _print_report(self, cr, uid, ids, data, context=None): raise (_('Error'), _('not implemented')) @@ -135,9 +184,13 @@ class account_common_report(orm.TransientModel): data = {} data['ids'] = context.get('active_ids', []) data['model'] = context.get('active_model', 'ir.ui.menu') - data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'period_from', 'period_to', 'filter', 'chart_account_id', 'target_move'])[0] - used_context = self._build_contexts(cr, uid, ids, data, context=context) - data['form']['periods'] = used_context.get('periods', False) and used_context['periods'] or [] + data['form'] = self.read(cr, uid, ids, [ + 'date_from', 'date_to', 'fiscalyear_id', 'period_from', + 'period_to', 'filter', 'chart_account_id', 'target_move' + ])[0] + used_context = self._build_contexts( + cr, uid, ids, data, context=context) + data['form']['periods'] = used_context.get( + 'periods', False) and used_context['periods'] or [] data['form']['used_context'] = used_context return self._print_report(cr, uid, ids, data, context=context) -