From 244f96ef8d20e5b272ff73e8ecfa04389a705cf1 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Sat, 23 Nov 2013 23:25:09 -0530 Subject: [PATCH 1/5] [IMP][account_financial_report] Added Partner Balances to AFR --- .../model/account_financial_report.py | 4 +- .../balance_full_4_cols_partner_balance.rml | 279 ++++++++++++++++++ account_financial_report/report/parser.py | 84 +++++- account_financial_report/view/report.xml | 11 + account_financial_report/view/wizard.xml | 3 + account_financial_report/wizard/wizard.py | 6 +- 6 files changed, 384 insertions(+), 3 deletions(-) create mode 100644 account_financial_report/report/balance_full_4_cols_partner_balance.rml diff --git a/account_financial_report/model/account_financial_report.py b/account_financial_report/model/account_financial_report.py index 2c593a24..968c8b3e 100644 --- a/account_financial_report/model/account_financial_report.py +++ b/account_financial_report/model/account_financial_report.py @@ -49,7 +49,9 @@ class account_financial_report(osv.osv): 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), 'journal_ledger': fields.boolean('journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - + 'partner_balance': fields.boolean('Partner Balance', help="""Allows to + Generate a Partner Balance for accounts with moves. Available when + Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"""), 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'lab_str': fields.char('Description', help='Description for the Summary', size=128), 'target_move': fields.selection([('posted', 'All Posted Entries'), diff --git a/account_financial_report/report/balance_full_4_cols_partner_balance.rml b/account_financial_report/report/balance_full_4_cols_partner_balance.rml new file mode 100644 index 00000000..47f1c716 --- /dev/null +++ b/account_financial_report/report/balance_full_4_cols_partner_balance.rml @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[setLang(user.lang)]] + + + + + + CODE + + + + ACCOUNT + + + INITIAL + + + DEBIT + + + CREDIT + + + BALANCE + + + + + + + + + + DATE + + + + + PERIOD + + + + REFERENCE + + + JOURNAL ENTRY + + + PARTNER + + + + + + + + + + + + + + + + + +
+ [[ repeatIn([x for x in lines(data['form']) if x['type'] != 'view'], 'a') ]] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]] + [[a['label']==True and a['code'] or '' ]] + + + + + [[ ((a['total'] and not a['label']) and setTag('para','para',{'alignment':"RIGHT"}) or (a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}))) or removeParentNode('font') ]] + [[ a['type']=='view' and a['name'].upper() or a['name'].title() ]] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(a['balanceinit'] and a['balanceinit'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(a['debit'], digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(a['credit'], digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(a['balance'] and a['balance'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']] + + + + + +
+ [[ repeatIn(a['partner'], 'm') ]] + + + + + + + + + + [[ m['partner_name'] ]] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(m['balanceinit'] and m['balanceinit'] * m.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(m['debit'], digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(m['credit'], digits=2, grouping=True) or '']] + + + + + [[ a['type']<>'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]] + [[ (a['total']==True) and formatLang(m['balance'] and m['balance'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']] + + + + +
+ +
+ +
+
diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 804a4650..f0e4fe95 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -35,7 +35,6 @@ from report import report_sxw from tools import config from tools.translate import _ from osv import osv -import pdb from openerp.tools.safe_eval import safe_eval as eval @@ -190,6 +189,81 @@ class account_balance(report_sxw.rml_parse): else: return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids] + def _get_partner_balance(self, account, init_period, ctx=None): + rp_obj = self.pool.get('res.partner') + res = [] + ctx = ctx or {} + if account['type'] in ('other', 'liquidity', 'receivable', 'payable'): + sql_query = """ + SELECT + CASE + WHEN aml.partner_id IS NOT NULL + THEN (SELECT name FROM res_partner WHERE aml.partner_id = id) + ELSE 'UNKNOWN' + END AS partner_name, + CASE + WHEN aml.partner_id IS NOT NULL + THEN aml.partner_id + ELSE 0 + END AS p_idx, + SUM(aml.debit) AS debit, + SUM(aml.credit) AS credit + FROM account_move_line AS aml + INNER JOIN account_account aa ON aa.id = aml.account_id + INNER JOIN account_move am ON am.id = aml.move_id + %s + GROUP BY p_idx, partner_name + ORDER BY partner_name""" + + WHERE_POSTED = '' + if ctx.get('state','posted')=='posted': + WHERE_POSTED = "AND am.state = 'posted'" + + cur_periods = ', '.join([str(i) for i in ctx['periods']]) + init_periods = ', '.join([str(i) for i in init_period]) + + WHERE = """ + WHERE aml.period_id IN (%s) + AND aa.id = %s + AND aml.state <> 'draft' + """ % (init_periods, account['id']) + query_init = sql_query%(WHERE+WHERE_POSTED) + + WHERE = """ + WHERE aml.period_id IN (%s) + AND aa.id = %s + AND aml.state <> 'draft' + """ % (cur_periods, account['id']) + + query_bal = sql_query%(WHERE+WHERE_POSTED) + + query = ''' + SELECT + vinit.partner_name, + (vinit.debit - vinit.credit) AS balanceinit, + vbal.debit, + vbal.credit, + (vinit.debit - vinit.credit + vbal.debit - vbal.credit) AS balance + FROM (%s) vinit + JOIN (%s) vbal ON vinit.p_idx = vbal.p_idx + '''%(query_init,query_bal) + +# import pdb +# pdb.set_trace() + + self.cr.execute(query) + res_dict = self.cr.dictfetchall() + balance = account['balanceinit'] + for det in res_dict: + res.append({ + 'partner_name': det['partner_name'], + 'balanceinit': det['balanceinit'], + 'debit': det['debit'], + 'credit': det['credit'], + 'balance': det['balance'], + }) + return res + def _get_analytic_ledger(self, account, ctx={}): res = [] @@ -828,6 +902,8 @@ class account_balance(report_sxw.rml_parse): res['mayor'] = self._get_analytic_ledger(res, ctx=ctx_end) elif to_include and form['journal_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): res['journal'] = self._get_journal_ledger(res, ctx=ctx_end) + elif to_include and form['partner_balance'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): + res['partner'] = self._get_partner_balance(res, ctx_i['periods'], ctx=ctx_end) else: res['mayor'] = [] @@ -938,6 +1014,12 @@ report_sxw.report_sxw('report.afr.analytic.ledger', parser=account_balance, header=False) +report_sxw.report_sxw('report.afr.partner.balance', + 'wizard.report', + 'account_financial_report/report/balance_full_4_cols_partner_balance.rml', + parser=account_balance, + header=False) + report_sxw.report_sxw('report.afr.journal.ledger', 'wizard.report', 'account_financial_report/report/balance_full_4_cols_journal_ledger.rml', diff --git a/account_financial_report/view/report.xml b/account_financial_report/view/report.xml index e97d73ce..119d0b93 100644 --- a/account_financial_report/view/report.xml +++ b/account_financial_report/view/report.xml @@ -46,6 +46,17 @@ header="False" /> + + + diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index 43bd6895..aea0afff 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.py @@ -51,7 +51,9 @@ class wizard_report(osv.osv_memory): 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), 'journal_ledger': fields.boolean('Journal Ledger', help="Allows to Generate an Journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - + 'partner_balance': fields.boolean('Partner Balance', help="""Allows to + Generate a Partner Balance for accounts with moves. Available when + Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"""), 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'lab_str': fields.char('Description', help='Description for the Summary', size=128), @@ -276,6 +278,8 @@ class wizard_report(osv.osv_memory): name = 'afr.analytic.ledger' elif data['form']['journal_ledger'] and data['form']['inf_type'] == 'BS': name = 'afr.journal.ledger' + elif data['form']['partner_balance'] and data['form']['inf_type'] == 'BS': + name = 'afr.partner.balance' else: name = 'afr.4cols' if data['form']['columns'] == 'five': From 7beb35cd8d90687aad8f61ee2ed24c29b401aa69 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Sun, 24 Nov 2013 00:44:10 -0530 Subject: [PATCH 2/5] [IMP][account_financial_report] Improved SQL query --- account_financial_report/report/parser.py | 54 ++++++++++++++--------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index f0e4fe95..6ab7bc34 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -206,14 +206,16 @@ class account_balance(report_sxw.rml_parse): THEN aml.partner_id ELSE 0 END AS p_idx, - SUM(aml.debit) AS debit, - SUM(aml.credit) AS credit + %s, + %s, + %s, + %s FROM account_move_line AS aml INNER JOIN account_account aa ON aa.id = aml.account_id INNER JOIN account_move am ON am.id = aml.move_id %s GROUP BY p_idx, partner_name - ORDER BY partner_name""" + """ WHERE_POSTED = '' if ctx.get('state','posted')=='posted': @@ -227,7 +229,11 @@ class account_balance(report_sxw.rml_parse): AND aa.id = %s AND aml.state <> 'draft' """ % (init_periods, account['id']) - query_init = sql_query%(WHERE+WHERE_POSTED) + query_init = sql_query%('SUM(aml.debit) AS init_dr', + 'SUM(aml.credit) AS init_cr', + '0.0 AS bal_dr', + '0.0 AS bal_cr', + WHERE+WHERE_POSTED) WHERE = """ WHERE aml.period_id IN (%s) @@ -235,32 +241,40 @@ class account_balance(report_sxw.rml_parse): AND aml.state <> 'draft' """ % (cur_periods, account['id']) - query_bal = sql_query%(WHERE+WHERE_POSTED) + query_bal = sql_query%('0.0 AS init_dr', + '0.0 AS init_cr', + 'SUM(aml.debit) AS bal_dr', + 'SUM(aml.credit) AS bal_cr', + WHERE+WHERE_POSTED) query = ''' SELECT - vinit.partner_name, - (vinit.debit - vinit.credit) AS balanceinit, - vbal.debit, - vbal.credit, - (vinit.debit - vinit.credit + vbal.debit - vbal.credit) AS balance + partner_name, + p_idx, + SUM(init_dr)-SUM(init_cr) AS balanceinit, + SUM(bal_dr) AS debit, + SUM(bal_cr) AS credit, + SUM(init_dr) - SUM(init_cr) + SUM(bal_dr) - SUM(bal_cr) AS balance + FROM ( + SELECT + * FROM (%s) vinit - JOIN (%s) vbal ON vinit.p_idx = vbal.p_idx + UNION ALL (%s) + ) v + GROUP BY p_idx, partner_name + ORDER BY partner_name '''%(query_init,query_bal) -# import pdb -# pdb.set_trace() - self.cr.execute(query) res_dict = self.cr.dictfetchall() - balance = account['balanceinit'] for det in res_dict: - res.append({ + i,d,c,b = det['balanceinit'], det['debit'], det['credit'], det['balance'], + any([bool(i),bool(d),bool(c),bool(b)]) and res.append({ 'partner_name': det['partner_name'], - 'balanceinit': det['balanceinit'], - 'debit': det['debit'], - 'credit': det['credit'], - 'balance': det['balance'], + 'balanceinit': i, + 'debit': d, + 'credit': c, + 'balance': b, }) return res From 2e4056201f4456e6592953e271ca3a638d00a5b5 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Sun, 24 Nov 2013 00:49:52 -0530 Subject: [PATCH 3/5] [FIX][account_financial_report] Fixing Report Cells --- .../report/balance_full_4_cols_partner_balance.rml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/account_financial_report/report/balance_full_4_cols_partner_balance.rml b/account_financial_report/report/balance_full_4_cols_partner_balance.rml index 47f1c716..6e1c783f 100644 --- a/account_financial_report/report/balance_full_4_cols_partner_balance.rml +++ b/account_financial_report/report/balance_full_4_cols_partner_balance.rml @@ -146,29 +146,23 @@ - + - DATE + - PERIOD + PARTNER - REFERENCE - - - JOURNAL ENTRY - - - PARTNER + From 85c799b4b4203fcfbf9123c36b6718e8d9befdb6 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Sun, 24 Nov 2013 01:01:43 -0530 Subject: [PATCH 4/5] [IMP][account_financial_report] Sending Unknown Partner at the end of the report --- account_financial_report/report/parser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 6ab7bc34..67a28609 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -267,15 +267,23 @@ class account_balance(report_sxw.rml_parse): self.cr.execute(query) res_dict = self.cr.dictfetchall() + unknown = False for det in res_dict: i,d,c,b = det['balanceinit'], det['debit'], det['credit'], det['balance'], - any([bool(i),bool(d),bool(c),bool(b)]) and res.append({ + if not any([i,d,c,b]): + continue + data = { 'partner_name': det['partner_name'], 'balanceinit': i, 'debit': d, 'credit': c, 'balance': b, - }) + } + if not det['p_idx']: + unknown = data + continue + res.append(data) + unknown and res.append(unknown) return res def _get_analytic_ledger(self, account, ctx={}): From 8ed3576105cb6136e290c7eac021daf435dd9780 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Wed, 27 Nov 2013 19:10:59 -0530 Subject: [PATCH 5/5] [AUTOPEP8][account_financial_report] autopep8 account_financial_report --recursive --in-place --pep8-passes 2000 --verbose --- .../model/account_financial_report.py | 82 ++++++--- account_financial_report/report/parser.py | 158 +++++++++--------- account_financial_report/wizard/wizard.py | 8 +- 3 files changed, 144 insertions(+), 104 deletions(-) diff --git a/account_financial_report/model/account_financial_report.py b/account_financial_report/model/account_financial_report.py index 968c8b3e..fd848349 100644 --- a/account_financial_report/model/account_financial_report.py +++ b/account_financial_report/model/account_financial_report.py @@ -38,29 +38,45 @@ class account_financial_report(osv.osv): _columns = { 'name': fields.char('Name', size=128, required=True), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"), - 'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True), - 'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True), - 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'), - 'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'), - 'account_ids': fields.many2many('account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True), - 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True), - 'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'), - - 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'journal_ledger': fields.boolean('journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'partner_balance': fields.boolean('Partner Balance', help="""Allows to - Generate a Partner Balance for accounts with moves. Available when - Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"""), - 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), - 'lab_str': fields.char('Description', help='Description for the Summary', size=128), + 'currency_id': fields.many2one( + 'res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"), + 'inf_type': fields.selection( + [('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True), + 'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), + ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True), + 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), + ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'), + 'display_account_level': fields.integer( + 'Up to level', help='Display accounts up to this level (0 to show all)'), + 'account_ids': fields.many2many( + 'account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True), + 'fiscalyear_id': fields.many2one( + 'account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True), + 'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', + 'period_id', 'Periods', help='All periods in the fiscal year if empty'), + + 'analytic_ledger': fields.boolean( + 'Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), + 'journal_ledger': fields.boolean( + 'journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), + 'partner_balance': fields.boolean('Partner Balance', help="Allows to " + "Generate a Partner Balance for accounts with moves. Available when " + "Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), + 'tot_check': fields.boolean( + 'Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), + 'lab_str': + fields.char( + 'Description', + help='Description for the Summary', + size=128), 'target_move': fields.selection([('posted', 'All Posted Entries'), ('all', 'All Entries'), ], 'Entries to Include', required=True, - help='Print All Accounting Entries or just Posted Accounting Entries'), + help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields - 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), + 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), + ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), 'date_to': fields.date('End date'), 'date_from': fields.date('Start date'), } @@ -68,8 +84,15 @@ class account_financial_report(osv.osv): _defaults = { 'display_account_level': lambda *a: 0, 'inf_type': lambda *a: 'BS', - 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c), - 'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid), + 'company_id': lambda self, cr, uid, c: + self.pool.get( + 'res.company')._company_default_get( + cr, + uid, + 'account.invoice', + context=c), + 'fiscalyear_id': lambda self, cr, uid, c: + self.pool.get('account.fiscalyear').find(cr, uid), 'display_account': lambda *a: 'bal_mov', 'columns': lambda *a: 'five', @@ -87,9 +110,18 @@ class account_financial_report(osv.osv): lst = self.search(cr, uid, [( 'name', 'like', new_name)], context=context) if lst: - new_name = '%s (%s)' % (new_name, len(lst)+1) + new_name = '%s (%s)' % (new_name, len(lst) + 1) defaults['name'] = new_name - return super(account_financial_report, self).copy(cr, uid, id, defaults, context=context) + return ( + super( + account_financial_report, + self).copy( + cr, + uid, + id, + defaults, + context=context) + ) def onchange_inf_type(self, cr, uid, ids, inf_type, context=None): if context is None: @@ -101,7 +133,8 @@ class account_financial_report(osv.osv): return res - def onchange_columns(self, cr, uid, ids, columns, fiscalyear_id, period_ids, context=None): + def onchange_columns(self, cr, uid, ids, columns, + fiscalyear_id, period_ids, context=None): if context is None: context = {} res = {'value': {}} @@ -118,7 +151,8 @@ class account_financial_report(osv.osv): res['value'].update({'period_ids': []}) return res - def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None): + def onchange_analytic_ledger( + self, cr, uid, ids, company_id, analytic_ledger, context=None): if context is None: context = {} context['company_id'] = company_id diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 67a28609..7e67c6cc 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -61,20 +61,21 @@ class account_balance(report_sxw.rml_parse): 'get_vat_by_country': self.get_vat_by_country, }) self.context = context - - + def get_vat_by_country(self, form): """ Return the vat of the partner by country """ rc_obj = self.pool.get('res.company') - country_code=rc_obj.browse(self.cr, self.uid, form['company_id'][0]).partner_id.country_id.code or '' - string_vat= rc_obj.browse(self.cr, self.uid, form['company_id'][0]).partner_id.vat or '' + country_code = rc_obj.browse(self.cr, self.uid, + form['company_id'][0]).partner_id.country_id.code or '' + string_vat = rc_obj.browse(self.cr, self.uid, + form['company_id'][0]).partner_id.vat or '' if string_vat: - if country_code=='MX': + if country_code == 'MX': return '%s' % (string_vat[2:]) - elif country_code=='VE': - return '- %s-%s-%s'%(string_vat[2:3],string_vat[3:11],string_vat[11:12]) + elif country_code == 'VE': + return '- %s-%s-%s' % (string_vat[2:3], string_vat[3:11], string_vat[11:12]) else: return string_vat else: @@ -119,10 +120,10 @@ class account_balance(report_sxw.rml_parse): if form['filter'] in ['bydate', 'all']: months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"] - mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1]-1] + mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1] - 1] ano = time.strptime(form['date_to'], "%Y-%m-%d")[0] dia = time.strptime(form['date_to'], "%Y-%m-%d")[2] - return _('From ')+self.formatLang(form['date_from'], date=True) + _(' to ')+self.formatLang(form['date_to'], date=True) + return _('From ') + self.formatLang(form['date_from'], date=True) + _(' to ') + self.formatLang(form['date_to'], date=True) elif form['filter'] in ['byperiod', 'all']: aux = [] period_obj = self.pool.get('account.period') @@ -131,7 +132,7 @@ class account_balance(report_sxw.rml_parse): aux.append(period.date_start) aux.append(period.date_stop) sorted(aux) - return _('From ')+self.formatLang(aux[0], date=True)+_(' to ')+self.formatLang(aux[-1], date=True) + return _('From ') + self.formatLang(aux[0], date=True) + _(' to ') + self.formatLang(aux[-1], date=True) def get_periods_and_date_text(self, form): """ @@ -215,10 +216,10 @@ class account_balance(report_sxw.rml_parse): INNER JOIN account_move am ON am.id = aml.move_id %s GROUP BY p_idx, partner_name - """ + """ WHERE_POSTED = '' - if ctx.get('state','posted')=='posted': + if ctx.get('state', 'posted') == 'posted': WHERE_POSTED = "AND am.state = 'posted'" cur_periods = ', '.join([str(i) for i in ctx['periods']]) @@ -229,11 +230,11 @@ class account_balance(report_sxw.rml_parse): AND aa.id = %s AND aml.state <> 'draft' """ % (init_periods, account['id']) - query_init = sql_query%('SUM(aml.debit) AS init_dr', - 'SUM(aml.credit) AS init_cr', - '0.0 AS bal_dr', - '0.0 AS bal_cr', - WHERE+WHERE_POSTED) + query_init = sql_query % ('SUM(aml.debit) AS init_dr', + 'SUM(aml.credit) AS init_cr', + '0.0 AS bal_dr', + '0.0 AS bal_cr', + WHERE + WHERE_POSTED) WHERE = """ WHERE aml.period_id IN (%s) @@ -241,11 +242,11 @@ class account_balance(report_sxw.rml_parse): AND aml.state <> 'draft' """ % (cur_periods, account['id']) - query_bal = sql_query%('0.0 AS init_dr', - '0.0 AS init_cr', - 'SUM(aml.debit) AS bal_dr', - 'SUM(aml.credit) AS bal_cr', - WHERE+WHERE_POSTED) + query_bal = sql_query % ('0.0 AS init_dr', + '0.0 AS init_cr', + 'SUM(aml.debit) AS bal_dr', + 'SUM(aml.credit) AS bal_cr', + WHERE + WHERE_POSTED) query = ''' SELECT @@ -263,14 +264,15 @@ class account_balance(report_sxw.rml_parse): ) v GROUP BY p_idx, partner_name ORDER BY partner_name - '''%(query_init,query_bal) + ''' % (query_init, query_bal) self.cr.execute(query) res_dict = self.cr.dictfetchall() unknown = False for det in res_dict: - i,d,c,b = det['balanceinit'], det['debit'], det['credit'], det['balance'], - if not any([i,d,c,b]): + i, d, c, b = det['balanceinit'], det[ + 'debit'], det['credit'], det['balance'], + if not any([i, d, c, b]): continue data = { 'partner_name': det['partner_name'], @@ -296,7 +298,7 @@ class account_balance(report_sxw.rml_parse): #~ periods = str(tuple(ctx['periods'])) where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % ( periods, account['id']) - if ctx.get('state','posted')=='posted': + if ctx.get('state', 'posted') == 'posted': where += "AND am.state = 'posted'" sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion, (select name from res_partner where aml.partner_id = id) as partner, @@ -346,7 +348,7 @@ class account_balance(report_sxw.rml_parse): #~ periods = str(tuple(ctx['periods'])) where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % ( periods, account['id']) - if ctx.get('state','posted')=='posted': + if ctx.get('state', 'posted') == 'posted': where += "AND am.state = 'posted'" sql_detalle = """SELECT DISTINCT am.id as am_id, @@ -370,9 +372,9 @@ class account_balance(report_sxw.rml_parse): 'name': det['name'], 'date': det['date'], 'period': det['periodo'], - 'obj': am_obj.browse(self.cr,self.uid,det['am_id']) + 'obj': am_obj.browse(self.cr, self.uid, det['am_id']) }) - print 'ACCOUNT NAME', am_obj.browse(self.cr,self.uid,det['am_id']).name + print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid, det['am_id']).name return res def lines(self, form, level=0): @@ -405,11 +407,9 @@ class account_balance(report_sxw.rml_parse): ids2.append([aa_brw.id, True, True, aa_brw]) return ids2 - - ############################################################################# + ####################################################################### # CONTEXT FOR ENDIND BALANCE # ####################################################################### - def _ctx_end(ctx): ctx_end = ctx ctx_end['filter'] = form.get('filter', 'all') @@ -443,7 +443,7 @@ class account_balance(report_sxw.rml_parse): ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( 'fiscalyear_id', '=', ctx_init['fiscalyear']), ('date_stop', '<', fiscalyear.date_start)]) return ctx_init - ############################################################################# + ####################################################################### # CONTEXT FOR INITIAL BALANCE # ####################################################################### @@ -490,7 +490,7 @@ class account_balance(report_sxw.rml_parse): if 'account_list' in form and form['account_list']: account_ids = form['account_list'] - account_list= form['account_list'] + account_list = form['account_list'] del form['account_list'] credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[ @@ -586,38 +586,41 @@ class account_balance(report_sxw.rml_parse): tot = {} ############################################################### - # Calculations of credit, debit and balance, + # Calculations of credit, debit and balance, # without repeating operations. ############################################################### account_black_ids = account_obj.search(self.cr, self.uid, ( [('id', 'in', [i[0] for i in all_account_ids]), ('type', 'not in', - ('view', 'consolidation'))])) + ('view', 'consolidation'))])) account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ - i[0] for i in all_account_ids]),('type', '=', 'view')])) + i[0] for i in all_account_ids]), ('type', '=', 'view')])) acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ - i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))])) + i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))])) account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol( - self.cr, self.uid, acc_cons_ids) or [] + self.cr, self.uid, acc_cons_ids) or [] account_black_ids += account_obj.search(self.cr, self.uid, ( - [('id', 'in', account_consol_ids ), - ('type', 'not in', - ('view', 'consolidation'))])) + [('id', 'in', account_consol_ids), + ('type', 'not in', + ('view', 'consolidation'))])) account_black_ids = list(set(account_black_ids)) c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([ - ('id', 'in', account_consol_ids), - ('type', '=', 'view')])) + ('id', 'in', + account_consol_ids), + ('type', '=', 'view')])) delete_cons = False if c_account_not_black_ids: - delete_cons = set(account_not_black_ids) & set(c_account_not_black_ids) and True or False - account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids)) + delete_cons = set(account_not_black_ids) & set( + c_account_not_black_ids) and True or False + account_not_black_ids = list( + set(account_not_black_ids) - set(c_account_not_black_ids)) # This could be done quickly with a sql sentence account_not_black = account_obj.browse( @@ -633,7 +636,8 @@ class account_balance(report_sxw.rml_parse): c_account_not_black_ids = [i.id for i in c_account_not_black] if delete_cons: - account_not_black_ids = c_account_not_black_ids + account_not_black_ids + account_not_black_ids = c_account_not_black_ids + \ + account_not_black_ids account_not_black = c_account_not_black + account_not_black else: acc_cons_brw = account_obj.browse( @@ -642,11 +646,13 @@ class account_balance(report_sxw.rml_parse): acc_cons_brw.reverse() acc_cons_ids = [i.id for i in acc_cons_brw] - account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids - account_not_black = c_account_not_black + acc_cons_brw + account_not_black + account_not_black_ids = c_account_not_black_ids + \ + acc_cons_ids + account_not_black_ids + account_not_black = c_account_not_black + \ + acc_cons_brw + account_not_black + + all_account_period = {} # All accounts per period - all_account_period = {} # All accounts per period - # Iteration limit depending on the number of columns if form['columns'] == 'thirteen': limit = 13 @@ -657,7 +663,7 @@ class account_balance(report_sxw.rml_parse): for p_act in range(limit): if limit != 1: - if p_act == limit-1: + if p_act == limit - 1: form['periods'] = period_ids else: if form['columns'] == 'thirteen': @@ -687,7 +693,7 @@ class account_balance(report_sxw.rml_parse): 'obj': i, 'debit': d, 'credit': c, - 'balance': d-c + 'balance': d - c } if form['inf_type'] == 'BS': dict_black.get(i.id)['balanceinit'] = 0.0 @@ -707,12 +713,12 @@ class account_balance(report_sxw.rml_parse): dict_not_black.get(i.id)['balanceinit'] = 0.0 all_account = dict_black.copy( - ) #It makes a copy because they modify + ) # It makes a copy because they modify for acc_id in account_not_black_ids: - acc_childs = dict_not_black.get(acc_id).get('obj').type=='view' \ - and dict_not_black.get(acc_id).get('obj').child_id \ - or dict_not_black.get(acc_id).get('obj').child_consol_ids + acc_childs = dict_not_black.get(acc_id).get('obj').type == 'view' \ + and dict_not_black.get(acc_id).get('obj').child_id \ + or dict_not_black.get(acc_id).get('obj').child_consol_ids for child_id in acc_childs: if child_id.type == 'consolidation' and delete_cons: continue @@ -727,7 +733,7 @@ class account_balance(report_sxw.rml_parse): child_id.id).get('balanceinit') all_account[acc_id] = dict_not_black[acc_id] - if p_act == limit-1: + if p_act == limit - 1: all_account_period['all'] = all_account else: if form['columns'] == 'thirteen': @@ -765,7 +771,7 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get(pn-1).get(id).get('debit', 0.0), all_account_period.get(pn-1).get(id).get('credit', 0.0), all_account_period.get(pn-1).get(id).get('balance', 0.0)]) + all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0), all_account_period.get(pn - 1).get(id).get('balance', 0.0)]) res.update({ 'dbr%s' % pn: self.exchange(d), 'cdr%s' % pn: self.exchange(c), @@ -773,8 +779,8 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get(pn-1).get(id).get('balanceinit', 0.0), all_account_period.get(pn-1).get(id).get('debit', 0.0), all_account_period.get(pn-1).get(id).get('credit', 0.0)]) - b = z(i+d-c) + all_account_period.get(pn - 1).get(id).get('balanceinit', 0.0), all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0)]) + b = z(i + d - c) res.update({ 'dbr%s' % pn: self.exchange(d), 'cdr%s' % pn: self.exchange(c), @@ -783,7 +789,7 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit',0.0), all_account_period.get('all').get(id).get('balance')]) + all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance')]) res.update({ 'dbr5': self.exchange(d), 'cdr5': self.exchange(c), @@ -791,8 +797,8 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit',0.0)]) - b = z(i+d-c) + all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) + b = z(i + d - c) res.update({ 'dbr5': self.exchange(d), 'cdr5': self.exchange(c), @@ -814,7 +820,7 @@ class account_balance(report_sxw.rml_parse): else: i, d, c = map(z, [ all_account_period.get(p_num).get(id).get('balanceinit', 0.0), all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0)]) - b = z(i+d-c) + b = z(i + d - c) res.update({ 'dbr%s' % pn: self.exchange(d), 'cdr%s' % pn: self.exchange(c), @@ -834,7 +840,7 @@ class account_balance(report_sxw.rml_parse): else: i, d, c = map(z, [ all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) - b = z(i+d-c) + b = z(i + d - c) res.update({ 'dbr13': self.exchange(d), 'cdr13': self.exchange(c), @@ -844,17 +850,17 @@ class account_balance(report_sxw.rml_parse): else: i, d, c = map(z, [ all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) - b = z(i+d-c) + b = z(i + d - c) res.update({ 'balanceinit': self.exchange(i), 'debit': self.exchange(d), 'credit': self.exchange(c), - 'ytd': self.exchange(d-c), + 'ytd': self.exchange(d - c), }) if form['inf_type'] == 'IS' and form['columns'] == 'one': res.update({ - 'balance': self.exchange(d-c), + 'balance': self.exchange(d - c), }) else: res.update({ @@ -870,7 +876,7 @@ class account_balance(report_sxw.rml_parse): to_test = [False] if form['display_account'] == 'mov' and aa_id[3].parent_id: # Include accounts with movements - for x in range(pn-1): + for x in range(pn - 1): to_test.append(res.get( 'dbr%s' % x, 0.0) >= 0.005 and True or False) to_test.append(res.get( @@ -880,7 +886,7 @@ class account_balance(report_sxw.rml_parse): elif form['display_account'] == 'bal' and aa_id[3].parent_id: # Include accounts with balance - for x in range(pn-1): + for x in range(pn - 1): to_test.append(res.get( 'bal%s' % x, 0.0) >= 0.005 and True or False) if any(to_test): @@ -888,7 +894,7 @@ class account_balance(report_sxw.rml_parse): elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id: # Include accounts with balance or movements - for x in range(pn-1): + for x in range(pn - 1): to_test.append(res.get( 'bal%s' % x, 0.0) >= 0.005 and True or False) to_test.append(res.get( @@ -925,7 +931,8 @@ class account_balance(report_sxw.rml_parse): elif to_include and form['journal_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): res['journal'] = self._get_journal_ledger(res, ctx=ctx_end) elif to_include and form['partner_balance'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): - res['partner'] = self._get_partner_balance(res, ctx_i['periods'], ctx=ctx_end) + res['partner'] = self._get_partner_balance( + res, ctx_i['periods'], ctx=ctx_end) else: res['mayor'] = [] @@ -1035,13 +1042,13 @@ report_sxw.report_sxw('report.afr.analytic.ledger', 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml', parser=account_balance, header=False) - + report_sxw.report_sxw('report.afr.partner.balance', 'wizard.report', 'account_financial_report/report/balance_full_4_cols_partner_balance.rml', parser=account_balance, header=False) - + report_sxw.report_sxw('report.afr.journal.ledger', 'wizard.report', 'account_financial_report/report/balance_full_4_cols_journal_ledger.rml', @@ -1065,4 +1072,3 @@ report_sxw.report_sxw('report.afr.13cols', 'account_financial_report/report/balance_full_13_cols.rml', parser=account_balance, header=False) - diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index aea0afff..5708402f 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.py @@ -51,16 +51,16 @@ class wizard_report(osv.osv_memory): 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), 'journal_ledger': fields.boolean('Journal Ledger', help="Allows to Generate an Journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'partner_balance': fields.boolean('Partner Balance', help="""Allows to - Generate a Partner Balance for accounts with moves. Available when - Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"""), + 'partner_balance': fields.boolean('Partner Balance', help="Allows to " + "Generate a Partner Balance for accounts with moves. Available when " + "Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'lab_str': fields.char('Description', help='Description for the Summary', size=128), 'target_move': fields.selection([('posted', 'All Posted Entries'), ('all', 'All Entries'), ], 'Entries to Include', required=True, - help='Print All Accounting Entries or just Posted Accounting Entries'), + help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), 'date_to': fields.date('End date'),