From 41bcee0cda20befefe80a6190f3b5e37eb880988 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Wed, 2 Mar 2022 13:06:58 +0000 Subject: [PATCH] [FIX] *: use lazy translation for _get_stat_buttons in project update Before this commit, the translation is not done in lazy, so for each stat button shown in the right side panel of the project update, a query is done to find the correct translation based on the language of the user. It means, the translation is costly and need to be done in lazy to reduce the time for the translation of those stat buttons. This commit uses the `_lt` to translate in lazy mode those stat buttons. By doing that, the execution time is reduced from 750 ms to 250 ms. X-original-commit: 95fe018 Part-of: odoo/odoo#85660 Co-authored-by: Yannick Tivisse Co-authored-by: Laurent Stukkens (LTU) --- addons/account_sale_timesheet/models/project.py | 4 ++-- addons/hr_timesheet/models/project.py | 4 ++-- addons/project/models/project.py | 12 ++++++------ addons/project_hr_expense/models/project.py | 4 ++-- addons/project_mrp/models/project.py | 8 ++++---- addons/project_purchase/models/project.py | 4 ++-- addons/sale_project/models/project.py | 4 ++-- addons/sale_project_account/models/project.py | 4 ++-- addons/sale_timesheet/models/project.py | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/addons/account_sale_timesheet/models/project.py b/addons/account_sale_timesheet/models/project.py index a6b30730559..4dc05e5a2fd 100644 --- a/addons/account_sale_timesheet/models/project.py +++ b/addons/account_sale_timesheet/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, _lt class Project(models.Model): _inherit = 'project.project' @@ -17,7 +17,7 @@ class Project(models.Model): if self.user_has_groups('account.group_account_readonly'): buttons.append({ 'icon': 'pencil-square-o', - 'text': _('Invoices'), + 'text': _lt('Invoices'), 'number': self.invoice_count, 'action_type': 'object', 'action': 'action_open_project_invoices', diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 4fc74ac6db4..7892580d380 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -3,7 +3,7 @@ from collections import defaultdict -from odoo import models, fields, api, _ +from odoo import models, fields, api, _, _lt from odoo.exceptions import UserError, ValidationError, RedirectWarning @@ -248,7 +248,7 @@ class Project(models.Model): if self.user_has_groups('hr_timesheet.group_hr_timesheet_user'): buttons.append({ 'icon': 'clock-o', - 'text': _('Recorded'), + 'text': _lt('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', diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 2b4804a67e2..b635483b856 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -8,7 +8,7 @@ from collections import defaultdict from datetime import timedelta, datetime, time from random import randint -from odoo import api, Command, fields, models, tools, SUPERUSER_ID, _ +from odoo import api, Command, fields, models, tools, SUPERUSER_ID, _, _lt from odoo.exceptions import UserError, ValidationError, AccessError from odoo.tools import format_amount from odoo.osv.expression import OR, AND @@ -746,7 +746,7 @@ class Project(models.Model): self.ensure_one() buttons = [{ 'icon': 'tasks', - 'text': _('Tasks'), + 'text': _lt('Tasks'), 'number': self.task_count, 'action_type': 'action', 'action': 'project.act_project_project_2_project_task_all', @@ -759,7 +759,7 @@ class Project(models.Model): if self.user_has_groups('project.group_project_rating'): buttons.append({ 'icon': 'smile-o', - 'text': _('Satisfaction'), + 'text': _lt('Satisfaction'), 'number': f'{round(100 * self.rating_avg_percentage, 2)} %', 'action_type': 'object', 'action': 'action_view_all_rating', @@ -769,7 +769,7 @@ class Project(models.Model): if self.user_has_groups('project.group_project_manager'): buttons.append({ 'icon': 'area-chart', - 'text': _('Burndown Chart'), + 'text': _lt('Burndown Chart'), 'action_type': 'action', 'action': 'project.action_project_task_burndown_chart_report', 'additional_context': json.dumps({ @@ -780,7 +780,7 @@ class Project(models.Model): }) buttons.append({ 'icon': 'users', - 'text': _('Collaborators'), + 'text': _lt('Collaborators'), 'number': self.collaborator_count, 'action_type': 'action', 'action': 'project.project_collaborator_action', @@ -793,7 +793,7 @@ class Project(models.Model): if self.user_has_groups('analytic.group_analytic_accounting'): buttons.append({ 'icon': 'usd', - 'text': _('Gross Margin'), + 'text': _lt('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', diff --git a/addons/project_hr_expense/models/project.py b/addons/project_hr_expense/models/project.py index 3968877af7e..941d4c0f8de 100644 --- a/addons/project_hr_expense/models/project.py +++ b/addons/project_hr_expense/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 api, fields, models, _ +from odoo import api, fields, models, _, _lt class Project(models.Model): _inherit = 'project.project' @@ -49,7 +49,7 @@ class Project(models.Model): if self.user_has_groups('hr_expense.group_hr_expense_team_approver'): buttons.append({ 'icon': 'money', - 'text': _('Expenses'), + 'text': _lt('Expenses'), 'number': self.expenses_count, 'action_type': 'object', 'action': 'action_open_project_expenses', diff --git a/addons/project_mrp/models/project.py b/addons/project_mrp/models/project.py index ff029fc0a69..2086c1cf53e 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, _lt class Project(models.Model): @@ -41,7 +41,7 @@ class Project(models.Model): if self.user_has_groups('mrp.group_mrp_user'): buttons.extend([{ 'icon': 'wrench', - 'text': _('Manufacturing Orders'), + 'text': _lt('Manufacturing Orders'), 'number': self.production_count, 'action_type': 'object', 'action': 'action_view_mrp_production', @@ -50,7 +50,7 @@ class Project(models.Model): }, { 'icon': 'cog', - 'text': _('Work Orders'), + 'text': _lt('Work Orders'), 'number': self.workorder_count, 'action_type': 'object', 'action': 'action_view_workorder', @@ -59,7 +59,7 @@ class Project(models.Model): }, { 'icon': 'flask', - 'text': _('Bills of Materials'), + 'text': _lt('Bills of Materials'), 'number': self.bom_count, 'action_type': 'object', 'action': 'action_view_mrp_bom', diff --git a/addons/project_purchase/models/project.py b/addons/project_purchase/models/project.py index 0fa33167953..6bf9a462cea 100644 --- a/addons/project_purchase/models/project.py +++ b/addons/project_purchase/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 api, fields, models, _ +from odoo import api, fields, models, _, _lt class Project(models.Model): @@ -52,7 +52,7 @@ class Project(models.Model): if self.user_has_groups('purchase.group_purchase_user'): buttons.append({ 'icon': 'credit-card', - 'text': _('Purchase Orders'), + 'text': _lt('Purchase Orders'), 'number': self.purchase_orders_count, 'action_type': 'object', 'action': 'action_open_project_purchase_orders', diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index 4373d51a645..a4b45263170 100644 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -3,7 +3,7 @@ from ast import literal_eval -from odoo import api, fields, models, _ +from odoo import api, fields, models, _, _lt from odoo.exceptions import ValidationError, AccessError @@ -134,7 +134,7 @@ class Project(models.Model): if self.user_has_groups('sales_team.group_sale_salesman_all_leads'): buttons.append({ 'icon': 'dollar', - 'text': _('Sales Orders'), + 'text': _lt('Sales Orders'), 'number': self.sale_order_count, 'action_type': 'object', 'action': 'action_view_sos', diff --git a/addons/sale_project_account/models/project.py b/addons/sale_project_account/models/project.py index aa830cc74bb..2c77c19a41f 100644 --- a/addons/sale_project_account/models/project.py +++ b/addons/sale_project_account/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, _, _lt class Project(models.Model): _inherit = 'project.project' @@ -38,7 +38,7 @@ class Project(models.Model): if self.user_has_groups('account.group_account_readonly'): buttons.append({ 'icon': 'pencil-square-o', - 'text': _('Vendor Bills'), + 'text': _lt('Vendor Bills'), 'number': self.vendor_bill_count, 'action_type': 'object', 'action': 'action_open_project_vendor_bills', diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 36d94d23ddf..85f3512bb77 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -4,7 +4,7 @@ import json from collections import defaultdict -from odoo import api, fields, models, _ +from odoo import api, fields, models, _, _lt from odoo.osv import expression from odoo.exceptions import ValidationError, UserError from odoo.tools import format_amount, float_is_zero, formatLang @@ -404,7 +404,7 @@ class Project(models.Model): if self.user_has_groups('hr_timesheet.group_hr_timesheet_approver'): buttons.append({ 'icon': 'clock-o', - 'text': _('Billable Time'), + 'text': _lt('Billable Time'), 'number': '%s %%' % (self.billable_percentage), 'action_type': 'object', 'action': 'action_billable_time_button',