summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorqdp-odoo <qdp@odoo.com>2016-06-03 17:58:30 +0200
committerqdp-odoo <qdp@odoo.com>2016-06-03 17:59:19 +0200
commit9d6b9cc93d64ede6e81c0893fbd6a268ffecf905 (patch)
treeb162de9a2982b28d7f788686820f90c25dafb151 /addons
parent4810513f3cb84e96888bd452577032c02652ed0c (diff)
[FIX] account: Filter on contact by total receivable/payable fixed. opw 669833
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/partner.py49
1 files changed, 22 insertions, 27 deletions
diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py
index 94cf8a82eaf..831dcd0d81e 100644
--- a/addons/account/models/partner.py
+++ b/addons/account/models/partner.py
@@ -252,40 +252,35 @@ class ResPartner(models.Model):
partner.debit = -val
@api.multi
- def _asset_difference_search(self, type, args):
- if not args:
+ def _asset_difference_search(self, account_type, operator, operand):
+ if operator not in ('<', '=', '>', '>=', '<='):
return []
- having_values = tuple(map(itemgetter(2), args))
- where = ' AND '.join(
- map(lambda x: '(SUM(bal2) %(operator)s %%s)' % {
- 'operator':x[1]},args))
- query = self.env['account.move.line']._query_get()
- self._cr.execute(('SELECT pid AS partner_id, SUM(bal2) FROM ' \
- '(SELECT CASE WHEN bal IS NOT NULL THEN bal ' \
- 'ELSE 0.0 END AS bal2, p.id as pid FROM ' \
- '(SELECT (debit-credit) AS bal, partner_id ' \
- 'FROM account_move_line l ' \
- 'WHERE account_id IN ' \
- '(SELECT id FROM account_account '\
- 'WHERE type=%s AND active) ' \
- 'AND reconciled IS FALSE ' \
- 'AND '+query+') AS l ' \
- 'RIGHT JOIN res_partner p ' \
- 'ON p.id = partner_id ) AS pl ' \
- 'GROUP BY pid HAVING ' + where),
- (type,) + having_values)
+ if type(operand) not in (float, int):
+ return []
+ sign = 1
+ if account_type == 'payable':
+ sign = -1
+ res = self._cr.execute('''
+ SELECT partner.id
+ FROM res_partner partner
+ LEFT JOIN account_move_line aml ON aml.partner_id = partner.id
+ RIGHT JOIN account_account acc ON aml.account_id = acc.id
+ WHERE acc.internal_type = %s
+ AND NOT acc.deprecated
+ GROUP BY partner.id
+ HAVING %s * COALESCE(SUM(aml.amount_residual), 0) ''' + operator + ''' %s''', (account_type, sign, operand))
res = self._cr.fetchall()
if not res:
return [('id', '=', '0')]
return [('id', 'in', map(itemgetter(0), res))]
- @api.multi
- def _credit_search(self, args):
- return self._asset_difference_search('receivable', args)
+ @api.model
+ def _credit_search(self, operator, operand):
+ return self._asset_difference_search('receivable', operator, operand)
- @api.multi
- def _debit_search(self, args):
- return self._asset_difference_search('payable', args)
+ @api.model
+ def _debit_search(self, operator, operand):
+ return self._asset_difference_search('payable', operator, operand)
@api.multi
def _invoice_total(self):