diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index 3317c26de57..5df50566b0d 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -35,8 +35,8 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): 'lines': self.lines, 'sum_debit_partner': self._sum_debit_partner, 'sum_credit_partner': self._sum_credit_partner, - 'sum_debit': self._sum_debit, - 'sum_credit': self._sum_credit, +# 'sum_debit': self._sum_debit, +# 'sum_credit': self._sum_credit, 'get_currency': self._get_currency, 'comma_me' : self.comma_me, 'get_start_period': self.get_start_period, @@ -185,10 +185,29 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): move_state = ['posted'] result_tmp = 0.0 + result_init = 0.0 if self.reconcil : RECONCILE_TAG = " " else: RECONCILE_TAG = "AND reconcile_id IS NULL" + if self.initial_balance: + self.cr.execute( + "SELECT sum(debit) " \ + "FROM account_move_line AS l, " \ + "account_move AS m " + "WHERE partner_id = %s" \ + "AND m.id = l.move_id " \ + "AND m.state IN %s " + "AND account_id IN %s" \ + " " + RECONCILE_TAG + " " \ + "AND " + self.init_query + " ", + (partner.id, tuple(move_state), tuple(self.account_ids))) + contemp = self.cr.fetchone() + if contemp != None: + result_init = contemp[0] or 0.0 + else: + result_init = result_tmp + 0.0 + self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line AS l, " \ @@ -206,7 +225,8 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): result_tmp = contemp[0] or 0.0 else: result_tmp = result_tmp + 0.0 - return result_tmp + + return result_tmp + result_init def _sum_credit_partner(self, partner): move_state = ['draft','posted'] @@ -214,10 +234,29 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): move_state = ['posted'] result_tmp = 0.0 + result_init = 0.0 if self.reconcil : RECONCILE_TAG = " " else: RECONCILE_TAG = "AND reconcile_id IS NULL" + if self.initial_balance: + self.cr.execute( + "SELECT sum(credit) " \ + "FROM account_move_line AS l, " \ + "account_move AS m " + "WHERE partner_id = %s" \ + "AND m.id = l.move_id " \ + "AND m.state IN %s " + "AND account_id IN %s" \ + " " + RECONCILE_TAG + " " \ + "AND " + self.init_query + " ", + (partner.id, tuple(move_state), tuple(self.account_ids))) + contemp = self.cr.fetchone() + if contemp != None: + result_init = contemp[0] or 0.0 + else: + result_init = result_tmp + 0.0 + self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line AS l, " \ @@ -231,111 +270,111 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): (partner.id, tuple(move_state), tuple(self.account_ids),)) contemp = self.cr.fetchone() - if contemp != None: - result_tmp = contemp[0] or 0.0 - else: - result_tmp = result_tmp + 0.0 - return result_tmp - - def _sum_debit(self): - move_state = ['draft','posted'] - if self.target_move == 'posted': - move_state = ['posted'] - - if not self.ids: - return 0.0 - result_tmp = 0.0 - result_init = 0.0 - if self.reconcil : - RECONCILE_TAG = " " - else: - RECONCILE_TAG = "AND reconcile_id IS NULL" - if self.initial_balance: - self.cr.execute( - "SELECT sum(debit) " \ - "FROM account_move_line AS l, " \ - "account_move AS m " - "WHERE partner_id IN %s" \ - "AND m.id = l.move_id " \ - "AND m.state IN %s " - "AND account_id IN %s" \ - "AND reconcile_id IS NULL " \ - "AND " + self.init_query + " ", - (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids))) - contemp = self.cr.fetchone() - if contemp != None: - result_init = contemp[0] or 0.0 - else: - result_init = result_tmp + 0.0 - - self.cr.execute( - "SELECT sum(debit) " \ - "FROM account_move_line AS l, " \ - "account_move AS m " - "WHERE partner_id IN %s" \ - "AND m.id = l.move_id " \ - "AND m.state IN %s " - "AND account_id IN %s" \ - " " + RECONCILE_TAG + " " \ - "AND " + self.query + " " , - (tuple(self.partner_ids), tuple(move_state) ,tuple(self.account_ids),)) - contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 else: result_tmp = result_tmp + 0.0 return result_tmp + result_init - def _sum_credit(self): - move_state = ['draft','posted'] - if self.target_move == 'posted': - move_state = ['posted'] - - if not self.ids: - return 0.0 - result_tmp = 0.0 - result_init = 0.0 - if self.reconcil : - RECONCILE_TAG = " " - else: - RECONCILE_TAG = "AND reconcile_id IS NULL" - if self.initial_balance: - self.cr.execute( - "SELECT sum(credit) " \ - "FROM account_move_line AS l, " \ - "account_move AS m " - "WHERE partner_id IN %s" \ - "AND m.id = l.move_id " \ - "AND m.state IN %s " - "AND account_id IN %s" \ - "AND reconcile_id IS NULL " \ - "AND " + self.init_query + " ", - (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids))) - contemp = self.cr.fetchone() - if contemp != None: - result_init = contemp[0] or 0.0 - else: - result_init = result_tmp + 0.0 - - self.cr.execute( - "SELECT sum(credit) " \ - "FROM account_move_line AS l, " \ - "account_move AS m " - "WHERE partner_id IN %s" \ - "AND m.id = l.move_id " \ - "AND m.state IN %s " - "AND account_id IN %s" \ - " " + RECONCILE_TAG + " " \ - "AND " + self.query + " " , - (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids),)) - contemp = self.cr.fetchone() - if contemp != None: - result_tmp = contemp[0] or 0.0 - else: - result_tmp = result_tmp + 0.0 - - return result_tmp + result_init + # code is deprecated +# def _sum_debit(self): +# move_state = ['draft','posted'] +# if self.target_move == 'posted': +# move_state = ['posted'] # +# if not self.ids: +# return 0.0 +# result_tmp = 0.0 +# result_init = 0.0 +# if self.reconcil : +# RECONCILE_TAG = " " +# else: +# RECONCILE_TAG = "AND reconcile_id IS NULL" +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(debit) " \ +# "FROM account_move_line AS l, " \ +# "account_move AS m " +# "WHERE partner_id IN %s" \ +# "AND m.id = l.move_id " \ +# "AND m.state IN %s " +# "AND account_id IN %s" \ +# "AND reconcile_id IS NULL " \ +# "AND " + self.init_query + " ", +# (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids))) +# contemp = self.cr.fetchone() +# if contemp != None: +# result_init = contemp[0] or 0.0 +# else: +# result_init = result_tmp + 0.0 +# +# self.cr.execute( +# "SELECT sum(debit) " \ +# "FROM account_move_line AS l, " \ +# "account_move AS m " +# "WHERE partner_id IN %s" \ +# "AND m.id = l.move_id " \ +# "AND m.state IN %s " +# "AND account_id IN %s" \ +# " " + RECONCILE_TAG + " " \ +# "AND " + self.query + " " , +# (tuple(self.partner_ids), tuple(move_state) ,tuple(self.account_ids),)) +# contemp = self.cr.fetchone() +# if contemp != None: +# result_tmp = contemp[0] or 0.0 +# else: +# result_tmp = result_tmp + 0.0 +# return result_tmp + result_init +# +# def _sum_credit(self): +# move_state = ['draft','posted'] +# if self.target_move == 'posted': +# move_state = ['posted'] +# +# if not self.ids: +# return 0.0 +# result_tmp = 0.0 +# result_init = 0.0 +# if self.reconcil : +# RECONCILE_TAG = " " +# else: +# RECONCILE_TAG = "AND reconcile_id IS NULL" +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(credit) " \ +# "FROM account_move_line AS l, " \ +# "account_move AS m " +# "WHERE partner_id IN %s" \ +# "AND m.id = l.move_id " \ +# "AND m.state IN %s " +# "AND account_id IN %s" \ +# "AND reconcile_id IS NULL " \ +# "AND " + self.init_query + " ", +# (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids))) +# contemp = self.cr.fetchone() +# if contemp != None: +# result_init = contemp[0] or 0.0 +# else: +# result_init = result_tmp + 0.0 +# +# self.cr.execute( +# "SELECT sum(credit) " \ +# "FROM account_move_line AS l, " \ +# "account_move AS m " +# "WHERE partner_id IN %s" \ +# "AND m.id = l.move_id " \ +# "AND m.state IN %s " +# "AND account_id IN %s" \ +# " " + RECONCILE_TAG + " " \ +# "AND " + self.query + " " , +# (tuple(self.partner_ids), tuple(move_state), tuple(self.account_ids),)) +# contemp = self.cr.fetchone() +# if contemp != None: +# result_tmp = contemp[0] or 0.0 +# else: +# result_tmp = result_tmp + 0.0 +# return result_tmp + result_init + def _get_partners(self): if self.result_selection == 'customer': return 'Receivable Accounts'