Skip to content

Commit

Permalink
[IMP] account: add filter on partner reports for partner/ partner cat…
Browse files Browse the repository at this point in the history
…egory
  • Loading branch information
dbh-odoo committed Mar 12, 2018
1 parent 414b1ef commit b4f4602
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions addons/account/models/account_move.py
Expand Up @@ -1187,6 +1187,12 @@ def _query_get(self, domain=None):
if context.get('analytic_account_ids'):
domain += [('analytic_account_id', 'in', context['analytic_account_ids'].ids)]

if context.get('res_partners'):
domain += [('partner_id', 'in', context['res_partners'].ids)]

if context.get('res_partner_categories'):
domain += [('partner_id.category_id', 'in', context['res_partner_categories'].ids)]

where_clause = ""
where_clause_params = []
tables = ''
Expand Down
11 changes: 10 additions & 1 deletion addons/account/report/account_aged_partner_balance.py
Expand Up @@ -13,6 +13,7 @@ class ReportAgedPartnerBalance(models.AbstractModel):
_name = 'report.account.report_agedpartnerbalance'

def _get_partner_move_lines(self, account_type, date_from, target_move, period_length):
ctx = self._context
periods = {}
start = datetime.strptime(date_from, "%Y-%m-%d")
for i in range(5)[::-1]:
Expand All @@ -26,6 +27,7 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l

res = []
total = []
partner_clause = ''
cr = self.env.cr
company_ids = self.env.context.get('company_ids', (self.env.user.company_id.id,))
move_state = ['draft', 'posted']
Expand All @@ -41,6 +43,13 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
if reconciled_after_date:
reconciliation_clause = '(l.reconciled IS FALSE OR l.id IN %s)'
arg_list += (tuple(reconciled_after_date),)
if ctx.get('res_partners'):
partner_clause = 'AND (l.partner_id IN %s)'
arg_list += (tuple(ctx['res_partners'].ids),)
if ctx.get('res_partner_categories'):
partner_clause += 'AND (l.id IN %s)'
aml_partner_ids = self.env['account.move.line'].search([('partner_id.category_id', 'in', ctx['res_partner_categories'].ids)]).ids
arg_list += (tuple(aml_partner_ids or [0]),)
arg_list += (date_from, tuple(company_ids))
query = '''
SELECT DISTINCT l.partner_id, UPPER(res_partner.name)
Expand All @@ -49,7 +58,7 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
AND (l.move_id = am.id)
AND (am.state IN %s)
AND (account_account.internal_type IN %s)
AND ''' + reconciliation_clause + '''
AND ''' + reconciliation_clause + partner_clause + '''
AND (l.date <= %s)
AND l.company_id IN %s
ORDER BY UPPER(res_partner.name)'''
Expand Down

0 comments on commit b4f4602

Please sign in to comment.