From 8d8e054a225bd75f12c466baaaa2daed998d45ef Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Thu, 14 Jan 2021 11:55:24 +0100 Subject: [PATCH] [IMP] sale_timesheet: convert timesheet_product_id in related for task Before this commit, this field is stored and contains by default the value of the same field in project.project. Moreover, we cannot choose another timesheet_product_id in task views. It means that field is most of the time the timesheet_product_id of linked project. This commit converts this stored field into related field to the same field in project.project and remove an inherit view which adds only this field without displaying in the view. task-2424382 --- addons/sale_timesheet/models/project.py | 34 +------------------ .../tests/test_project_billing.py | 4 +-- .../views/project_task_views.xml | 11 ------ 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 3eb8a054974..d7bb125d332 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -186,16 +186,6 @@ class Project(models.Model): class ProjectTask(models.Model): _inherit = "project.task" - @api.model - def default_get(self, fields): - result = super(ProjectTask, self).default_get(fields) - - if not result.get('timesheet_product_id', False) and 'project_id' in result: - project = self.env['project.project'].browse(result['project_id']) - if project.pricing_type != 'employee_rate': - result['timesheet_product_id'] = project.timesheet_product_id.id - return result - # override sale_order_id and make it computed stored field instead of regular field. sale_order_id = fields.Many2one(compute='_compute_sale_order_id', store=True, readonly=False, domain="['|', '|', ('partner_id', '=', partner_id), ('partner_id', 'child_of', commercial_partner_id), ('partner_id', 'parent_of', partner_id)]") @@ -204,14 +194,7 @@ class ProjectTask(models.Model): is_project_map_empty = fields.Boolean("Is Project map empty", compute='_compute_is_project_map_empty') has_multi_sol = fields.Boolean(compute='_compute_has_multi_sol', compute_sudo=True) allow_billable = fields.Boolean(related="project_id.allow_billable") - timesheet_product_id = fields.Many2one( - 'product.product', string='Service', - domain="""[ - ('type', '=', 'service'), - ('invoice_policy', '=', 'delivery'), - ('service_type', '=', 'timesheet'), - '|', ('company_id', '=', False), ('company_id', '=', company_id)]""", - help='Select a Service product with which you would like to bill your time spent on this task.') + timesheet_product_id = fields.Many2one(related="project_id.timesheet_product_id") remaining_hours_so = fields.Float('Remaining Hours on SO', compute='_compute_remaining_hours_so') remaining_hours_available = fields.Boolean(related="sale_line_id.remaining_hours_available") @@ -298,21 +281,6 @@ class ProjectTask(models.Model): domain.append(('order_id', '=?', self.project_sale_order_id.id)) return self.env['sale.order.line'].search(domain, limit=1) - def action_make_billable(self): - return { - "name": _("Create Sales Order"), - "type": 'ir.actions.act_window', - "res_model": 'project.task.create.sale.order', - "views": [[False, "form"]], - "target": 'new', - "context": { - 'active_id': self.id, - 'active_model': 'project.task', - 'form_view_initial_mode': 'edit', - 'default_product_id': self.timesheet_product_id.id or self.project_id.timesheet_product_id.id, - }, - } - def _get_timesheet(self): # return not invoiced timesheet and timesheet without so_line or so_line linked to task timesheet_ids = super(ProjectTask, self)._get_timesheet() diff --git a/addons/sale_timesheet/tests/test_project_billing.py b/addons/sale_timesheet/tests/test_project_billing.py index d7689b76dc9..787f06654bb 100644 --- a/addons/sale_timesheet/tests/test_project_billing.py +++ b/addons/sale_timesheet/tests/test_project_billing.py @@ -119,7 +119,8 @@ class TestProjectBilling(TestCommonSaleTimesheet): Task = self.env['project.task'] # set a customer on the project self.project_non_billable.write({ - 'partner_id': self.partner_2.id + 'partner_id': self.partner_2.id, + 'timesheet_product_id': self.product_delivery_timesheet3, }) # create a task and 2 timesheets task = Task.with_context(default_project_id=self.project_non_billable.id).create({ @@ -147,7 +148,6 @@ class TestProjectBilling(TestCommonSaleTimesheet): 'allow_billable': True, 'pricing_type': 'fixed_rate', }) - task.timesheet_product_id = self.product_delivery_timesheet3 # create wizard wizard = self.env['project.create.sale.order'].with_context(active_id=self.project_non_billable.id, active_model='project.project').create({}) diff --git a/addons/sale_timesheet/views/project_task_views.xml b/addons/sale_timesheet/views/project_task_views.xml index 09618e2c685..1b3f205aebc 100644 --- a/addons/sale_timesheet/views/project_task_views.xml +++ b/addons/sale_timesheet/views/project_task_views.xml @@ -202,17 +202,6 @@ - - project.task.form.inherit.timesheet - project.task - - - - - - - - Overview project.project