bemade-addons/bemade_fsm/tests/test_task_report.py

63 lines
2.1 KiB
Python
Raw Normal View History

from .test_bemade_fsm_common import BemadeFSMBaseTest
from odoo.tests import Form
class TestTaskReport(BemadeFSMBaseTest):
def test_split_time_materials_setting(self):
with Form(self.env["res.config.settings"]) as settings:
settings.separate_time_on_work_orders = True
with Form(self.env["res.config.settings"]):
self.assertTrue(settings.separate_time_on_work_orders)
so = self._generate_sale_order()
service_product = self._generate_product()
material_product = self._generate_product(
name="Material Product",
product_type="consu",
service_tracking="no",
)
visit = self._generate_visit(sale_order=so)
self._generate_sale_order_line(sale_order=so, product=service_product)
self._generate_sale_order_line(sale_order=so, product=material_product)
so.action_confirm()
task = visit.task_id
# Add timesheet entry to make the report renderable
self.env["account.analytic.line"].create(
{
"name": "Test timesheet entry",
"task_id": task.id,
"project_id": task.project_id.id,
"unit_amount": 2.0,
"employee_id": self.env["hr.employee"]
.create(
{
"name": "Test Employee",
"user_id": self.env.user.id,
}
)
.id,
}
)
html_content = (
self.env["ir.actions.report"]
._render(
"industry_fsm.worksheet_custom", [task.id]
)[ # pyright: ignore[reportOptionalSubscript]
0
]
.decode("utf-8")
.split("\n")
)
strings_to_find = ["<h2>Materials</h2>", "<span>Material Product</span>"]
for line in strings_to_find:
line_found = False
for html_line in html_content:
if line in html_line:
line_found = True
self.assertTrue(line_found, f"{line} should be in file.")