[IMP] partner_statement: add Detailed Activity report
This commit is contained in:
@@ -2,11 +2,23 @@
|
||||
# Copyright 2021 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo import _, models
|
||||
|
||||
from odoo.addons.report_xlsx_helper.report.report_xlsx_format import FORMATS
|
||||
|
||||
|
||||
def copy_format(book, fmt):
|
||||
properties = [f[4:] for f in dir(fmt) if f[0:4] == "set_"]
|
||||
dft_fmt = book.add_format()
|
||||
return book.add_format(
|
||||
{
|
||||
k: v
|
||||
for k, v in fmt.__dict__.items()
|
||||
if k in properties and dft_fmt.__dict__[k] != v
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ActivityStatementXslx(models.AbstractModel):
|
||||
_name = "report.p_s.report_activity_statement_xlsx"
|
||||
_description = "Activity Statement XLSL Report"
|
||||
@@ -36,7 +48,7 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
}
|
||||
|
||||
sheet.merge_range(
|
||||
row_pos, 0, row_pos, 6, statement_header, FORMATS["format_right_bold"]
|
||||
row_pos, 0, row_pos, 6, statement_header, FORMATS["format_left_bold"]
|
||||
)
|
||||
row_pos += 1
|
||||
sheet.write(
|
||||
@@ -47,20 +59,25 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
row_pos,
|
||||
2,
|
||||
row_pos,
|
||||
4,
|
||||
3,
|
||||
_("Description"),
|
||||
FORMATS["format_theader_yellow_center"],
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 5, _("Open Amount"), FORMATS["format_theader_yellow_center"]
|
||||
row_pos, 4, _("Original Amount"), FORMATS["format_theader_yellow_center"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 5, _("Applied Amount"), FORMATS["format_theader_yellow_center"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 6, _("Open Amount"), FORMATS["format_theader_yellow_center"]
|
||||
)
|
||||
sheet.write(row_pos, 6, _("Balance"), FORMATS["format_theader_yellow_center"])
|
||||
row_pos += 1
|
||||
sheet.write(
|
||||
row_pos, 1, partner_data.get("start"), FORMATS["format_tcell_date_left"]
|
||||
row_pos, 1, partner_data.get("prior_day"), FORMATS["format_tcell_date_left"]
|
||||
)
|
||||
sheet.merge_range(
|
||||
row_pos, 2, row_pos, 4, _("Balance Forward"), FORMATS["format_tcell_left"]
|
||||
row_pos, 2, row_pos, 5, _("Balance Forward"), FORMATS["format_tcell_left"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos,
|
||||
@@ -68,12 +85,21 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
currency_data.get("balance_forward"),
|
||||
FORMATS["current_money_format"],
|
||||
)
|
||||
format_tcell_left = FORMATS["format_tcell_left"]
|
||||
format_tcell_date_left = FORMATS["format_tcell_date_left"]
|
||||
format_distributed = FORMATS["format_distributed"]
|
||||
current_money_format = FORMATS["current_money_format"]
|
||||
for line in currency_data.get("lines"):
|
||||
if line.get("blocked"):
|
||||
format_tcell_left = FORMATS["format_tcell_left_blocked"]
|
||||
format_tcell_date_left = FORMATS["format_tcell_date_left_blocked"]
|
||||
format_distributed = FORMATS["format_distributed_blocked"]
|
||||
current_money_format = FORMATS["current_money_format_blocked"]
|
||||
row_pos += 1
|
||||
name_to_show = (
|
||||
line.get("name", "") == "/" or not line.get("name", "")
|
||||
) and line.get("ref", "")
|
||||
if line.get("name", "") != "/":
|
||||
if line.get("name", "") and line.get("name", "") != "/":
|
||||
if not line.get("ref", ""):
|
||||
name_to_show = line.get("name", "")
|
||||
else:
|
||||
@@ -83,30 +109,26 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
name_to_show = line.get("name", "")
|
||||
elif line.get("ref", "") not in line.get("name", ""):
|
||||
name_to_show = line.get("ref", "")
|
||||
sheet.write(row_pos, 0, line.get("move_id", ""), format_tcell_left)
|
||||
sheet.write(row_pos, 1, line.get("date", ""), format_tcell_date_left)
|
||||
sheet.merge_range(row_pos, 2, row_pos, 3, name_to_show, format_distributed)
|
||||
sheet.write(row_pos, 4, line.get("amount", ""), current_money_format)
|
||||
sheet.write(
|
||||
row_pos, 0, line.get("move_id", ""), FORMATS["format_tcell_left"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 1, line.get("date", ""), FORMATS["format_tcell_date_left"]
|
||||
)
|
||||
sheet.merge_range(
|
||||
row_pos, 2, row_pos, 4, name_to_show, FORMATS["format_distributed"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 5, line.get("amount", ""), FORMATS["current_money_format"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 6, line.get("balance", ""), FORMATS["current_money_format"]
|
||||
row_pos, 5, line.get("applied_amount", ""), current_money_format
|
||||
)
|
||||
sheet.write(row_pos, 6, line.get("open_amount", ""), current_money_format)
|
||||
row_pos += 1
|
||||
sheet.write(
|
||||
row_pos, 1, partner_data.get("end"), FORMATS["format_tcell_date_left"]
|
||||
)
|
||||
sheet.merge_range(
|
||||
row_pos, 2, row_pos, 4, _("Ending Balance"), FORMATS["format_tcell_left"]
|
||||
row_pos, 2, row_pos, 5, _("Ending Balance"), FORMATS["format_tcell_left"]
|
||||
)
|
||||
sheet.write(
|
||||
row_pos, 6, currency_data.get("amount_due"), FORMATS["current_money_format"]
|
||||
row_pos,
|
||||
6,
|
||||
currency_data.get("amount_due"),
|
||||
FORMATS["current_money_format"],
|
||||
)
|
||||
return row_pos
|
||||
|
||||
@@ -180,7 +202,7 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
)
|
||||
return row_pos
|
||||
|
||||
def _size_columns(self, sheet):
|
||||
def _size_columns(self, sheet, data):
|
||||
for i in range(7):
|
||||
sheet.set_column(0, i, 20)
|
||||
|
||||
@@ -203,7 +225,7 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
0,
|
||||
row_pos,
|
||||
6,
|
||||
_("Statement of Account from %s") % (company.display_name),
|
||||
_("Statement of Account from %s") % (company.display_name,),
|
||||
FORMATS["format_ws_title"],
|
||||
)
|
||||
row_pos += 1
|
||||
@@ -211,10 +233,10 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
sheet.write(
|
||||
row_pos,
|
||||
2,
|
||||
fields.Date.from_string(data.get("date_end")),
|
||||
data.get("data", {}).get(partners.ids[0], {}).get("today"),
|
||||
FORMATS["format_date_left"],
|
||||
)
|
||||
self._size_columns(sheet)
|
||||
self._size_columns(sheet, data)
|
||||
for partner in partners:
|
||||
invoice_address = data.get(
|
||||
"get_inv_addr", lambda x: self.env["res.partner"]
|
||||
@@ -286,6 +308,23 @@ class ActivityStatementXslx(models.AbstractModel):
|
||||
FORMATS["current_money_format"] = workbook.add_format(
|
||||
{"align": "right", "num_format": money_string}
|
||||
)
|
||||
bg_grey = "#CCCCCC"
|
||||
FORMATS["format_tcell_left_blocked"] = copy_format(
|
||||
workbook, FORMATS["format_tcell_left"]
|
||||
)
|
||||
FORMATS["format_tcell_left_blocked"].set_bg_color(bg_grey)
|
||||
FORMATS["format_tcell_date_left_blocked"] = copy_format(
|
||||
workbook, FORMATS["format_tcell_date_left"]
|
||||
)
|
||||
FORMATS["format_tcell_date_left_blocked"].set_bg_color(bg_grey)
|
||||
FORMATS["format_distributed_blocked"] = copy_format(
|
||||
workbook, FORMATS["format_distributed"]
|
||||
)
|
||||
FORMATS["format_distributed_blocked"].set_bg_color(bg_grey)
|
||||
FORMATS["current_money_format_blocked"] = copy_format(
|
||||
workbook, FORMATS["current_money_format"]
|
||||
)
|
||||
FORMATS["current_money_format_blocked"].set_bg_color(bg_grey)
|
||||
row_pos = self._write_currency_lines(
|
||||
row_pos, sheet, partner, currency, data
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user