From 828d5157a52b6cbffee3cc142b6808a9f7ea939c Mon Sep 17 00:00:00 2001 From: "Cedric Prieels (cpr)" Date: Tue, 7 Sep 2021 13:47:32 +0000 Subject: [PATCH] [FIX] project{,_mrp}: fix project update stat buttons We are copying 3 stats buttons from the project view form (manufacturing orders, work orders and bills of materials) and we add them to the project update page. See task-2638359 closes odoo/odoo#76421 X-original-commit: 4572e710a5e755c0c75c95a6d033e44f0a2799f8 Related: odoo/enterprise#20811 Signed-off-by: LTU-Odoo --- .../account_sale_timesheet/models/project.py | 19 +++-- addons/hr_timesheet/models/project.py | 19 +++-- addons/project/models/project.py | 85 ++++++++++--------- addons/project_hr_expense/models/project.py | 19 +++-- addons/project_mrp/models/project.py | 53 +++++++++++- addons/project_mrp/views/project_views.xml | 9 +- addons/project_purchase/models/project.py | 19 +++-- addons/sale_project/models/project.py | 17 ++-- addons/sale_project_account/models/project.py | 19 +++-- addons/sale_timesheet/models/project.py | 27 +++--- 10 files changed, 172 insertions(+), 114 deletions(-) diff --git a/addons/account_sale_timesheet/models/project.py b/addons/account_sale_timesheet/models/project.py index d8086b57a4c..c07110e7f63 100644 --- a/addons/account_sale_timesheet/models/project.py +++ b/addons/account_sale_timesheet/models/project.py @@ -14,13 +14,14 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'pencil-square-o', - 'text': _('Invoices'), - 'number': self.invoice_count, - 'action_type': 'object', - 'action': 'action_open_project_invoices', - 'show': self.user_has_groups('account.group_account_readonly') and bool(self.analytic_account_id) and self.invoice_count > 0, - 'sequence': 11, - }) + if self.user_has_groups('account.group_account_readonly'): + buttons.append({ + 'icon': 'pencil-square-o', + 'text': _('Invoices'), + 'number': self.invoice_count, + 'action_type': 'object', + 'action': 'action_open_project_invoices', + 'show': bool(self.analytic_account_id) and self.invoice_count > 0, + 'sequence': 11, + }) return buttons diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 9c334067746..a79273a59bf 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -204,15 +204,16 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'clock-o', - 'text': _('Recorded'), - 'number': '%s %s' % (self.total_timesheet_time, self.env.company.timesheet_encode_uom_id.name), - 'action_type': 'object', - 'action': 'action_show_timesheets_by_employee_invoice_type', - 'show': self.user_has_groups('hr_timesheet.group_hr_timesheet_user') and self.allow_timesheets, - 'sequence': 4, - }) + if self.user_has_groups('hr_timesheet.group_hr_timesheet_user'): + buttons.append({ + 'icon': 'clock-o', + 'text': _('Recorded'), + 'number': '%s %s' % (self.total_timesheet_time, self.env.company.timesheet_encode_uom_id.name), + 'action_type': 'object', + 'action': 'action_show_timesheets_by_employee_invoice_type', + 'show': self.allow_timesheets, + 'sequence': 4, + }) return buttons diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 43f320c10e5..4223b57fc9b 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -717,48 +717,51 @@ class Project(models.Model): }), 'show': True, 'sequence': 2, - }, - { - 'icon': 'smile-o', - 'text': _('Customer Satisfaction'), - 'number': '%s %%' % (self.rating_percentage_satisfaction), - 'action_type': 'object', - 'action': 'action_view_all_rating', - 'show': self.user_has_groups('project.group_project_rating') and self.rating_active and self.rating_percentage_satisfaction > -1, - 'sequence': 5, - }, - { - 'icon': 'area-chart', - 'text': _('Burndown Chart'), - 'action_type': 'action', - 'action': 'project.action_project_task_burndown_chart_report', - 'additional_context': json.dumps({ - 'active_id': self.id, - }), - 'show': self.user_has_groups('project.group_project_manager'), - 'sequence': 7, - }, - { - 'icon': 'usd', - 'text': _('Gross Margin'), - 'number': format_amount(self.env, self.analytic_account_balance, self.company_id.currency_id), - 'action_type': 'object', - 'action': 'action_view_analytic_account_entries', - 'show': self.user_has_groups('analytic.group_analytic_accounting'), - 'sequence': 18, - }, - { - 'icon': 'users', - 'text': _('Collaborators'), - 'number': self.collaborator_count, - 'action_type': 'action', - 'action': 'project.project_collaborator_action', - 'additional_context': json.dumps({ - 'active_id': self.id, - }), - 'show': self.user_has_groups('project.group_project_manager'), - 'sequence': 19, }] + if self.user_has_groups('project.group_project_rating'): + buttons.append({ + 'icon': 'smile-o', + 'text': _('Customer Satisfaction'), + 'number': '%s %%' % (self.rating_percentage_satisfaction), + 'action_type': 'object', + 'action': 'action_view_all_rating', + 'show': self.rating_active and self.rating_percentage_satisfaction > -1, + 'sequence': 5, + }) + if self.user_has_groups('project.group_project_manager'): + buttons.append({ + 'icon': 'area-chart', + 'text': _('Burndown Chart'), + 'action_type': 'action', + 'action': 'project.action_project_task_burndown_chart_report', + 'additional_context': json.dumps({ + 'active_id': self.id, + }), + 'show': True, + 'sequence': 7, + }) + buttons.append({ + 'icon': 'users', + 'text': _('Collaborators'), + 'number': self.collaborator_count, + 'action_type': 'action', + 'action': 'project.project_collaborator_action', + 'additional_context': json.dumps({ + 'active_id': self.id, + }), + 'show': True, + 'sequence': 23, + }) + if self.user_has_groups('analytic.group_analytic_accounting'): + buttons.append({ + 'icon': 'usd', + 'text': _('Gross Margin'), + 'number': format_amount(self.env, self.analytic_account_balance, self.company_id.currency_id), + 'action_type': 'object', + 'action': 'action_view_analytic_account_entries', + 'show': True, + 'sequence': 18, + }) return buttons def _get_tasks_analysis_counts(self, created=False, updated=False): diff --git a/addons/project_hr_expense/models/project.py b/addons/project_hr_expense/models/project.py index 9449190dced..a96b88f02ec 100644 --- a/addons/project_hr_expense/models/project.py +++ b/addons/project_hr_expense/models/project.py @@ -46,13 +46,14 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'money', - 'text': _('Expenses'), - 'number': self.expenses_count, - 'action_type': 'object', - 'action': 'action_open_project_expenses', - 'show': self.user_has_groups('hr_expense.group_hr_expense_team_approver') and self.expenses_count > 0, - 'sequence': 10, - }) + if self.user_has_groups('hr_expense.group_hr_expense_team_approver'): + buttons.append({ + 'icon': 'money', + 'text': _('Expenses'), + 'number': self.expenses_count, + 'action_type': 'object', + 'action': 'action_open_project_expenses', + 'show': self.expenses_count > 0, + 'sequence': 10, + }) return buttons diff --git a/addons/project_mrp/models/project.py b/addons/project_mrp/models/project.py index 02015281e10..6f56f157c0c 100644 --- a/addons/project_mrp/models/project.py +++ b/addons/project_mrp/models/project.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import fields, models, _ class Project(models.Model): @@ -13,12 +13,57 @@ class Project(models.Model): def action_view_mrp_production(self): self.ensure_one() - return self.analytic_account_id.action_view_mrp_production() + action = self.analytic_account_id.action_view_mrp_production() + if self.production_count > 1: + action["view_mode"] = 'tree,form,kanban,calendar,pivot,graph' + return action def action_view_mrp_bom(self): self.ensure_one() - return self.analytic_account_id.action_view_mrp_bom() + action = self.analytic_account_id.action_view_mrp_bom() + if self.bom_count > 1: + action['view_mode'] = 'tree,form,kanban' + return action def action_view_workorder(self): self.ensure_one() - return self.analytic_account_id.action_view_workorder() + action = self.analytic_account_id.action_view_workorder() + if self.workorder_count > 1: + action['view_mode'] = 'tree,form,kanban,calendar,pivot,graph,gantt' + return action + + # ---------------------------- + # Project Updates + # ---------------------------- + + def _get_stat_buttons(self): + buttons = super(Project, self)._get_stat_buttons() + if self.user_has_groups('mrp.group_mrp_user'): + buttons.extend([{ + 'icon': 'wrench', + 'text': _('Manufacturing Orders'), + 'number': self.production_count, + 'action_type': 'object', + 'action': 'action_view_mrp_production', + 'show': self.production_count > 0, + 'sequence': 19, + }, + { + 'icon': 'cog', + 'text': _('Work Orders'), + 'number': self.workorder_count, + 'action_type': 'object', + 'action': 'action_view_workorder', + 'show': self.workorder_count > 0, + 'sequence': 20, + }, + { + 'icon': 'flask', + 'text': _('Bills of Materials'), + 'number': self.bom_count, + 'action_type': 'object', + 'action': 'action_view_mrp_bom', + 'show': self.bom_count > 0, + 'sequence': 21, + }]) + return buttons diff --git a/addons/project_mrp/views/project_views.xml b/addons/project_mrp/views/project_views.xml index 73d20de0ad8..e9c5489bead 100644 --- a/addons/project_mrp/views/project_views.xml +++ b/addons/project_mrp/views/project_views.xml @@ -8,15 +8,18 @@ diff --git a/addons/project_purchase/models/project.py b/addons/project_purchase/models/project.py index a29879e6f37..1ae99499007 100644 --- a/addons/project_purchase/models/project.py +++ b/addons/project_purchase/models/project.py @@ -49,13 +49,14 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'credit-card', - 'text': _('Purchase Orders'), - 'number': self.purchase_orders_count, - 'action_type': 'object', - 'action': 'action_open_project_purchase_orders', - 'show': self.user_has_groups('purchase.group_purchase_user') and self.purchase_orders_count > 0, - 'sequence': 13, - }) + if self.user_has_groups('purchase.group_purchase_user'): + buttons.append({ + 'icon': 'credit-card', + 'text': _('Purchase Orders'), + 'number': self.purchase_orders_count, + 'action_type': 'object', + 'action': 'action_open_project_purchase_orders', + 'show': self.purchase_orders_count > 0, + 'sequence': 13, + }) return buttons diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index 707ae7492c2..5746931f135 100644 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -76,14 +76,15 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'dollar', - 'text': _('Sales Order'), - 'action_type': 'object', - 'action': 'action_view_so', - 'show': self.user_has_groups('sales_team.group_sale_salesman_all_leads') and bool(self.sale_order_id), - 'sequence': 1, - }) + if self.user_has_groups('sales_team.group_sale_salesman_all_leads'): + buttons.append({ + 'icon': 'dollar', + 'text': _('Sales Order'), + 'action_type': 'object', + 'action': 'action_view_so', + 'show': bool(self.sale_order_id), + 'sequence': 1, + }) return buttons class ProjectTask(models.Model): diff --git a/addons/sale_project_account/models/project.py b/addons/sale_project_account/models/project.py index 00d812d51fd..ac25b813fac 100644 --- a/addons/sale_project_account/models/project.py +++ b/addons/sale_project_account/models/project.py @@ -35,13 +35,14 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'pencil-square-o', - 'text': _('Vendor Bills'), - 'number': self.vendor_bill_count, - 'action_type': 'object', - 'action': 'action_open_project_vendor_bills', - 'show': self.user_has_groups('account.group_account_readonly') and self.vendor_bill_count > 0, - 'sequence': 14, - }) + if self.user_has_groups('account.group_account_readonly'): + buttons.append({ + 'icon': 'pencil-square-o', + 'text': _('Vendor Bills'), + 'number': self.vendor_bill_count, + 'action_type': 'object', + 'action': 'action_open_project_vendor_bills', + 'show': self.vendor_bill_count > 0, + 'sequence': 14, + }) return buttons diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index e2141ffc076..6f72d684eb4 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -387,19 +387,20 @@ class Project(models.Model): def _get_stat_buttons(self): buttons = super(Project, self)._get_stat_buttons() - buttons.append({ - 'icon': 'clock-o', - 'text': _('Billable Time'), - 'number': '%s %%' % (self.billable_percentage), - 'action_type': 'object', - 'action': 'action_billable_time_button', - 'additional_context': json.dumps({ - 'active_id': self.id, - 'default_project_id': self.id - }), - 'show': self.user_has_groups('hr_timesheet.group_hr_timesheet_approver') and self.allow_timesheets and bool(self.analytic_account_id), - 'sequence': 9, - }) + if self.user_has_groups('hr_timesheet.group_hr_timesheet_approver'): + buttons.append({ + 'icon': 'clock-o', + 'text': _('Billable Time'), + 'number': '%s %%' % (self.billable_percentage), + 'action_type': 'object', + 'action': 'action_billable_time_button', + 'additional_context': json.dumps({ + 'active_id': self.id, + 'default_project_id': self.id + }), + 'show': self.allow_timesheets and bool(self.analytic_account_id), + 'sequence': 9, + }) return buttons class ProjectTask(models.Model):