[IMP] partner_statement: add Detailed Activity report
This commit is contained in:
@@ -34,6 +34,21 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
):
|
||||
return {}
|
||||
|
||||
def _get_account_display_prior_lines(
|
||||
self, company_id, partner_ids, date_start, date_end, account_type
|
||||
):
|
||||
return {}
|
||||
|
||||
def _get_account_display_reconciled_lines(
|
||||
self, company_id, partner_ids, date_start, date_end, account_type
|
||||
):
|
||||
return {}
|
||||
|
||||
def _get_account_display_ending_lines(
|
||||
self, company_id, partner_ids, date_start, date_end, account_type
|
||||
):
|
||||
return {}
|
||||
|
||||
def _show_buckets_sql_q1(self, partners, date_end, account_type):
|
||||
return str(
|
||||
self._cr.mogrify(
|
||||
@@ -273,16 +288,21 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
_("Total"),
|
||||
]
|
||||
|
||||
def _get_line_currency_defaults(self, currency_id, currencies, balance_forward):
|
||||
def _get_line_currency_defaults(
|
||||
self, currency_id, currencies, balance_forward, amount_due
|
||||
):
|
||||
if currency_id not in currencies:
|
||||
# This will only happen if currency is inactive
|
||||
currencies[currency_id] = self.env["res.currency"].browse(currency_id)
|
||||
return (
|
||||
{
|
||||
"prior_lines": [],
|
||||
"lines": [],
|
||||
"ending_lines": [],
|
||||
"buckets": [],
|
||||
"balance_forward": balance_forward,
|
||||
"amount_due": balance_forward,
|
||||
"amount_due": amount_due,
|
||||
"ending_balance": 0.0,
|
||||
},
|
||||
currencies,
|
||||
)
|
||||
@@ -290,6 +310,12 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
def _add_currency_line(self, line, currency):
|
||||
return [line]
|
||||
|
||||
def _add_currency_prior_line(self, line, currency):
|
||||
return [line]
|
||||
|
||||
def _add_currency_ending_line(self, line, currency):
|
||||
return [line]
|
||||
|
||||
@api.model
|
||||
def _get_report_values(self, docids, data=None):
|
||||
# flake8: noqa: C901
|
||||
@@ -325,6 +351,8 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
date_end = datetime.strptime(date_end, DEFAULT_SERVER_DATE_FORMAT).date()
|
||||
account_type = data["account_type"]
|
||||
aging_type = data["aging_type"]
|
||||
is_activity = data.get("is_activity")
|
||||
is_detailed = data.get("is_detailed")
|
||||
today = fields.Date.today()
|
||||
amount_field = data.get("amount_field", "amount")
|
||||
|
||||
@@ -344,9 +372,31 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
|
||||
res = {}
|
||||
# get base data
|
||||
prior_day = date_start - timedelta(days=1) if date_start else None
|
||||
prior_lines = (
|
||||
self._get_account_display_prior_lines(
|
||||
company_id, partner_ids, prior_day, prior_day, account_type
|
||||
)
|
||||
if is_detailed
|
||||
else {}
|
||||
)
|
||||
lines = self._get_account_display_lines(
|
||||
company_id, partner_ids, date_start, date_end, account_type
|
||||
)
|
||||
ending_lines = (
|
||||
self._get_account_display_ending_lines(
|
||||
company_id, partner_ids, date_start, date_end, account_type
|
||||
)
|
||||
if is_detailed
|
||||
else {}
|
||||
)
|
||||
reconciled_lines = (
|
||||
self._get_account_display_reconciled_lines(
|
||||
company_id, partner_ids, date_start, date_end, account_type
|
||||
)
|
||||
if is_activity
|
||||
else {}
|
||||
)
|
||||
balances_forward = self._get_account_initial_balance(
|
||||
company_id, partner_ids, date_start, account_type
|
||||
)
|
||||
@@ -359,7 +409,7 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
else:
|
||||
bucket_labels = {}
|
||||
|
||||
# organise and format for report
|
||||
# organize and format for report
|
||||
format_date = self._format_date_to_partner_lang
|
||||
partners_to_remove = set()
|
||||
for partner_id in partner_ids:
|
||||
@@ -369,6 +419,9 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
date_start, date_formats.get(partner_id, default_fmt)
|
||||
),
|
||||
"end": format_date(date_end, date_formats.get(partner_id, default_fmt)),
|
||||
"prior_day": format_date(
|
||||
prior_day, date_formats.get(partner_id, default_fmt)
|
||||
),
|
||||
"currencies": {},
|
||||
}
|
||||
currency_dict = res[partner_id]["currencies"]
|
||||
@@ -378,7 +431,32 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
currency_dict[line["currency_id"]],
|
||||
currencies,
|
||||
) = self._get_line_currency_defaults(
|
||||
line["currency_id"], currencies, line["balance"]
|
||||
line["currency_id"],
|
||||
currencies,
|
||||
line["balance"],
|
||||
0.0 if is_detailed else line["balance"],
|
||||
)
|
||||
|
||||
for line in prior_lines.get(partner_id, []):
|
||||
if line["currency_id"] not in currency_dict:
|
||||
(
|
||||
currency_dict[line["currency_id"]],
|
||||
currencies,
|
||||
) = self._get_line_currency_defaults(
|
||||
line["currency_id"], currencies, 0.0, 0.0
|
||||
)
|
||||
line_currency = currency_dict[line["currency_id"]]
|
||||
if not line["blocked"]:
|
||||
line_currency["amount_due"] += line["open_amount"]
|
||||
line["balance"] = line_currency["amount_due"]
|
||||
line["date"] = format_date(
|
||||
line["date"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line["date_maturity"] = format_date(
|
||||
line["date_maturity"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line_currency["prior_lines"].extend(
|
||||
self._add_currency_prior_line(line, currencies[line["currency_id"]])
|
||||
)
|
||||
|
||||
for line in lines[partner_id]:
|
||||
@@ -387,11 +465,59 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
currency_dict[line["currency_id"]],
|
||||
currencies,
|
||||
) = self._get_line_currency_defaults(
|
||||
line["currency_id"], currencies, 0.0
|
||||
line["currency_id"], currencies, 0.0, 0.0
|
||||
)
|
||||
line_currency = currency_dict[line["currency_id"]]
|
||||
if not line["blocked"]:
|
||||
line_currency["amount_due"] += line[amount_field]
|
||||
if not is_activity:
|
||||
line_currency["amount_due"] += line[amount_field]
|
||||
line["balance"] = line_currency["amount_due"]
|
||||
else:
|
||||
line_currency["ending_balance"] += line[amount_field]
|
||||
line["balance"] = line_currency["ending_balance"]
|
||||
line["date"] = format_date(
|
||||
line["date"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line["date_maturity"] = format_date(
|
||||
line["date_maturity"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line["reconciled_line"] = False
|
||||
if is_activity:
|
||||
line["open_amount"] = 0.0
|
||||
line["applied_amount"] = 0.0
|
||||
line_currency["lines"].extend(
|
||||
self._add_currency_line(line, currencies[line["currency_id"]])
|
||||
)
|
||||
for line2 in reconciled_lines:
|
||||
if line2["id"] in line["ids"]:
|
||||
line2["date"] = format_date(
|
||||
line2["date"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line2["date_maturity"] = format_date(
|
||||
line2["date_maturity"],
|
||||
date_formats.get(partner_id, default_fmt),
|
||||
)
|
||||
line2["reconciled_line"] = True
|
||||
line2["applied_amount"] = line2["open_amount"]
|
||||
line["applied_amount"] += line2["open_amount"]
|
||||
if is_detailed:
|
||||
line_currency["lines"].extend(
|
||||
self._add_currency_line(
|
||||
line2, currencies[line["currency_id"]]
|
||||
)
|
||||
)
|
||||
if is_activity:
|
||||
line["open_amount"] = line["amount"] + line["applied_amount"]
|
||||
line_currency["amount_due"] += line["open_amount"]
|
||||
|
||||
if is_detailed:
|
||||
for line_currency in currency_dict.values():
|
||||
line_currency["amount_due"] = 0.0
|
||||
|
||||
for line in ending_lines.get(partner_id, []):
|
||||
line_currency = currency_dict[line["currency_id"]]
|
||||
if not line["blocked"]:
|
||||
line_currency["amount_due"] += line["open_amount"]
|
||||
line["balance"] = line_currency["amount_due"]
|
||||
line["date"] = format_date(
|
||||
line["date"], date_formats.get(partner_id, default_fmt)
|
||||
@@ -399,8 +525,10 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
line["date_maturity"] = format_date(
|
||||
line["date_maturity"], date_formats.get(partner_id, default_fmt)
|
||||
)
|
||||
line_currency["lines"].extend(
|
||||
self._add_currency_line(line, currencies[line["currency_id"]])
|
||||
line_currency["ending_lines"].extend(
|
||||
self._add_currency_ending_line(
|
||||
line, currencies[line["currency_id"]]
|
||||
)
|
||||
)
|
||||
|
||||
if data["show_aging_buckets"]:
|
||||
@@ -410,7 +538,7 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
currency_dict[line["currency_id"]],
|
||||
currencies,
|
||||
) = self._get_line_currency_defaults(
|
||||
line["currency_id"], currencies, 0.0
|
||||
line["currency_id"], currencies, 0.0, 0.0
|
||||
)
|
||||
line_currency = currency_dict[line["currency_id"]]
|
||||
line_currency["buckets"] = line
|
||||
@@ -439,6 +567,7 @@ class ReportStatementCommon(models.AbstractModel):
|
||||
"company": self.env["res.company"].browse(company_id),
|
||||
"Currencies": currencies,
|
||||
"account_type": account_type,
|
||||
"is_detailed": is_detailed,
|
||||
"bucket_labels": bucket_labels,
|
||||
"get_inv_addr": self._get_invoice_address,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user