diff --git a/addons/account/report/account_partner_balance.py b/addons/account/report/account_partner_balance.py
index e135c837ff3..96be4e9b7d5 100644
--- a/addons/account/report/account_partner_balance.py
+++ b/addons/account/report/account_partner_balance.py
@@ -104,6 +104,7 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
self.query = data['form'].get('query_line', '')
self.init_query = data['form'].get('initial_bal_query', '')
self.result_selection = data['form'].get('result_selection')
+ self.target_move = data['form'].get('target_move', 'all')
if (self.result_selection == 'customer' ):
self.ACCOUNT_TYPE = ('receivable',)
@@ -122,6 +123,10 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return super(partner_balance, self).set_context(objects, data, ids, report_type=report_type)
def lines(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
full_account = []
result_tmp = 0.0
self.cr.execute(
@@ -142,11 +147,13 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
") 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)" \
+ "JOIN account_move am ON (am.id = l.move_id)" \
"WHERE ac.type IN %s " \
+ "AND am.state IN %s " \
"AND " + self.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,))
+ (self.ACCOUNT_TYPE, tuple(move_state)))
res = self.cr.dictfetchall()
#For include intial balance..
@@ -211,11 +218,11 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
full_account = [r for r in res if r['sdebit'] > 0 or r['scredit'] > 0]
else:
full_account = [r for r in res]
-
+
for rec in full_account:
if not rec.get('name', False):
rec.update({'name': 'No Partner Defined'})
-
+
## We will now compute Total
subtotal_row = self._add_subtotal(full_account)
# if not self.initial_balance:
@@ -348,15 +355,21 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return completearray
def _sum_debit(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
if not self.ids:
return 0.0
temp_res = 0.0
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line AS l " \
+ "JOIN account_move am ON (am.id = l.move_id)" \
"WHERE l.account_id IN %s" \
+ "AND am.state IN %s" \
"AND " + self.query + "" ,
- (tuple(self.account_ids), ))
+ (tuple(self.account_ids), tuple(move_state)))
temp_res = float(self.cr.fetchone()[0] or 0.0)
# if self.initial_balance:
# self.cr.execute(
@@ -369,15 +382,21 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return temp_res
def _sum_credit(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
if not self.ids:
return 0.0
temp_res = 0.0
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line AS l " \
+ "JOIN account_move am ON (am.id = l.move_id)" \
"WHERE l.account_id IN %s" \
+ "AND am.state IN %s" \
"AND " + self.query + "" ,
- (tuple(self.account_ids),))
+ (tuple(self.account_ids), tuple(move_state)))
temp_res = float(self.cr.fetchone()[0] or 0.0)
# if self.initial_balance:
# self.cr.execute(
@@ -390,16 +409,22 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return temp_res
def _sum_litige(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
if not self.ids:
return 0.0
temp_res = 0.0
self.cr.execute(
"SELECT sum(debit-credit) " \
"FROM account_move_line AS l " \
+ "JOIN account_move am ON (am.id = l.move_id)" \
"WHERE l.account_id IN %s" \
+ "AND am.state IN %s" \
"AND " + self.query + " " \
"AND l.blocked=TRUE ",
- (tuple(self.account_ids), ))
+ (tuple(self.account_ids), tuple(move_state), ))
temp_res = float(self.cr.fetchone()[0] or 0.0)
# if self.initial_balance:
# self.cr.execute(
@@ -413,6 +438,10 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return temp_res
def _sum_sdebit(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
if not self.ids:
return 0.0
result_tmp = 0.0
@@ -423,10 +452,12 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
"ELSE 0 " \
"END " \
"FROM account_move_line AS l " \
+ "JOIN account_move am ON (am.id = l.move_id)" \
"WHERE l.account_id IN %s" \
+ "AND am.state IN %s" \
"AND " + self.query + " " \
"GROUP BY l.partner_id",
- (tuple(self.account_ids),))
+ (tuple(self.account_ids), tuple(move_state),))
a = self.cr.fetchone()[0]
if self.cr.fetchone() != None:
@@ -436,6 +467,10 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return result_tmp
def _sum_scredit(self):
+ move_state = ['draft','posted']
+ if self.target_move == 'posted':
+ move_state = ['posted']
+
if not self.ids:
return 0.0
result_tmp = 0.0
@@ -447,9 +482,11 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
"END " \
"FROM account_move_line AS l " \
"WHERE l.account_id IN %s" \
+ "JOIN account_move am ON (am.id = l.move_id)" \
+ "AND am.state IN %s" \
"AND " + self.query + " " \
"GROUP BY l.partner_id",
- (tuple(self.account_ids), ))
+ (tuple(self.account_ids), tuple(move_state), ))
a = self.cr.fetchone()[0] or 0.0
if self.cr.fetchone() != None:
result_tmp = result_tmp + (a or 0.0)
diff --git a/addons/account/wizard/account_report_partner_balance.py b/addons/account/wizard/account_report_partner_balance.py
index d67954c3784..5e5ca64173b 100644
--- a/addons/account/wizard/account_report_partner_balance.py
+++ b/addons/account/wizard/account_report_partner_balance.py
@@ -32,18 +32,21 @@ class account_partner_balance(osv.osv_memory):
# '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')
+ ,'Display Partners'),
+ 'target_move': fields.selection([('all', 'All Entries'),
+ ('posted', 'All Posted Entries')], 'Target Moves', required=True),
}
_defaults = {
# 'initial_balance': True,
- 'display_partner': 'non-zero_balance'
+ 'display_partner': 'non-zero_balance',
+ 'target_move': 'all'
}
def _print_report(self, cr, uid, ids, data, query_line, context=None):
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, ['display_partner'])[0])
+ data['form'].update(self.read(cr, uid, ids, ['display_partner', 'target_move'])[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 81dfada99cc..2b970b45f93 100644
--- a/addons/account/wizard/account_report_partner_balance_view.xml
+++ b/addons/account/wizard/account_report_partner_balance_view.xml
@@ -12,6 +12,7 @@
+