[MIG] partner_statement: Migration to 14.0
This commit is contained in:
@@ -38,66 +38,47 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
return str(
|
||||
self._cr.mogrify(
|
||||
"""
|
||||
SELECT l.partner_id, l.currency_id, l.company_id, l.move_id,
|
||||
(abs(COALESCE(l.balance, 0.0)) + sum(
|
||||
coalesce(pr.pr_sign, 0.0) * coalesce(pr.amount, 0.0))
|
||||
) * sign(COALESCE(l.balance, 0.0)) AS open_due,
|
||||
(abs(COALESCE(l.amount_currency, 0.0)) + sum(
|
||||
coalesce(pr.pr_sign, 0.0) * CASE
|
||||
WHEN pr.currency_id IS NOT NULL AND pr.currency_id = l.currency_id
|
||||
THEN coalesce(pr.amount_currency, 0.0)
|
||||
WHEN cur.id IS NOT NULL AND ROUND(
|
||||
abs(COALESCE(l.balance, 0.0)), cur.decimal_places) > 0.0
|
||||
THEN ROUND(coalesce(pr.amount, 0.0) *
|
||||
COALESCE(l.amount_currency, 0.0) / NULLIF(l.balance, 0.0),
|
||||
cur.decimal_places)
|
||||
ELSE ROUND(coalesce(pr.amount, 0.0) *
|
||||
COALESCE((
|
||||
SELECT r.rate FROM res_currency_rate r
|
||||
JOIN account_move_line aml
|
||||
ON pr.credit_move_id = aml.id
|
||||
WHERE r.currency_id = l.currency_id
|
||||
AND r.name <= aml.date
|
||||
AND (r.company_id IS NULL
|
||||
OR r.company_id = l.company_id)
|
||||
ORDER BY r.company_id, r.name DESC LIMIT 1), 1.0),
|
||||
cur.decimal_places)
|
||||
END)
|
||||
) * sign(COALESCE(l.amount_currency, 0.0)) AS open_due_currency,
|
||||
SELECT l.partner_id, l.currency_id, l.company_id, l.move_id,
|
||||
CASE WHEN l.balance > 0.0
|
||||
THEN l.balance - sum(coalesce(pd.amount, 0.0))
|
||||
ELSE l.balance + sum(coalesce(pc.amount, 0.0))
|
||||
END AS open_due,
|
||||
CASE WHEN l.balance > 0.0
|
||||
THEN l.amount_currency - sum(coalesce(pd.debit_amount_currency, 0.0))
|
||||
ELSE l.amount_currency + sum(coalesce(pc.credit_amount_currency, 0.0))
|
||||
END AS open_due_currency,
|
||||
CASE WHEN l.date_maturity is null
|
||||
THEN l.date
|
||||
ELSE l.date_maturity
|
||||
END as date_maturity
|
||||
FROM (
|
||||
SELECT l.*, CASE
|
||||
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
|
||||
AND ROUND(COALESCE(l.amount_currency, 0.0),
|
||||
cur.decimal_places) > 0.0 THEN 1
|
||||
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
|
||||
AND ROUND(COALESCE(l.amount_currency, 0.0),
|
||||
cur.decimal_places) < 0.0 THEN -1
|
||||
WHEN l.balance > 0.0 THEN 1 ELSE -1 END as sign
|
||||
END as date_maturity
|
||||
FROM account_move_line l
|
||||
LEFT JOIN res_currency cur ON cur.id = l.currency_id
|
||||
) l
|
||||
JOIN account_move m ON l.move_id = m.id
|
||||
LEFT JOIN res_currency cur ON cur.id = l.currency_id
|
||||
LEFT JOIN LATERAL (SELECT pr.*,
|
||||
CASE WHEN pr.credit_move_id = l.id THEN l.sign
|
||||
ELSE -l.sign END AS pr_sign
|
||||
FROM account_partial_reconcile pr
|
||||
WHERE pr.max_date <= %(date_end)s AND (
|
||||
(pr.debit_move_id = l.id) OR (pr.credit_move_id = l.id))
|
||||
) as pr ON TRUE
|
||||
WHERE l.partner_id IN %(partners)s
|
||||
AND l.account_internal_type = %(account_type)s
|
||||
AND (
|
||||
(pr.id IS NOT NULL AND pr.max_date <= %(date_end)s) OR
|
||||
(pr.id IS NULL)
|
||||
) AND l.date <= %(date_end)s AND not l.blocked
|
||||
AND m.state IN ('posted')
|
||||
GROUP BY l.partner_id, l.currency_id, l.date, l.date_maturity,
|
||||
l.amount_currency, l.balance, l.move_id, l.company_id, l.id
|
||||
JOIN account_move m ON (l.move_id = m.id)
|
||||
JOIN account_account aa ON (aa.id = l.account_id)
|
||||
JOIN account_account_type at ON (at.id = aa.user_type_id)
|
||||
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 = l.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 = l.id
|
||||
WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)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 AND not l.blocked
|
||||
AND m.state IN ('posted')
|
||||
GROUP BY l.partner_id, l.currency_id, l.date, l.date_maturity,
|
||||
l.amount_currency, l.balance, l.move_id,
|
||||
l.company_id, l.id
|
||||
""",
|
||||
locals(),
|
||||
),
|
||||
@@ -307,8 +288,8 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
)
|
||||
|
||||
@api.model
|
||||
# flake8: noqa: C901
|
||||
def _get_report_values(self, docids, data=None):
|
||||
# flake8: noqa: C901
|
||||
"""
|
||||
@return: returns a dict of parameters to pass to qweb report.
|
||||
the most important pair is {'data': res} which contains all
|
||||
|
||||
Reference in New Issue
Block a user