From 7e09f931ff08bc5acbd8846f5ec367e65f2f2e62 Mon Sep 17 00:00:00 2001 From: laa Date: Tue, 21 Jan 2020 16:27:23 +0000 Subject: [PATCH] [IMP] hr_timesheet,industry_fsm: Display CTA buttons with computed fields Purpose ======= The various buttons in FSM are currently displayed based on a set of attributes. As there are many different configurations possible for projects, it makes a lot of conditions (= the code is a living nightmare). This task aims at replacing these attributes by computed fields in order to gain clarity and to avoid the various bugs we recently faced + add python tests to ensure their robustness. Specification ============= START/STOP/PAUSE/RESUME ----------------------- - should not be visible if the task is marked as done - should be visible in non-primary if Time > 0 - should be visible in primary if Time = 0 - when the timer is running, do not display the following buttons: Create Sales Order, Mark as done, Create Invoice, Sign report, Send report - only visible if the 'Timesheet Timer' feature is enabled on the project SIGN REPORT ----------- - should not be visible - if Time = 0 AND Worksheet = 0 AND Products = 0 - OR if the report already is signed - should be visible in non primary if Time > 0 OR Worksheet > 0 OR Products > 0 - should be visible in primary if Time > 0 AND Worksheet > 0 AND Products > 0 - once the report is signed, display an 'fa-globe Customer Preview' stat button redirecting to the webpage with the report - only visible if the 'worksheets' feature is enabled on the project SEND REPORT ----------- - should not be visible if Time = 0 AND Worksheet = 0 AND Products = 0 - should be visible in non primary if Time > 0 OR Worksheet > 0 OR Products > 0 OR if the report was already sent - should be visible in primary if - Time > 0 AND Worksheet > 0 AND Products > 0 - AND the report is signed - only visible if the 'worksheets' feature is enabled on the project MARK AS DONE ------------ - should not be visible if the task is marked as done - should be visible in non primary if - Time > 0 OR Worksheet > 0 OR Products > 0 - OR if Time = 0 OR Worksheet = 0 OR Products = 0 - should be visible in primary if Time > 0 AND Worksheet > 0 AND Products > 0 - only visible if is_fsm is true on the project CREATE INVOICE -------------- - should not be visible if the task is not marked as done OR if the SO linked to the task has the 'Fully invoiced' invoice status - should be visible in non primary if the SO linked to the task has the 'Nothing to invoice' invoice status - should be visible in primary if the SO linked to the task has one of the following invoice status: To Invoice, Upselling - only visible if the Bill from tasks feature is enabled on the project EXTRA QUOTATION + CREATE SALES ORDER ------------------------------------ no change of behavior closes odoo/odoo#42508 Taskid: 2126857 Related: odoo/enterprise#6918 Signed-off-by: Yannick Tivisse (yti) Co-authored-by: Yannick Tivisse --- addons/hr_timesheet/models/project.py | 32 +++++++++++++++++++ addons/hr_timesheet/views/project_views.xml | 15 ++++++--- addons/sale_timesheet/models/project.py | 22 +++++++++++++ .../views/project_task_views.xml | 6 ++-- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index d33d9c45722..329c242e0d3 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -98,6 +98,38 @@ class Task(models.Model): timesheet_timer_first_start = fields.Datetime("Timesheet Timer First Use", readonly=True) timesheet_timer_last_stop = fields.Datetime("Timesheet Timer Last Use", readonly=True) display_timesheet_timer = fields.Boolean("Display Timesheet Time", compute='_compute_display_timesheet_timer') + display_timer_start_primary = fields.Boolean(compute='_compute_display_timer_buttons') + display_timer_start_secondary = fields.Boolean(compute='_compute_display_timer_buttons') + display_timer_stop = fields.Boolean(compute='_compute_display_timer_buttons') + display_timer_pause = fields.Boolean(compute='_compute_display_timer_buttons') + display_timer_resume = fields.Boolean(compute='_compute_display_timer_buttons') + + @api.depends('display_timesheet_timer', 'timer_start', 'timer_pause', 'total_hours_spent') + def _compute_display_timer_buttons(self): + for task in self: + start_p, start_s, stop, pause, resume = True, True, True, True, True + if not task.display_timesheet_timer: + start_p, start_s, stop, pause, resume = False, False, False, False, False + else: + if task.timer_start: + start_p, start_s = False, False + if task.timer_pause: + pause = False + else: + resume = False + else: + stop, pause, resume = False, False, False + if not task.total_hours_spent: + start_s = False + else: + start_p = False + task.write({ + 'display_timer_start_primary': start_p, + 'display_timer_start_secondary': start_s, + 'display_timer_stop': stop, + 'display_timer_pause': pause, + 'display_timer_resume': resume, + }) @api.depends('timesheet_ids.unit_amount') def _compute_effective_hours(self): diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index 3df4ad3b4b0..a50c6dfb58b 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -261,16 +261,21 @@ + + + + +