From 3d71503df84f8b6456f4c744d3801147a7c7a9df Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Tue, 14 Sep 2010 17:37:27 +0530 Subject: [PATCH] [IMP] account: Remove Initial Balance Logic from Partner Balance Report bzr revid: psi@tinyerp.co.in-20100914120727-mw6a3fhj2u32jj68 --- .../account/report/account_partner_balance.py | 194 +++++++++--------- .../wizard/account_report_partner_balance.py | 8 +- .../account_report_partner_balance_view.xml | 2 +- 3 files changed, 102 insertions(+), 102 deletions(-) diff --git a/addons/account/report/account_partner_balance.py b/addons/account/report/account_partner_balance.py index 5d6788f240c..83e9f03e0a4 100644 --- a/addons/account/report/account_partner_balance.py +++ b/addons/account/report/account_partner_balance.py @@ -99,12 +99,12 @@ class partner_balance(report_sxw.rml_parse, common_report_header): def set_context(self, objects, data, ids, report_type=None): ## Compute Code # - self.initial_balance = data['form'].get('initial_balance', True) - self.display_partner = data['form'].get('display_partner', 'non-zero_balance') +# self.initial_balance = data['form'].get('initial_balance', True) + self.display_partner = data['form'].get('display_partner', 'non-zero_balance') self.query = data['form'].get('query_line', '') self.init_query = data['form'].get('initial_bal_query', '') self.result_selection = data['form'].get('result_selection') - + if (self.result_selection == 'customer' ): self.ACCOUNT_TYPE = ('receivable',) elif (self.result_selection == 'supplier'): @@ -150,81 +150,81 @@ class partner_balance(report_sxw.rml_parse, common_report_header): res = self.cr.dictfetchall() #For include intial balance.. - if self.initial_balance: - self.cr.execute( - "SELECT '1' AS type, '' AS ref, l.account_id AS account_id, '' AS account_name, '' AS code, '' AS name, sum(debit) AS debit, sum(credit) AS credit, " \ - "CASE WHEN sum(debit) > sum(credit) " \ - "THEN sum(debit) - sum(credit) " \ - "ELSE 0 " \ - "END AS sdebit, " \ - "CASE WHEN sum(debit) < sum(credit) " \ - "THEN sum(credit) - sum(debit) " \ - "ELSE 0 " \ - "END AS scredit, " \ - "(SELECT sum(debit-credit) " \ - "FROM account_move_line l " \ - "WHERE partner_id = p.id " \ - " AND " + self.init_query + " " \ - "AND blocked = TRUE " \ - ") AS enlitige " \ - "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ - "JOIN account_account ac ON (l.account_id = ac.id) " \ - "WHERE ac.type IN %s " \ - "AND " + self.init_query + "" \ - "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id, p.name", - (self.ACCOUNT_TYPE, )) - res1 = self.cr.dictfetchall() - final_init = {} - res_init = {} - debit = credit = 0 - for r in res1: - if final_init.get(r['account_id'], False): - res_init = final_init[r['account_id']] - debit += final_init[r['account_id']]['debit'] - credit += final_init[r['account_id']]['credit'] - res_init['credit'] = credit - res_init['debit'] = debit - res_init['type'] = 3 - res_init['ref'] = '' - res_init['code'] = '' - res_init['name'] = 'Initial Balance' - res_init['balance'] = debit - credit - res_init['enlitige'] = 0.0 # fix me - res_init['account_id'] = final_init[r['account_id']]['account_id'] - else: - res_init = {} - debit = r['debit'] - credit = r['credit'] - res_init['credit'] = credit - res_init['debit'] = debit - res_init['type'] = 3 - res_init['ref'] = '' - res_init['code'] = '' - res_init['name'] = 'Initial Balance' - res_init['balance'] = debit - credit - res_init['enlitige'] = 0.0 # fix me - res_init['account_id'] = r['account_id'] - final_init[r['account_id']] = res_init - +# if self.initial_balance: +# self.cr.execute( +# "SELECT '1' AS type, '' AS ref, l.account_id AS account_id, '' AS account_name, '' AS code, '' AS name, sum(debit) AS debit, sum(credit) AS credit, " \ +# "CASE WHEN sum(debit) > sum(credit) " \ +# "THEN sum(debit) - sum(credit) " \ +# "ELSE 0 " \ +# "END AS sdebit, " \ +# "CASE WHEN sum(debit) < sum(credit) " \ +# "THEN sum(credit) - sum(debit) " \ +# "ELSE 0 " \ +# "END AS scredit, " \ +# "(SELECT sum(debit-credit) " \ +# "FROM account_move_line l " \ +# "WHERE partner_id = p.id " \ +# " AND " + self.init_query + " " \ +# "AND blocked = TRUE " \ +# ") AS enlitige " \ +# "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ +# "JOIN account_account ac ON (l.account_id = ac.id) " \ +# "WHERE ac.type IN %s " \ +# "AND " + self.init_query + "" \ +# "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ +# "ORDER BY l.account_id, p.name", +# (self.ACCOUNT_TYPE, )) +# res1 = self.cr.dictfetchall() +# final_init = {} +# res_init = {} +# debit = credit = 0 +# for r in res1: +# if final_init.get(r['account_id'], False): +# res_init = final_init[r['account_id']] +# debit += final_init[r['account_id']]['debit'] +# credit += final_init[r['account_id']]['credit'] +# res_init['credit'] = credit +# res_init['debit'] = debit +# res_init['type'] = 3 +# res_init['ref'] = '' +# res_init['code'] = '' +# res_init['name'] = 'Initial Balance' +# res_init['balance'] = debit - credit +# res_init['enlitige'] = 0.0 # fix me +# res_init['account_id'] = final_init[r['account_id']]['account_id'] +# else: +# res_init = {} +# debit = r['debit'] +# credit = r['credit'] +# res_init['credit'] = credit +# res_init['debit'] = debit +# res_init['type'] = 3 +# res_init['ref'] = '' +# res_init['code'] = '' +# res_init['name'] = 'Initial Balance' +# res_init['balance'] = debit - credit +# res_init['enlitige'] = 0.0 # fix me +# res_init['account_id'] = r['account_id'] +# final_init[r['account_id']] = res_init + if self.display_partner == 'non-zero_balance': full_account = [r for r in res if r['sdebit'] > 0 or r['scredit'] > 0] else: full_account = [r for r in res] - + ## We will now compute Total subtotal_row = self._add_subtotal(full_account) - if not self.initial_balance: - return subtotal_row - - #If include initial balance is selected.. - subtotal = copy.deepcopy(subtotal_row) - init_acnt = [] - for row in subtotal_row: - if final_init and row.get('account_id', False) and not row['account_id'] in init_acnt and final_init.get(row['account_id'], False): - subtotal.insert(subtotal.index(row), final_init[row['account_id']]) - init_acnt.append(row['account_id']) - return subtotal +# if not self.initial_balance: +# return subtotal_row +# +# #If include initial balance is selected.. +# subtotal = copy.deepcopy(subtotal_row) +# init_acnt = [] +# for row in subtotal_row: +# if final_init and row.get('account_id', False) and not row['account_id'] in init_acnt and final_init.get(row['account_id'], False): +# subtotal.insert(subtotal.index(row), final_init[row['account_id']]) +# init_acnt.append(row['account_id']) + return subtotal_row def _add_subtotal(self, cleanarray): i = 0 @@ -354,14 +354,14 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND " + self.query + "" , (tuple(self.account_ids), )) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(debit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND " + self.init_query + "" , - (tuple(self.account_ids), )) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(debit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids), )) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_credit(self): @@ -375,14 +375,14 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND " + self.query + "" , (tuple(self.account_ids),)) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(credit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND " + self.init_query + "" , - (tuple(self.account_ids),)) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(credit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids),)) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_litige(self): @@ -397,15 +397,15 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND l.blocked=TRUE ", (tuple(self.account_ids), )) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(debit-credit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND l.blocked=TRUE "\ - "AND " + self.init_query + "" , - (tuple(self.account_ids), )) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(debit-credit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND l.blocked=TRUE "\ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids), )) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_sdebit(self): diff --git a/addons/account/wizard/account_report_partner_balance.py b/addons/account/wizard/account_report_partner_balance.py index 819889b5128..d67954c3784 100644 --- a/addons/account/wizard/account_report_partner_balance.py +++ b/addons/account/wizard/account_report_partner_balance.py @@ -29,13 +29,13 @@ class account_partner_balance(osv.osv_memory): _name = 'account.partner.balance' _description = 'Print Account Partner Balance' _columns = { - 'initial_balance': fields.boolean('Include Initial Balances' - ,help='It adds initial balance row on report which display previous sum amount of debit/credit/balance'), +# 'initial_balance': fields.boolean('Include Initial Balances' +# ,help='It adds initial balance row on report which display previous sum amount of debit/credit/balance'), 'display_partner': fields.selection([('non-zero_balance', 'With balance is not equal to 0'), ('all', 'All Partners')] ,'Display Partners') } _defaults = { - 'initial_balance': True, +# 'initial_balance': True, 'display_partner': 'non-zero_balance' } @@ -43,7 +43,7 @@ class account_partner_balance(osv.osv_memory): if context is None: context = {} data = self.pre_print_report(cr, uid, ids, data, query_line, context=context) - data['form'].update(self.read(cr, uid, ids, ['initial_balance', 'display_partner'])[0]) + data['form'].update(self.read(cr, uid, ids, ['display_partner'])[0]) return { 'type': 'ir.actions.report.xml', 'report_name': 'account.partner.balance', diff --git a/addons/account/wizard/account_report_partner_balance_view.xml b/addons/account/wizard/account_report_partner_balance_view.xml index dc75d032329..81dfada99cc 100644 --- a/addons/account/wizard/account_report_partner_balance_view.xml +++ b/addons/account/wizard/account_report_partner_balance_view.xml @@ -10,7 +10,7 @@ - +