Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] partner_statement, add report current statement #1163

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions partner_statement/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Partner Statement
=================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down Expand Up @@ -147,7 +147,7 @@ promote its widespread use.

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-MiquelRForgeFlow|
|maintainer-MiquelRForgeFlow|

This module is part of the `OCA/account-financial-reporting <https://github.com/OCA/account-financial-reporting/tree/16.0/partner_statement>`_ project on GitHub.

Expand Down
2 changes: 2 additions & 0 deletions partner_statement/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from . import activity_statement_xlsx
from . import detailed_activity_statement_xlsx
from . import outstanting_statement_xlsx
from . import current_statement
from . import current_statement_xlsx
Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there too much difference between current_statement and outstanding_statement? If not, perhaps it's better to make current_statement be an inherit of outstanding_statement, the same way detailed_activity_statement inherits activity_statement. Surely it would reduce code.

Or maybe it should just get merged into the outstanding_statement by adding an extra boolean parameter.

159 changes: 159 additions & 0 deletions partner_statement/report/current_statement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Copyright 2018 ForgeFlow, S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class CurrentStatement(models.AbstractModel):
"""Model of Current Statement"""

_inherit = "statement.common"
_name = "report.partner_statement.current_statement"
_description = "Partner Current Statement"

def _display_lines_sql_q1(self, partners, date_end, account_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _display_lines_sql_q1(self, partners, date_end, account_type):
def _display_current_lines_sql_q1(self, partners, date_end, account_type):

same for the other methods

partners = tuple(partners)
return str(

Check warning on line 16 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L15-L16

Added lines #L15 - L16 were not covered by tests
self._cr.mogrify(
"""
SELECT l.id, m.name AS move_id, l.partner_id, l.date, l.name,
l.blocked, l.currency_id, l.company_id,
CASE WHEN l.ref IS NOT NULL
THEN l.ref
ELSE m.ref
END as ref,
CASE WHEN (l.currency_id is not null AND l.amount_currency > 0.0)
THEN avg(l.amount_currency)
ELSE avg(l.debit)
END as debit,
CASE WHEN (l.currency_id is not null AND l.amount_currency < 0.0)
THEN avg(l.amount_currency * (-1))
ELSE avg(l.credit)
END as credit,
CASE WHEN l.balance > 0.0
THEN round(l.balance - sum(coalesce(pd.amount, 0.0)),2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why apply round? if you have a good reason, then apply it to other reports too, but my opinion is not to apply it in the queries, as maybe you have a different rounding instead of 2. I think it should be applied somewhere in the python part of the code.

ELSE round(l.balance + sum(coalesce(pc.amount, 0.0)),2)
END AS open_amount,
CASE WHEN l.balance > 0.0
THEN round(l.amount_currency - sum(coalesce(pd.debit_amount_currency, 0.0)),2)
ELSE round(l.amount_currency + sum(coalesce(pc.credit_amount_currency, 0.0)),2)
END AS open_amount_currency,
CASE WHEN l.date_maturity is null
THEN l.date
ELSE l.date_maturity
END as date_maturity,
CASE WHEN
coalesce(l.date_maturity,l.date)::date
< date_trunc('month', date %(date_end)s)::date
THEN 0
ELSE 1
END current_month
FROM account_move_line l
JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_move m ON (l.move_id = m.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 aa.account_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 m.state IN ('posted')
GROUP BY l.id, l.partner_id, m.name, l.date, l.date_maturity, l.name,
CASE WHEN l.ref IS NOT NULL
THEN l.ref
ELSE m.ref
END,
l.blocked, l.currency_id, l.balance, l.amount_currency, l.company_id
""",
locals(),
),
"utf-8",
)

def _display_lines_sql_q2(self):
return str(

Check warning on line 87 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L87

Added line #L87 was not covered by tests
self._cr.mogrify(
"""
SELECT Q1.partner_id, Q1.currency_id, Q1.move_id,
Q1.date, Q1.date_maturity, Q1.debit, Q1.credit,
Q1.name, Q1.ref, Q1.blocked, Q1.company_id,
Q1.current_month,
CASE WHEN Q1.currency_id is not null
THEN Q1.open_amount_currency
ELSE Q1.open_amount
END as open_amount
FROM Q1
""",
locals(),
),
"utf-8",
)

def _display_lines_sql_q3(self, company_id):
return str(

Check warning on line 106 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L106

Added line #L106 was not covered by tests
self._cr.mogrify(
"""
SELECT Q2.partner_id, Q2.move_id, Q2.date, Q2.date_maturity,
Q2.name, Q2.ref, Q2.debit, Q2.credit,
Q2.debit-Q2.credit AS amount, blocked,
COALESCE(Q2.currency_id, c.currency_id) AS currency_id,
Q2.open_amount
FROM Q2
JOIN res_company c ON (c.id = Q2.company_id)
WHERE c.id = %(company_id)s AND (Q2.open_amount != 0.0
or Q2.current_month = 1)
""",
locals(),
),
"utf-8",
)

def _get_account_display_lines(
self, company_id, partner_ids, date_start, date_end, account_type
):
res = dict(map(lambda x: (x, []), partner_ids))
partners = tuple(partner_ids)

Check warning on line 128 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L128

Added line #L128 was not covered by tests
# pylint: disable=E8103
self.env.cr.execute(

Check warning on line 130 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L130

Added line #L130 was not covered by tests
"""
WITH Q1 as (%s),
Q2 AS (%s),
Q3 AS (%s)
SELECT partner_id, currency_id, move_id, date, date_maturity, debit,
credit, amount, open_amount, name, ref, blocked
FROM Q3
ORDER BY date, date_maturity, move_id"""
% (
self._display_lines_sql_q1(partners, date_end, account_type),
self._display_lines_sql_q2(),
self._display_lines_sql_q3(company_id),
)
)
for row in self.env.cr.dictfetchall():
res[row.pop("partner_id")].append(row)
return res

Check warning on line 147 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L146-L147

Added lines #L146 - L147 were not covered by tests

@api.model
def _get_report_values(self, docids, data=None):
if not data:
data = {}

Check warning on line 152 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L152

Added line #L152 was not covered by tests
if "company_id" not in data:
wiz = self.env["current.statement.wizard"].with_context(

Check warning on line 154 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L154

Added line #L154 was not covered by tests
active_ids=docids, model="res.partner"
)
data.update(wiz.create({})._prepare_statement())
data["amount_field"] = "open_amount"
return super()._get_report_values(docids, data)

Check warning on line 159 in partner_statement/report/current_statement.py

View check run for this annotation

Codecov / codecov/patch

partner_statement/report/current_statement.py#L157-L159

Added lines #L157 - L159 were not covered by tests
Loading
Loading