Files
odoo_source/addons/project_mrp/models/project.py
T
Cedric Prieels (cpr) 828d5157a5 [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 <IT-Ideas@users.noreply.github.com>
2021-09-14 12:07:39 +00:00

70 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
class Project(models.Model):
_inherit = "project.project"
production_count = fields.Integer(related="analytic_account_id.production_count")
workorder_count = fields.Integer(related="analytic_account_id.workorder_count")
bom_count = fields.Integer(related="analytic_account_id.bom_count")
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,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