Files
odoo_source/addons/project_mrp/models/project.py
T
41bcee0cda [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 <yti@odoo.com>
Co-authored-by: Laurent Stukkens (LTU) <ltu@odoo.com>
2022-03-03 03:07:57 +00:00

70 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _lt
class Project(models.Model):
_inherit = "project.project"
production_count = fields.Integer(related="analytic_account_id.production_count", groups='mrp.group_mrp_user')
workorder_count = fields.Integer(related="analytic_account_id.workorder_count", groups='mrp.group_mrp_user')
bom_count = fields.Integer(related="analytic_account_id.bom_count", groups='mrp.group_mrp_user')
def action_view_mrp_production(self):
self.ensure_one()
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()
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()
action = self.analytic_account_id.action_view_workorder()
if self.workorder_count > 1:
action['view_mode'] = 'tree,form,kanban,calendar,pivot,graph'
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': _lt('Manufacturing Orders'),
'number': self.production_count,
'action_type': 'object',
'action': 'action_view_mrp_production',
'show': self.production_count > 0,
'sequence': 39,
},
{
'icon': 'cog',
'text': _lt('Work Orders'),
'number': self.workorder_count,
'action_type': 'object',
'action': 'action_view_workorder',
'show': self.workorder_count > 0,
'sequence': 42,
},
{
'icon': 'flask',
'text': _lt('Bills of Materials'),
'number': self.bom_count,
'action_type': 'object',
'action': 'action_view_mrp_bom',
'show': self.bom_count > 0,
'sequence': 45,
}])
return buttons