From ecfd5871467ea05e5cc4a2b7059cfed1667b7934 Mon Sep 17 00:00:00 2001 From: dsolanki Date: Thu, 11 Mar 2021 17:19:27 +0530 Subject: [PATCH] [MIG] Migrate module sale_timesheet_task_exclude to v14. --- sale_timesheet_task_exclude/README.rst | 2 ++ .../models/project_task.py | 25 +++++++++++++++---- .../readme/CONTRIBUTORS.rst | 2 ++ sale_timesheet_task_exclude/readme/USAGE.rst | 2 +- .../tests/test_sale_timesheet_exclude_task.py | 11 +++----- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/sale_timesheet_task_exclude/README.rst b/sale_timesheet_task_exclude/README.rst index 121b73f0f8..54c1fd6a9e 100644 --- a/sale_timesheet_task_exclude/README.rst +++ b/sale_timesheet_task_exclude/README.rst @@ -83,6 +83,8 @@ Contributors * Fernando La Chica +* Dhara Solanki + Maintainers ~~~~~~~~~~~ diff --git a/sale_timesheet_task_exclude/models/project_task.py b/sale_timesheet_task_exclude/models/project_task.py index 7aec51b47b..e0ed0f4493 100644 --- a/sale_timesheet_task_exclude/models/project_task.py +++ b/sale_timesheet_task_exclude/models/project_task.py @@ -15,11 +15,26 @@ class ProjectTask(models.Model): ), ) - @api.depends("exclude_from_sale_order") - def _compute_billable_type(self): - super()._compute_billable_type() - for task in self.filtered("exclude_from_sale_order"): - task.billable_type = "no" + @api.depends( + "sale_line_id", + "project_id", + "allow_billable", + "non_allow_billable", + "exclude_from_sale_order", + ) + def _compute_sale_order_id(self): + for task in self: + if task.exclude_from_sale_order: + task.sale_order_id = False + elif not task.allow_billable or task.non_allow_billable: + task.sale_order_id = False + elif task.allow_billable: + if task.sale_line_id: + task.sale_order_id = task.sale_line_id.sudo().order_id + elif task.project_id.sale_order_id: + task.sale_order_id = task.project_id.sale_order_id + if task.sale_order_id and not task.partner_id: + task.partner_id = task.sale_order_id.partner_id def write(self, vals): res = super().write(vals) diff --git a/sale_timesheet_task_exclude/readme/CONTRIBUTORS.rst b/sale_timesheet_task_exclude/readme/CONTRIBUTORS.rst index 97f7b9309c..7eddb1a50b 100644 --- a/sale_timesheet_task_exclude/readme/CONTRIBUTORS.rst +++ b/sale_timesheet_task_exclude/readme/CONTRIBUTORS.rst @@ -5,3 +5,5 @@ * `Guadaltech Soluciones Tecnológicas, S.L. `_: * Fernando La Chica + +* Dhara Solanki diff --git a/sale_timesheet_task_exclude/readme/USAGE.rst b/sale_timesheet_task_exclude/readme/USAGE.rst index 15e4f73376..8d931df3f6 100644 --- a/sale_timesheet_task_exclude/readme/USAGE.rst +++ b/sale_timesheet_task_exclude/readme/USAGE.rst @@ -1,4 +1,4 @@ -# Go to *Project > All Tasks* +# Go to *Project > Tasks* # Open specific task for editing # Check *Exclude From Billing* diff --git a/sale_timesheet_task_exclude/tests/test_sale_timesheet_exclude_task.py b/sale_timesheet_task_exclude/tests/test_sale_timesheet_exclude_task.py index 37442cca7b..4e0b37a256 100644 --- a/sale_timesheet_task_exclude/tests/test_sale_timesheet_exclude_task.py +++ b/sale_timesheet_task_exclude/tests/test_sale_timesheet_exclude_task.py @@ -42,7 +42,7 @@ def test_exclude_from_sale_order(self): } ) project = self.SudoProject.create( - {"name": "Project #1", "allow_timesheets": True} + {"name": "Project #1", "allow_timesheets": True, "allow_billable": True} ) product = self.SudoProductProduct.create( { @@ -116,16 +116,13 @@ def test_exclude_from_sale_order(self): "employee_id": employee.id, } ) - self.assertTrue(timesheet.so_line) - self.assertEqual(task.billable_type, "task_rate") + self.assertTrue(task.sale_order_id) task.exclude_from_sale_order = True - self.assertEqual(task.billable_type, "no") - self.assertFalse(timesheet.so_line) + self.assertFalse(task.sale_order_id) task.exclude_from_sale_order = False - self.assertEqual(task.billable_type, "task_rate") - self.assertTrue(timesheet.so_line) + self.assertTrue(task.sale_order_id) payment = ( self.env["sale.advance.payment.inv"]