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':