[IMP] account: support of filtering on partner (category) in reports
This commit allow to filter easily on partners or partner categories in financial reports Was PR #23364 Was task: 36626
This commit is contained in:
@@ -1203,6 +1203,12 @@ class AccountMoveLine(models.Model):
|
||||
if context.get('analytic_account_ids'):
|
||||
domain += [('analytic_account_id', 'in', context['analytic_account_ids'].ids)]
|
||||
|
||||
if context.get('partner_ids'):
|
||||
domain += [('partner_id', 'in', context['partner_ids'].ids)]
|
||||
|
||||
if context.get('partner_categories'):
|
||||
domain += [('partner_id.category_id', 'in', context['partner_categories'].ids)]
|
||||
|
||||
where_clause = ""
|
||||
where_clause_params = []
|
||||
tables = ''
|
||||
|
||||
@@ -17,6 +17,7 @@ class ReportAgedPartnerBalance(models.AbstractModel):
|
||||
# Do an invoice and a payment and unreconcile. The amount will be nullified
|
||||
# By default, the partner wouldn't appear in this report.
|
||||
# The context key allow it to appear
|
||||
ctx = self._context
|
||||
periods = {}
|
||||
start = datetime.strptime(date_from, "%Y-%m-%d")
|
||||
for i in range(5)[::-1]:
|
||||
@@ -30,6 +31,7 @@ class ReportAgedPartnerBalance(models.AbstractModel):
|
||||
|
||||
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']
|
||||
@@ -45,6 +47,13 @@ class ReportAgedPartnerBalance(models.AbstractModel):
|
||||
if reconciled_after_date:
|
||||
reconciliation_clause = '(l.reconciled IS FALSE OR l.id IN %s)'
|
||||
arg_list += (tuple(reconciled_after_date),)
|
||||
if ctx.get('partner_ids'):
|
||||
partner_clause = 'AND (l.partner_id IN %s)'
|
||||
arg_list += (tuple(ctx['partner_ids'].ids),)
|
||||
if ctx.get('partner_categories'):
|
||||
partner_clause += 'AND (l.partner_id IN %s)'
|
||||
partner_ids = self.env['res.partner'].search([('category_id', 'in', ctx['partner_categories'].ids)]).ids
|
||||
arg_list += (tuple(partner_ids or [0]),)
|
||||
arg_list += (date_from, tuple(company_ids))
|
||||
query = '''
|
||||
SELECT DISTINCT l.partner_id, UPPER(res_partner.name)
|
||||
@@ -53,7 +62,7 @@ class ReportAgedPartnerBalance(models.AbstractModel):
|
||||
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)'''
|
||||
|
||||
Reference in New Issue
Block a user