From 5aefa7cfb897963fb04af3a1c0432aec484ff6e9 Mon Sep 17 00:00:00 2001 From: majouda Date: Fri, 5 Apr 2024 17:34:20 -0400 Subject: [PATCH] fix --- .docker_files/main/__manifest__.py | 2 +- Dockerfile | 2 +- .../models/account_analytic_line.py | 62 +------------------ project_wip_timesheet/models/project_type.py | 1 + .../tests/test_wip_journal_entries.py | 10 +-- 5 files changed, 9 insertions(+), 68 deletions(-) diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index c1574227..b5769d6f 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -93,7 +93,7 @@ "project_wip_material", # "project_wip_outsourcing", # "project_wip_supply_cost", - # "project_wip_timesheet", + "project_wip_timesheet", "timesheet_task_project_no_change", ], "installable": True, diff --git a/Dockerfile b/Dockerfile index a5d81811..ac4e5460 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,7 +92,7 @@ COPY project_wip /mnt/extra-addons/project_wip COPY project_wip_material /mnt/extra-addons/project_wip_material #COPY project_wip_outsourcing /mnt/extra-addons/project_wip_outsourcing #COPY project_wip_supply_cost /mnt/extra-addons/project_wip_supply_cost -#COPY project_wip_timesheet /mnt/extra-addons/project_wip_timesheet +COPY project_wip_timesheet /mnt/extra-addons/project_wip_timesheet COPY stock_location_production /mnt/extra-addons/stock_location_production COPY timesheet_task_project_no_change /mnt/extra-addons/timesheet_task_project_no_change diff --git a/project_wip_timesheet/models/account_analytic_line.py b/project_wip_timesheet/models/account_analytic_line.py index 1dc4935b..596e90f4 100644 --- a/project_wip_timesheet/models/account_analytic_line.py +++ b/project_wip_timesheet/models/account_analytic_line.py @@ -92,8 +92,7 @@ def _update_salary_account_move(self): ) ) - self.salary_account_move_id.button_draft() - self.salary_account_move_id.name = "" + self.salary_account_move_id.state = "draft" vals = self._get_salary_account_move_vals() self.salary_account_move_id.write(vals) self.salary_account_move_id.post() @@ -112,16 +111,7 @@ def _reverse_salary_account_move_for_updated_timesheet(self): move_name=self.salary_account_move_id.name, ) ) - reversed_move = self.salary_account_move_id._reverse_moves() - reversed_move.action_post() - - # get the reversed move line and reconcile it with the salary move line - reversed_move_line, move_line = self._get_line_reconciliation_data( - self.salary_account_move_id, reversed_move - ) - - # reconcile the move lines - self._reconcile_move_lines(move_line, reversed_move_line) + self.salary_account_move_id._reverse_moves() self.salary_account_move_id = False @@ -138,53 +128,7 @@ def _reverse_salary_account_move_for_deleted_timesheet(self): move_name=self.salary_account_move_id.name, ) ) - # reverse the move and post it to allow the reconciliation of the move lines - reversed_move = self.salary_account_move_id._reverse_moves() - reversed_move.action_post() - - # get the reversed move line and reconcile it with the salary move line - reversed_move_line, move_line = self._get_line_reconciliation_data( - self.salary_account_move_id, reversed_move - ) - - # reconcile the move lines - self._reconcile_move_lines(move_line, reversed_move_line) - - def _get_line_reconciliation_data(self, move, reversed_move): - """Get the reconciled move line and the original move line. - In case, we changed project in timesheet, and project has no type to select wip - account, we identify the account move line by task_id linked, that only on wip - account. - - :rtype: tuple - """ - move_line = move.line_ids.filtered( - lambda line: (line.account_id == self._get_wip_account()) or line.task_id - ) - reversed_move_line = reversed_move.line_ids.filtered( - lambda line: (line.account_id == self._get_wip_account()) or line.task_id - ) - return reversed_move_line, move_line - - def _reconcile_move_lines(self, move_line, reversal_line): - """Reconcile the move lines.""" - data = [ - { - "id": None, - "mv_line_ids": [move_line.id, reversal_line.id], - "new_mv_line_dicts": [], - "type": None, - } - ] - self.env["account.reconciliation.widget"].process_move_lines(data) - - if move_line.matching_number == "P": - raise ValidationError( - _( - "The entry {move_line} ({amount}) could not be reconciled." - "You should verify if the Salary entry is partially reconciled." - ).format(wip_line=move_line.display_name, amount=move_line.balance) - ) + self.salary_account_move_id._reverse_moves() def _is_salary_account_move_reconciled(self): return any(line.reconciled for line in self.salary_account_move_id.line_ids) diff --git a/project_wip_timesheet/models/project_type.py b/project_wip_timesheet/models/project_type.py index a71cbb7d..3c1821e8 100644 --- a/project_wip_timesheet/models/project_type.py +++ b/project_wip_timesheet/models/project_type.py @@ -28,6 +28,7 @@ class ProjectType(models.Model): @api.constrains("salary_account_id", "salary_journal_id", "wip_account_id") def _check_required_fields_for_salary_entries(self): + self = self.with_context(force_company=self.env.user.company_id.id) project_types_with_salary_account = self.filtered(lambda t: t.salary_account_id) for project_type in project_types_with_salary_account: if not project_type.wip_account_id: diff --git a/project_wip_timesheet/tests/test_wip_journal_entries.py b/project_wip_timesheet/tests/test_wip_journal_entries.py index df34239f..99594588 100644 --- a/project_wip_timesheet/tests/test_wip_journal_entries.py +++ b/project_wip_timesheet/tests/test_wip_journal_entries.py @@ -61,7 +61,7 @@ def setUpClass(cls): { "name": "Work in Progress", "code": "WIP", - # "update_posted": True, + "restrict_mode_hash_table": True, "type": "general", "company_id": cls.company.id, } @@ -99,10 +99,6 @@ def setUpClass(cls): cls.env = cls.env(user=cls.manager, context={"force_company": cls.company.id}) - cls.env["project.project"].create( - {"name": "Job 123", "company_id": cls.company.id} - ) - cls.project_type = cls.env["project.type"].create( { "name": "Trailer Refurb", @@ -181,12 +177,12 @@ def test_account_move_has_no_analytic_lines(self): def _get_wip_move_line(self, timesheet_line): return timesheet_line.salary_account_move_id.line_ids.filtered( - lambda l: l.account_id == self.wip_account + lambda line: line.account_id == self.wip_account ) def _get_salary_move_line(self, timesheet_line): return timesheet_line.salary_account_move_id.line_ids.filtered( - lambda l: l.account_id == self.salary_account + lambda line: line.account_id == self.salary_account ) def test_wip_move_line_analytic_account_is_project(self):