|
@ -11,35 +11,6 @@ class OutstandingStatement(models.AbstractModel): |
|
|
_inherit = 'statement.common' |
|
|
_inherit = 'statement.common' |
|
|
_name = 'report.partner_statement.outstanding_statement' |
|
|
_name = 'report.partner_statement.outstanding_statement' |
|
|
|
|
|
|
|
|
def _display_lines_sql_q0(self, date_end): |
|
|
|
|
|
return str( |
|
|
|
|
|
self._cr.mogrify(""" |
|
|
|
|
|
SELECT l1.id, |
|
|
|
|
|
CASE WHEN l1.reconciled = TRUE and l1.balance > 0.0 |
|
|
|
|
|
THEN max(pd.max_date) |
|
|
|
|
|
WHEN l1.reconciled = TRUE and l1.balance < 0.0 |
|
|
|
|
|
THEN max(pc.max_date) |
|
|
|
|
|
ELSE null |
|
|
|
|
|
END as reconciled_date |
|
|
|
|
|
FROM account_move_line l1 |
|
|
|
|
|
LEFT JOIN (SELECT pr.* |
|
|
|
|
|
FROM account_partial_reconcile pr |
|
|
|
|
|
INNER JOIN account_move_line l2 |
|
|
|
|
|
ON pr.credit_move_id = l2.id |
|
|
|
|
|
WHERE l2.date <= %(date_end)s |
|
|
|
|
|
) as pd ON pd.debit_move_id = l1.id |
|
|
|
|
|
LEFT JOIN (SELECT pr.* |
|
|
|
|
|
FROM account_partial_reconcile pr |
|
|
|
|
|
INNER JOIN account_move_line l2 |
|
|
|
|
|
ON pr.debit_move_id = l2.id |
|
|
|
|
|
WHERE l2.date <= %(date_end)s |
|
|
|
|
|
) as pc ON pc.credit_move_id = l1.id |
|
|
|
|
|
GROUP BY l1.id |
|
|
|
|
|
""", locals() |
|
|
|
|
|
), |
|
|
|
|
|
"utf-8" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def _display_lines_sql_q1(self, partners, date_end, account_type): |
|
|
def _display_lines_sql_q1(self, partners, date_end, account_type): |
|
|
partners = tuple(partners) |
|
|
partners = tuple(partners) |
|
|
return str(self._cr.mogrify(""" |
|
|
return str(self._cr.mogrify(""" |
|
@ -68,7 +39,6 @@ class OutstandingStatement(models.AbstractModel): |
|
|
FROM account_move_line l |
|
|
FROM account_move_line l |
|
|
JOIN account_account_type at ON (at.id = l.user_type_id) |
|
|
JOIN account_account_type at ON (at.id = l.user_type_id) |
|
|
JOIN account_move m ON (l.move_id = m.id) |
|
|
JOIN account_move m ON (l.move_id = m.id) |
|
|
LEFT JOIN Q0 ON Q0.id = l.id |
|
|
|
|
|
LEFT JOIN (SELECT pr.* |
|
|
LEFT JOIN (SELECT pr.* |
|
|
FROM account_partial_reconcile pr |
|
|
FROM account_partial_reconcile pr |
|
|
INNER JOIN account_move_line l2 |
|
|
INNER JOIN account_move_line l2 |
|
@ -82,9 +52,13 @@ class OutstandingStatement(models.AbstractModel): |
|
|
WHERE l2.date <= %(date_end)s |
|
|
WHERE l2.date <= %(date_end)s |
|
|
) as pc ON pc.credit_move_id = l.id |
|
|
) as pc ON pc.credit_move_id = l.id |
|
|
WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)s |
|
|
WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)s |
|
|
AND (Q0.reconciled_date is null or |
|
|
|
|
|
Q0.reconciled_date > %(date_end)s) |
|
|
|
|
|
AND l.date <= %(date_end)s |
|
|
|
|
|
|
|
|
AND ( |
|
|
|
|
|
(pd.id IS NOT NULL AND |
|
|
|
|
|
pd.max_date <= %(date_end)s) OR |
|
|
|
|
|
(pc.id IS NOT NULL AND |
|
|
|
|
|
pc.max_date <= %(date_end)s) OR |
|
|
|
|
|
(pd.id IS NULL AND pc.id IS NULL) |
|
|
|
|
|
) AND l.date <= %(date_end)s |
|
|
GROUP BY l.partner_id, m.name, l.date, l.date_maturity, l.name, |
|
|
GROUP BY l.partner_id, m.name, l.date, l.date_maturity, l.name, |
|
|
l.ref, l.blocked, l.currency_id, |
|
|
l.ref, l.blocked, l.currency_id, |
|
|
l.balance, l.amount_currency, l.company_id |
|
|
l.balance, l.amount_currency, l.company_id |
|
@ -126,15 +100,13 @@ class OutstandingStatement(models.AbstractModel): |
|
|
partners = tuple(partner_ids) |
|
|
partners = tuple(partner_ids) |
|
|
# pylint: disable=E8103 |
|
|
# pylint: disable=E8103 |
|
|
self.env.cr.execute(""" |
|
|
self.env.cr.execute(""" |
|
|
WITH Q0 as (%s), |
|
|
|
|
|
Q1 AS (%s), |
|
|
|
|
|
|
|
|
WITH Q1 as (%s), |
|
|
Q2 AS (%s), |
|
|
Q2 AS (%s), |
|
|
Q3 AS (%s) |
|
|
Q3 AS (%s) |
|
|
SELECT partner_id, currency_id, move_id, date, date_maturity, debit, |
|
|
SELECT partner_id, currency_id, move_id, date, date_maturity, debit, |
|
|
credit, amount, open_amount, name, ref, blocked |
|
|
credit, amount, open_amount, name, ref, blocked |
|
|
FROM Q3 |
|
|
FROM Q3 |
|
|
ORDER BY date, date_maturity, move_id""" % ( |
|
|
ORDER BY date, date_maturity, move_id""" % ( |
|
|
self._display_lines_sql_q0(date_end), |
|
|
|
|
|
self._display_lines_sql_q1(partners, date_end, account_type), |
|
|
self._display_lines_sql_q1(partners, date_end, account_type), |
|
|
self._display_lines_sql_q2(), |
|
|
self._display_lines_sql_q2(), |
|
|
self._display_lines_sql_q3(company_id))) |
|
|
self._display_lines_sql_q3(company_id))) |
|
|