Skip to content

Commit

Permalink
TA#67305 [16.0] [ADD] TU
Browse files Browse the repository at this point in the history
  • Loading branch information
rivo2302 committed Oct 25, 2024
1 parent e4c6bdf commit d0635c3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 31 deletions.
17 changes: 9 additions & 8 deletions report_aeroo/extra_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def format_datetime(report, value: datetime, datetime_format: str):
format_datetime = babel.dates.format_datetime(
datetime_in_timezone, datetime_format, locale=lang
)
format_datetime = format_datetime.replace("a.m.", "AM").replace(
"p.m.", "PM")
format_datetime = format_datetime.replace("a.m.", "AM").replace("p.m.", "PM")
return format_datetime


Expand All @@ -133,10 +132,12 @@ def format_datetime_now(report, datetime_format: str = None, delta: timedelta =

if delta is not None:
timestamp += delta
formatted_datetime_now = format_datetime(report, value=timestamp,
datetime_format=datetime_format)
formatted_datetime_now = formatted_datetime_now.replace("a.m.", "AM"
).replace("p.m.", "PM")
formatted_datetime_now = format_datetime(
report, value=timestamp, datetime_format=datetime_format
)
formatted_datetime_now = formatted_datetime_now.replace("a.m.", "AM").replace(
"p.m.", "PM"
)

return formatted_datetime_now

Expand All @@ -151,7 +152,7 @@ def format_decimal(report, amount: float, amount_format="#,##0.00"):
"""
lang = report._context.get("lang") or "en_US"
res = babel.numbers.format_decimal(amount, format=amount_format, locale=lang)
res = res.replace('\u202f', '\xa0')
res = res.replace("\u202f", "\xa0")
return res


Expand Down Expand Up @@ -194,7 +195,7 @@ def format_currency(
res = babel.numbers.format_currency(
amount, currency.name, format=amount_format, locale=locale
)
res = res.replace('\u202f', '\xa0')
res = res.replace("\u202f", "\xa0")
return res


Expand Down
15 changes: 10 additions & 5 deletions report_aeroo/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from ..namespace import AerooNamespace
from ..extra_functions import aeroo_function_registry

_logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -338,8 +339,7 @@ def _render_aeroo(self, doc_ids, data=None, force_output_format=None):
"""
output_format = force_output_format or self.aeroo_out_format_id.code

if data is None:
data = {}
data = data or {}

if len(doc_ids) > 1:
return self._render_aeroo_multi(doc_ids, data, output_format)
Expand Down Expand Up @@ -467,7 +467,7 @@ def _find_aeroo_report_attachment(self, record, output_format):
limit=1,
)
if attachment:
return base64.decodestring(attachment.datas)
return base64.decodebytes(attachment.datas)
return None

def _create_aeroo_attachment(self, record, file_data, output_format):
Expand All @@ -481,7 +481,7 @@ def _create_aeroo_attachment(self, record, file_data, output_format):
return self.env["ir.attachment"].create(
{
"name": filename,
"datas": base64.encodestring(file_data),
"datas": base64.encodebytes(file_data),
"res_model": record._name,
"res_id": record.id,
}
Expand Down Expand Up @@ -631,12 +631,17 @@ class AerooReportsGeneratedFromListViews(models.Model):
_inherit = "ir.actions.report"

def _render_aeroo(self, doc_ids, data=None, force_output_format=None):
data = data or {}
if self.multi:
return self._render_aeroo_from_list_of_records(
doc_ids, data, force_output_format
)
else:
return super()._render_aeroo(doc_ids, data, force_output_format)
return super()._render_aeroo(
doc_ids=doc_ids,
data=data,
force_output_format=force_output_format,
)

def _render_aeroo_from_list_of_records(
self, doc_ids, data=None, force_output_format=None
Expand Down
18 changes: 8 additions & 10 deletions report_aeroo/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
# Copyright 2018 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
test_email_template,
test_extra_functions,
test_load_views,
test_report_aeroo,
test_report_aeroo_access,
test_report_aeroo_company_eval,
test_report_aeroo_lang_eval,
test_report_aeroo_multi
)
from . import test_email_template
from . import test_extra_functions
from . import test_load_views
from . import test_report_aeroo
from . import test_report_aeroo_access
from . import test_report_aeroo_company_eval
from . import test_report_aeroo_lang_eval
from . import test_report_aeroo_multi
13 changes: 9 additions & 4 deletions report_aeroo/tests/test_load_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

class TestLoadViews(TransactionCase):
def test_aeroo_template_data_not_in_result(self):
self.env.ref("report_aeroo.aeroo_sample_report").create_action()
result = self.env["res.partner"].get_views([(None, "tree")], {"toolbar": True})
actions = result["fields_views"]["tree"]["toolbar"]["print"]
assert "aeroo_template_data" not in actions[0]
simple_report = self.env.ref("report_aeroo.aeroo_sample_report")
simple_report.create_action()
view = self.env.ref("base.view_partner_tree")
result = self.env["res.partner"].get_views(
[(view.id, "list")], {"toolbar": True}
)
action_reports = result["views"]["list"]["toolbar"]["print"]
report_ids = [report["id"] for report in action_reports]
assert simple_report.id in report_ids
2 changes: 1 addition & 1 deletion report_aeroo/tests/test_report_aeroo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _render_report(self, partners):
:param partners: a res.partner recordset
"""
self.report.sudo(self.user.id)._render(partners.ids, {})
self.report._render_aeroo(partners.ids, {})

def _create_report_line(self, lang, company=None):
self.report.write(
Expand Down
4 changes: 2 additions & 2 deletions report_aeroo/tests/test_report_aeroo_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def setUpClass(cls):
cls.user.groups_id |= cls.env.ref("report_aeroo.group_aeroo_manager")

def test_report_create(self):
assert self.report.sudo(self.user).copy({})
assert self.report.with_user(self.user.id).copy({})

def test_report_unlink(self):
self.report.sudo(self.user).unlink()
self.report.with_user(self.user.id).unlink()
assert not self.report.exists()
2 changes: 1 addition & 1 deletion report_aeroo/tests/test_report_aeroo_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _render_report(self, partners):
:param partners: a res.partner recordset
"""
self.report.sudo(self.env.ref("base.user_demo").id)._render(partners.ids, {})
self.report.with_user(self.env.ref("base.user_demo").id)._render_aeroo(partners.ids, {})

def test_generate_report_with_pdf_format_and_multiple_records(self):
self.report.aeroo_out_format_id = self.env.ref(
Expand Down

0 comments on commit d0635c3

Please sign in to comment.