Skip to content

Commit

Permalink
[UPD] unit test coverage, remove create(), write() in project.task
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsirintanis committed Jan 16, 2024
1 parent b79cfcd commit 2ae9ed9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
12 changes: 7 additions & 5 deletions project_forecast_line/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ def _compute_main_role_id(self):
# can"t store as it depends on current date
today = fields.Date.context_today(self)
for rec in self:
rec.main_role_id = rec.role_ids.filtered(
lambda r: r.date_start <= today and (r.date_end >= today)
if r.date_end
else True
)[:1].role_id
rec.main_role_id = fields.first(
rec.role_ids.filtered(
lambda r: r.date_start <= today and (r.date_end >= today)
if r.date_end
else True
)
).role_id

def write(self, values):
values = self._check_job_role(values)
Expand Down
20 changes: 0 additions & 20 deletions project_forecast_line/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ class ProjectTask(models.Model):
help="Technical field used to trigger the forecast recomputation",
)

@api.model_create_multi
def create(self, vals_list):
# compatibility with fields from project_enterprise
for vals in vals_list:
if vals.get("planned_date_begin"):
vals["forecast_date_planned_start"] = vals["planned_date_begin"]
if vals.get("planned_date_end"):
vals["forecast_date_planned_end"] = vals["planned_date_end"]
tasks = super().create(vals_list)
# tasks._update_forecast_lines()
return tasks

def _update_forecast_lines_trigger_fields(self):
return [
# "sale_order_line_id",
Expand All @@ -53,14 +41,6 @@ def _compute_forecast_recomputation_trigger(self):
for rec in self:
rec.forecast_recomputation_trigger = value

def write(self, values):
# compatibility with fields from project_enterprise
if "planned_date_begin" in values:
values["forecast_date_planned_start"] = values["planned_date_begin"]
if "planned_date_end" in values:
values["forecast_date_planned_end"] = values["planned_date_end"]
return super().write(values)

def _write(self, values):
res = super()._write(values)
if self.env.context.get("project_forecast_line_task_noloop"):
Expand Down
30 changes: 30 additions & 0 deletions project_forecast_line/tests/test_forecast_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,11 @@ def test_draft_sale_order_creates_negative_forecast_forecast(self):
self.assertEqual(forecast_lines.cost, -10 * 8 * 75)
self.assertEqual(forecast_lines.date_from, date(2022, 2, 1))
self.assertEqual(forecast_lines.date_to, date(2022, 2, 28))
so.action_cancel()

@freeze_time("2022-01-01")
def test_sale_line_unlink(self):
project = self.env["project.project"].create({"name": "TestProjectReschedule"})
so = self._create_sale("2022-02-07", "2022-02-20")
line = so.order_line[0]
forecast_lines = self.env["forecast.line"].search(
Expand All @@ -311,6 +313,10 @@ def test_sale_line_unlink(self):
("res_model", "=", "sale.order.line"),
]
)
# Check that project is automatically
# assigned to forecast lines too
so.write({"project_id": project.id})
self.assertEqual(project, forecast_lines.mapped("project_id"))
line.unlink()
self.assertFalse(forecast_lines.exists())

Expand Down Expand Up @@ -536,6 +542,30 @@ def setUpClass(cls):
# tests, outside of the context manager.
cls.task.flush()

def test_onchange_user_id(self):
"""Test onchange_user_id method"""
task = self.task
# Set role to false, to set it again
task.forecast_role_id = False
self.assertFalse(task.forecast_role_id)
# set user to False, and try again
task.user_id = False
task.onchange_user_id()
self.assertFalse(task.forecast_role_id)
# this is still false, as current user
# does not have a main_role_id
self.assertFalse(task.forecast_role_id)
# set user to False, and try again
task.user_id = False
task.onchange_user_id()
self.assertFalse(task.forecast_role_id)
# Assign user with an active role_id
task.user_id = self.user_consultant
task.onchange_user_id()
self.assertEqual(
task.forecast_role_id, self.user_consultant.employee_id.main_role_id
)

@freeze_time("2022-02-01 12:00:00")
def test_task_unlink(self):
task_forecast = self.env["forecast.line"].search(
Expand Down

0 comments on commit 2ae9ed9

Please sign in to comment.