Merge pull request #124 from akretion/12.0-imp-button-prod-to-bom
[IMP] mrp_usability: improve smart button from products to BoMs
This commit is contained in:
@@ -31,6 +31,8 @@ Small usability improvements on MRP:
|
|||||||
|
|
||||||
* complete Manufacturing Order report with unvailable products
|
* complete Manufacturing Order report with unvailable products
|
||||||
|
|
||||||
|
* improve smart button from products to BoMs (display BoM form if only one instead of displaying a list of one)
|
||||||
|
|
||||||
**Table of contents**
|
**Table of contents**
|
||||||
|
|
||||||
.. contents::
|
.. contents::
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
from . import mrp
|
from . import models
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
'depends': ['mrp'],
|
'depends': ['mrp'],
|
||||||
'data': [
|
'data': [
|
||||||
'mrp_view.xml',
|
'views/mrp_views.xml',
|
||||||
|
'views/product_views.xml',
|
||||||
'report/mrp_report.xml'
|
'report/mrp_report.xml'
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|||||||
2
mrp_usability/models/__init__.py
Normal file
2
mrp_usability/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
from . import mrp, product
|
||||||
44
mrp_usability/models/product.py
Normal file
44
mrp_usability/models/product.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Copyright (C) 2020 - Akretion
|
||||||
|
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductTemplate(models.Model):
|
||||||
|
_inherit = "product.template"
|
||||||
|
|
||||||
|
def action_view_bom(self):
|
||||||
|
"""Replace native action `template_open_bom` to distinguish if we will display
|
||||||
|
only one BoM form or a list of BoMs."""
|
||||||
|
self.ensure_one()
|
||||||
|
|
||||||
|
act_window_xml_id = "mrp.mrp_bom_form_action"
|
||||||
|
act_window = self.env.ref(act_window_xml_id).read()[0]
|
||||||
|
if self.bom_count > 1:
|
||||||
|
act_window["context"] = {
|
||||||
|
"default_product_tmpl_id": self.id,
|
||||||
|
"search_default_product_tmpl_id": self.id,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
act_window["context"] = {"default_product_tmpl_id": self.id}
|
||||||
|
act_window["views"] = [(self.env.ref("mrp.mrp_bom_form_view").id, "form")]
|
||||||
|
act_window["res_id"] = (
|
||||||
|
self.env["mrp.bom"].search([("product_tmpl_id", "=", self.id)]).id
|
||||||
|
)
|
||||||
|
|
||||||
|
return act_window
|
||||||
|
|
||||||
|
|
||||||
|
class ProductProduct(models.Model):
|
||||||
|
_inherit = "product.product"
|
||||||
|
|
||||||
|
def action_view_bom(self):
|
||||||
|
res = super().action_view_bom()
|
||||||
|
|
||||||
|
bom_target_ids = self.env["mrp.bom"].search(res["domain"])
|
||||||
|
|
||||||
|
if len(bom_target_ids) == 1:
|
||||||
|
res["views"] = [(self.env.ref("mrp.mrp_bom_form_view").id, "form")]
|
||||||
|
res["res_id"] = bom_target_ids[0].id
|
||||||
|
|
||||||
|
return res
|
||||||
@@ -9,3 +9,5 @@ Small usability improvements on MRP:
|
|||||||
* show bom type in tree view + add group by
|
* show bom type in tree view + add group by
|
||||||
|
|
||||||
* complete Manufacturing Order report with unvailable products
|
* complete Manufacturing Order report with unvailable products
|
||||||
|
|
||||||
|
* improve smart button from products to BoMs (display BoM form if only one instead of displaying a list of one)
|
||||||
|
|||||||
25
mrp_usability/views/product_views.xml
Normal file
25
mrp_usability/views/product_views.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="product_template_form_view_bom_button" model="ir.ui.view">
|
||||||
|
<field name="name">product.template.procurement</field>
|
||||||
|
<field name="model">product.template</field>
|
||||||
|
<field name="inherit_id" ref="mrp.product_template_form_view_bom_button" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
|
<xpath expr="//field[@name='bom_count']/.." position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='bom_count']/.." position="after">
|
||||||
|
<button class="oe_stat_button" name="action_view_bom" type="object"
|
||||||
|
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}"
|
||||||
|
icon="fa-flask">
|
||||||
|
<field string="Bill of Materials" name="bom_count"
|
||||||
|
widget="statinfo" />
|
||||||
|
</button>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user