From ec7b6c00f9949d938d14fe8d1d13916aac53af53 Mon Sep 17 00:00:00 2001 From: Rivo Lalaina Date: Tue, 19 Nov 2024 17:24:33 +0300 Subject: [PATCH] [IMP] [16.0] pre-commit : add black (#448) --- .pre-commit-config.yaml | 4 ++++ .../tests/test_default_task_stage.py | 1 - .../models/account_analytic_line.py | 1 + project_stage_allow_timesheet/models/project.py | 10 ++++++---- project_stage_allow_timesheet/models/project_stage.py | 2 +- project_stage_allow_timesheet/models/project_task.py | 6 +++--- .../models/project_task_type.py | 2 +- .../tests/test_project_task.py | 6 ++---- .../tests/test_config_parameter.py | 1 - .../tests/test_project_task.py | 1 - 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28b1b493..3cd01ba0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,10 @@ default_language_version: python: python3 node: "14.13.0" repos: + - repo: https://github.com/psf/black + rev: 22.8.0 + hooks: + - id: black - repo: https://github.com/PyCQA/flake8 rev: 3.8.3 hooks: diff --git a/project_default_task_stage/tests/test_default_task_stage.py b/project_default_task_stage/tests/test_default_task_stage.py index d05b9c05..4fc4a8f5 100644 --- a/project_default_task_stage/tests/test_default_task_stage.py +++ b/project_default_task_stage/tests/test_default_task_stage.py @@ -6,7 +6,6 @@ class TestDefaultTaskStage(SavepointCase): - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/project_stage_allow_timesheet/models/account_analytic_line.py b/project_stage_allow_timesheet/models/account_analytic_line.py index 47515dea..9fd6542f 100644 --- a/project_stage_allow_timesheet/models/account_analytic_line.py +++ b/project_stage_allow_timesheet/models/account_analytic_line.py @@ -12,6 +12,7 @@ class AccountAnalyticLine(models.Model): def _should_apply_constraints(self, env): def _is_testing(): return getattr(threading.current_thread(), "testing", False) + return not _is_testing() or env.context.get( "enable_project_stage_allow_timesheet_constraint" ) diff --git a/project_stage_allow_timesheet/models/project.py b/project_stage_allow_timesheet/models/project.py index b898f0b7..fb40c0e2 100644 --- a/project_stage_allow_timesheet/models/project.py +++ b/project_stage_allow_timesheet/models/project.py @@ -6,14 +6,16 @@ class Project(models.Model): - _inherit = 'project.project' + _inherit = "project.project" - @api.depends('stage_id', 'stage_id.allow_timesheet') + @api.depends("stage_id", "stage_id.allow_timesheet") def _compute_allow_timesheet(self): for record in self: record.allow_timesheets = record.stage_id.allow_timesheet allow_timesheets = fields.Boolean( - readonly=True, compute="_compute_allow_timesheet", store=True, - help="Depends if the project stage allows timesheet." + readonly=True, + compute="_compute_allow_timesheet", + store=True, + help="Depends if the project stage allows timesheet.", ) diff --git a/project_stage_allow_timesheet/models/project_stage.py b/project_stage_allow_timesheet/models/project_stage.py index f60124af..2a1f8721 100644 --- a/project_stage_allow_timesheet/models/project_stage.py +++ b/project_stage_allow_timesheet/models/project_stage.py @@ -5,7 +5,7 @@ class ProjectStage(models.Model): - _inherit = 'project.project.stage' + _inherit = "project.project.stage" allow_timesheet = fields.Boolean( default=True, diff --git a/project_stage_allow_timesheet/models/project_task.py b/project_stage_allow_timesheet/models/project_task.py index 9afc63a9..64ac319b 100644 --- a/project_stage_allow_timesheet/models/project_task.py +++ b/project_stage_allow_timesheet/models/project_task.py @@ -1,4 +1,3 @@ - # Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). @@ -13,14 +12,15 @@ class ProjectTask(models.Model): def _should_apply_constraints(self, env): def _is_testing(): return getattr(threading.current_thread(), "testing", False) + return not _is_testing() or env.context.get( "enable_project_stage_allow_timesheet_constraint" ) @api.constrains("project_id") def _check_project_move_allow_timesheet(self): - """ Check if a line is moved to another project, - the target project must allow time sheet """ + """Check if a line is moved to another project, + the target project must allow time sheet""" if not self._should_apply_constraints(self.env): return diff --git a/project_stage_allow_timesheet/models/project_task_type.py b/project_stage_allow_timesheet/models/project_task_type.py index 984249d5..10ad85d8 100644 --- a/project_stage_allow_timesheet/models/project_task_type.py +++ b/project_stage_allow_timesheet/models/project_task_type.py @@ -6,7 +6,7 @@ class ProjectTaskType(models.Model): - _inherit = 'project.task.type' + _inherit = "project.task.type" allow_timesheet = fields.Boolean( string="Allow timesheets", diff --git a/project_stage_allow_timesheet/tests/test_project_task.py b/project_stage_allow_timesheet/tests/test_project_task.py index d1670f7c..a32c3b08 100644 --- a/project_stage_allow_timesheet/tests/test_project_task.py +++ b/project_stage_allow_timesheet/tests/test_project_task.py @@ -12,9 +12,7 @@ def setUpClass(cls): context = dict( cls.env.context, enable_project_stage_allow_timesheet_constraint=True ) - cls.employee = cls.env["hr.employee"].create( - {"name": "Employee"} - ) + cls.employee = cls.env["hr.employee"].create({"name": "Employee"}) cls.env = cls.env(context=context) cls.project_stage_timesheet = cls.env["project.project.stage"].create( {"name": "project_stage", "allow_timesheet": True} @@ -42,7 +40,7 @@ def setUpClass(cls): "name": "line", "task_id": cls.task_timesheet.id, "project_id": cls.project_timesheet.id, - "employee_id": cls.employee.id + "employee_id": cls.employee.id, } ) diff --git a/project_task_full_text_search/tests/test_config_parameter.py b/project_task_full_text_search/tests/test_config_parameter.py index 7f27bd24..18663ecd 100644 --- a/project_task_full_text_search/tests/test_config_parameter.py +++ b/project_task_full_text_search/tests/test_config_parameter.py @@ -7,7 +7,6 @@ class TestFullTextSearchParamKey(common.SavepointCase): - @classmethod def setUpClass(cls): super().setUpClass() diff --git a/project_task_full_text_search/tests/test_project_task.py b/project_task_full_text_search/tests/test_project_task.py index cac0e64b..735798d7 100644 --- a/project_task_full_text_search/tests/test_project_task.py +++ b/project_task_full_text_search/tests/test_project_task.py @@ -5,7 +5,6 @@ class TestTaskFullTextSearch(common.SavepointCase): - @classmethod def setUpClass(cls): super().setUpClass()