[IMP] mrp_bom_hierarchy: black, isort, prettier

This commit is contained in:
Miquel Raïch
2022-06-15 12:50:35 +02:00
parent ad22e96e85
commit 034a104d7a
12 changed files with 244 additions and 252 deletions

View File

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (C) 2015 Eficent (<http://www.eficent.com/>) # Copyright (C) 2015 Eficent (<http://www.eficent.com/>)
@@ -18,4 +17,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from . import model from . import model

View File

@@ -0,0 +1,35 @@
##############################################################################
#
# Copyright (C) 2015 Eficent (<http://www.eficent.com/>)
# <contact@eficent.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "MRP BOM Hierarchy",
"version": "1.0",
"author": "Eficent, Odoo Community Association (OCA)",
"category": "Manufacturing",
"depends": ["mrp"],
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"demo": [],
"data": [
"view/mrp.xml",
],
"test": [],
"installable": True,
"auto_install": False,
}

View File

@@ -1,103 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Eficent (<http://www.eficent.com/>)
# <contact@eficent.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "MRP BOM Hierarchy",
"version": "1.0",
"author": "Eficent",
"website": "www.eficent.com",
"category": "Manufacturing",
"depends": ["mrp"],
"description": """
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
MRP BOM Hierarchy
=================
This module was written to extend the functionality of Bill of
Materials to support users to better maintain the BOM hierarchy.
This module replaces the existing BOM tree views with a new one, from
which the user can create a complete BOM hierarchy.
The user can navigate from the tree view to child BOM's, or to the
product's BOM components with a single click.
The user can now search using the field 'Complete Reference' (or Name) to
find all the BOM hierarchy associated to a particular BOM Reference (or
Name) at once.
Installation
============
No specific installation steps are required.
Configuration
=============
No specific configuration steps are required.
Usage
=====
To use this module, you need to go to 'Manufacturing | Products | Bill of
Materials Hierarchy'
Known issues / Roadmap
======================
No issues have been identified with this module.
Credits
=======
Contributors
------------
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.
""",
"website": "http://www.eficent.com/",
"license": "AGPL-3",
"demo": [],
"data": [
"view/mrp.xml",
],
"test": [],
"installable": True,
"auto_install": False,
"active": False
}

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (C) 2014 Eficent (<http://www.eficent.com/>) # Copyright (C) 2014 Eficent (<http://www.eficent.com/>)
@@ -18,4 +17,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from . import mrp from . import mrp

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
@@ -19,11 +18,11 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields, expression from odoo import fields, models
class mrp_bom(osv.osv): class Bom(models.Model):
_inherit = 'mrp.bom' _inherit = "mrp.bom"
def get_child_boms(self, cr, uid, ids, context=None): def get_child_boms(self, cr, uid, ids, context=None):
result = {} result = {}
@@ -32,7 +31,8 @@ class mrp_bom(osv.osv):
for curr_id in ids: for curr_id in ids:
result[curr_id] = True result[curr_id] = True
# Now add the children # Now add the children
cr.execute(''' cr.execute(
"""
WITH RECURSIVE children AS ( WITH RECURSIVE children AS (
SELECT bom_id, id SELECT bom_id, id
FROM mrp_bom FROM mrp_bom
@@ -43,20 +43,20 @@ class mrp_bom(osv.osv):
JOIN children b ON(a.bom_id = b.id) JOIN children b ON(a.bom_id = b.id)
) )
SELECT * FROM children order by bom_id SELECT * FROM children order by bom_id
''', (tuple(ids),)) """,
(tuple(ids),),
)
res = cr.fetchall() res = cr.fetchall()
for x, y in res: for _x, y in res:
result[y] = True result[y] = True
return result return result
def _get_boms_from_product(self, cr, uid, ids, context=None): def _get_boms_from_product(self, cr, uid, ids, context=None):
result = {} result = {}
bom_obj = self.pool.get('mrp.bom') bom_obj = self.pool.get("mrp.bom")
for p in ids: for p in ids:
product_bom_ids = bom_obj.search( product_bom_ids = bom_obj.search(cr, uid, [("product_id", "=", p)])
cr, uid, [('product_id', '=', p)]) bom_ids = bom_obj.get_child_boms(cr, uid, product_bom_ids, context=context)
bom_ids = bom_obj.get_child_boms(cr, uid, product_bom_ids,
context=context)
for bom_id in bom_ids: for bom_id in bom_ids:
result[bom_id] = True result[bom_id] = True
return result return result
@@ -71,8 +71,7 @@ class mrp_bom(osv.osv):
result[bom.id] = True result[bom.id] = True
return result return result
def _bom_hierarchy_indent_calc(self, cr, uid, ids, prop, unknow_none, def _bom_hierarchy_indent_calc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
unknow_dict):
if not ids: if not ids:
return [] return []
res = [] res = []
@@ -81,17 +80,18 @@ class mrp_bom(osv.osv):
b = bom b = bom
while b: while b:
if b.name and b.bom_id: if b.name and b.bom_id:
data.insert(0, '>') data.insert(0, ">")
else: else:
data.insert(0, '') data.insert(0, "")
b = b.bom_id b = b.bom_id
data = ''.join(data) data = "".join(data)
res.append((bom.id, data)) res.append((bom.id, data))
return dict(res) return dict(res)
def _complete_bom_hierarchy_code_calc( def _complete_bom_hierarchy_code_calc(
self, cr, uid, ids, prop, unknow_none, unknow_dict): self, cr, uid, ids, prop, unknow_none, unknow_dict
):
if not ids: if not ids:
return [] return []
res = [] res = []
@@ -106,17 +106,18 @@ class mrp_bom(osv.osv):
elif b.product_id.default_code: elif b.product_id.default_code:
data.insert(0, b.product_id.default_code) data.insert(0, b.product_id.default_code)
else: else:
data.insert(0, '') data.insert(0, "")
b = b.bom_id b = b.bom_id
data = ' / '.join(data) data = " / ".join(data)
data = '[' + data + '] ' data = "[" + data + "] "
res.append((bom.id, data)) res.append((bom.id, data))
return dict(res) return dict(res)
def _complete_bom_hierarchy_name_calc( def _complete_bom_hierarchy_name_calc(
self, cr, uid, ids, prop, unknow_none, unknow_dict): self, cr, uid, ids, prop, unknow_none, unknow_dict
):
if not ids: if not ids:
return [] return []
res = [] res = []
@@ -129,11 +130,11 @@ class mrp_bom(osv.osv):
elif b.product_id.name: elif b.product_id.name:
data.insert(0, b.product_id.name) data.insert(0, b.product_id.name)
else: else:
data.insert(0, '') data.insert(0, "")
b = b.bom_id b = b.bom_id
data = ' / '.join(data) data = " / ".join(data)
res.append((bom.id, data)) res.append((bom.id, data))
return dict(res) return dict(res)
@@ -146,13 +147,15 @@ class mrp_bom(osv.osv):
res[bom.id] = False res[bom.id] = False
return res return res
def _product_has_own_bom(self, cr, uid, ids, prop, unknow_none, def _product_has_own_bom(self, cr, uid, ids, prop, unknow_none, unknow_dict):
unknow_dict):
res = {} res = {}
for bom in self.browse(cr, uid, ids, context=None): for bom in self.browse(cr, uid, ids, context=None):
bom_ids = self.pool.get('mrp.bom').search( bom_ids = self.pool.get("mrp.bom").search(
cr, uid, [('product_id', '=', bom.product_id.id), cr,
('bom_id', '=', False)], context=None) uid,
[("product_id", "=", bom.product_id.id), ("bom_id", "=", False)],
context=None,
)
if bom_ids: if bom_ids:
res[bom.id] = True res[bom.id] = True
else: else:
@@ -160,42 +163,59 @@ class mrp_bom(osv.osv):
return res return res
_columns = { _columns = {
'is_parent': fields.function(_is_parent, string="Is parent BOM", "is_parent": fields.function(
type='boolean', readonly=True, _is_parent,
store=True), string="Is parent BOM",
'has_child': fields.function(_is_bom, string="Has components", type="boolean",
type='boolean', readonly=True), readonly=True,
'product_has_own_bom': fields.function(_product_has_own_bom, store=True,
string="Product has own BOM", ),
type='boolean', readonly=True), "has_child": fields.function(
'bom_hierarchy_indent': fields.function(_bom_hierarchy_indent_calc, _is_bom, string="Has components", type="boolean", readonly=True
method=True, ),
type='char', string='Level', "product_has_own_bom": fields.function(
size=32, readonly=True), _product_has_own_bom,
'complete_bom_hierarchy_code': fields.function( string="Product has own BOM",
_complete_bom_hierarchy_code_calc, method=True, type='char', type="boolean",
string='Complete Reference', size=250, readonly=True,
help='Describes the full path of this ' ),
'component within the BOM hierarchy using the BOM reference.', "bom_hierarchy_indent": fields.function(
_bom_hierarchy_indent_calc,
method=True,
type="char",
string="Level",
size=32,
readonly=True,
),
"complete_bom_hierarchy_code": fields.function(
_complete_bom_hierarchy_code_calc,
method=True,
type="char",
string="Complete Reference",
size=250,
help="Describes the full path of this "
"component within the BOM hierarchy using the BOM reference.",
store={ store={
'mrp.bom': (get_child_boms, ['name', 'code', 'position', "mrp.bom": (get_child_boms, ["name", "code", "position", "bom_id"], 20),
'bom_id'], 20), "product.product": (_get_boms_from_product, ["default_code"], 20),
'product.product': (_get_boms_from_product, ['default_code'],
20),
}),
'complete_bom_hierarchy_name': fields.function(
_complete_bom_hierarchy_name_calc, method=True, type='char',
string='Complete Name', size=250,
help='Describes the full path of this '
'component within the BOM hierarchy using the BOM name.',
store={
'mrp.bom': (get_child_boms, ['name', 'bom_id'], 20),
'product.product': (_get_boms_from_product, ['name'], 20),
}, },
), ),
"complete_bom_hierarchy_name": fields.function(
_complete_bom_hierarchy_name_calc,
method=True,
type="char",
string="Complete Name",
size=250,
help="Describes the full path of this "
"component within the BOM hierarchy using the BOM name.",
store={
"mrp.bom": (get_child_boms, ["name", "bom_id"], 20),
"product.product": (_get_boms_from_product, ["name"], 20),
},
),
} }
_order = 'complete_bom_hierarchy_code' _order = "complete_bom_hierarchy_code"
def action_openChildTreeView(self, cr, uid, ids, context=None): def action_openChildTreeView(self, cr, uid, ids, context=None):
""" """
@@ -204,17 +224,17 @@ class mrp_bom(osv.osv):
if context is None: if context is None:
context = {} context = {}
bom = self.browse(cr, uid, ids[0], context) bom = self.browse(cr, uid, ids[0], context)
child_bom_ids = self.pool.get('mrp.bom').search( child_bom_ids = self.pool.get("mrp.bom").search(
cr, uid, [('bom_id', '=', bom.id)]) cr, uid, [("bom_id", "=", bom.id)]
res = self.pool.get('ir.actions.act_window').for_xml_id( )
cr, uid, 'mrp_bom_hierarchy', 'action_mrp_bom_hierarchy_tree2', res = self.pool.get("ir.actions.act_window").for_xml_id(
context) cr, uid, "mrp_bom_hierarchy", "action_mrp_bom_hierarchy_tree2", context
res['context'] = { )
'default_bom_id': bom.id, res["context"] = {
"default_bom_id": bom.id,
} }
res['domain'] = "[('id', 'in', ["+','.join( res["domain"] = "[('id', 'in', [" + ",".join(map(str, child_bom_ids)) + "])]"
map(str, child_bom_ids))+"])]" res["nodestroy"] = False
res['nodestroy'] = False
return res return res
def action_openParentTreeView(self, cr, uid, ids, context=None): def action_openParentTreeView(self, cr, uid, ids, context=None):
@@ -224,15 +244,15 @@ class mrp_bom(osv.osv):
if context is None: if context is None:
context = {} context = {}
bom = self.browse(cr, uid, ids[0], context) bom = self.browse(cr, uid, ids[0], context)
res = self.pool.get('ir.actions.act_window').for_xml_id( res = self.pool.get("ir.actions.act_window").for_xml_id(
cr, uid, 'mrp_bom_hierarchy', 'action_mrp_bom_hierarchy_tree2', cr, uid, "mrp_bom_hierarchy", "action_mrp_bom_hierarchy_tree2", context
context) )
if bom.bom_id: if bom.bom_id:
for parent_bom_id in self.pool.get('mrp.bom').search( for parent_bom_id in self.pool.get("mrp.bom").search(
cr, uid, [('id', '=', cr, uid, [("id", "=", bom.bom_id.id)]
bom.bom_id.id)]): ):
res['domain'] = "[('id','=',"+str(parent_bom_id)+")]" res["domain"] = "[('id','='," + str(parent_bom_id) + ")]"
res['nodestroy'] = False res["nodestroy"] = False
return res return res
def action_openProductBOMTreeView(self, cr, uid, ids, context=None): def action_openProductBOMTreeView(self, cr, uid, ids, context=None):
@@ -242,17 +262,19 @@ class mrp_bom(osv.osv):
if context is None: if context is None:
context = {} context = {}
bom = self.browse(cr, uid, ids[0], context) bom = self.browse(cr, uid, ids[0], context)
product_bom_ids = self.pool.get('mrp.bom').search( product_bom_ids = self.pool.get("mrp.bom").search(
cr, uid, [('product_id', '=', bom.product_id.id), cr,
('bom_id', '=', False)], context=context) uid,
res = self.pool.get('ir.actions.act_window').for_xml_id( [("product_id", "=", bom.product_id.id), ("bom_id", "=", False)],
cr, uid, 'mrp', 'mrp_bom_form_action2', context=context,
context) )
res = self.pool.get("ir.actions.act_window").for_xml_id(
cr, uid, "mrp", "mrp_bom_form_action2", context
)
res['context'] = { res["context"] = {
'default_product_id': bom.product_id.id, "default_product_id": bom.product_id.id,
} }
res['domain'] = "[('id', 'in', ["+','.join( res["domain"] = "[('id', 'in', [" + ",".join(map(str, product_bom_ids)) + "])]"
map(str, product_bom_ids))+"])]" res["nodestroy"] = False
res['nodestroy'] = False return res
return res

View File

@@ -0,0 +1 @@
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>

View File

@@ -0,0 +1,12 @@
This module was written to extend the functionality of Bill of
Materials to support users to better maintain the BOM hierarchy.
This module replaces the existing BOM tree views with a new one, from
which the user can create a complete BOM hierarchy.
The user can navigate from the tree view to child BOM's, or to the
product's BOM components with a single click.
The user can now search using the field 'Complete Reference' (or Name) to
find all the BOM hierarchy associated to a particular BOM Reference (or
Name) at once.

View File

@@ -0,0 +1,2 @@
To use this module, you need to go to 'Manufacturing | Products | Bill of
Materials Hierarchy'.

View File

@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<openerp> <odoo>
<data> <data>
<record id="mrp_bom_form_view" model="ir.ui.view"> <record id="mrp_bom_form_view" model="ir.ui.view">
<field name="name">mrp.bom.form</field> <field name="name">mrp.bom.form</field>
<field name="model">mrp.bom</field> <field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/> <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//notebook/page/field[@name='bom_lines']/tree//field[@name='product_id']" position="after"> <xpath
<field name="is_parent" invisible="1"/> expr="//notebook/page/field[@name='bom_lines']/tree//field[@name='product_id']"
<field name="product_has_own_bom"/> position="after"
<button string="View product's BOM" >
name="action_openProductBOMTreeView" <field name="is_parent" invisible="1" />
type="object" <field name="product_has_own_bom" />
icon="terp-folder-orange" <button
attrs="{'invisible': [('is_parent', '=', True)]}"/> string="View product's BOM"
name="action_openProductBOMTreeView"
type="object"
icon="terp-folder-orange"
attrs="{'invisible': [('is_parent', '=', True)]}"
/>
</xpath> </xpath>
</field> </field>
</record> </record>
@@ -22,74 +27,87 @@
<record id="view_mrp_bom_filter" model="ir.ui.view"> <record id="view_mrp_bom_filter" model="ir.ui.view">
<field name="name">mrp.bom.select</field> <field name="name">mrp.bom.select</field>
<field name="model">mrp.bom</field> <field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.view_mrp_bom_filter"/> <field name="inherit_id" ref="mrp.view_mrp_bom_filter" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="before"> <xpath expr="//field[@name='product_id']" position="before">
<field name="complete_bom_hierarchy_code"/> <field name="complete_bom_hierarchy_code" />
<field name="complete_bom_hierarchy_name"/> <field name="complete_bom_hierarchy_name" />
<field name="bom_id"/> <field name="bom_id" />
<field name="is_parent"/> <field name="is_parent" />
<filter string="Parent BOM" name="parent_bom" <filter
domain="[('is_parent','=','True')]"/> string="Parent BOM"
name="parent_bom"
domain="[('is_parent','=','True')]"
/>
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="mrp_bom_hierarchy_tree_view" model="ir.ui.view"> <record id="mrp_bom_hierarchy_tree_view" model="ir.ui.view">
<field name="name">mrp.bom.tree</field> <field name="name">mrp.bom.tree</field>
<field name="model">mrp.bom</field> <field name="model">mrp.bom</field>
<field name="field_parent">child_complete_ids</field> <field name="field_parent">child_complete_ids</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Bill of Materials" <tree string="Bill of Materials" colors="blue:method">
colors="blue:method"> <button
<button string="Child BOMs" string="Child BOMs"
name="action_openChildTreeView" name="action_openChildTreeView"
type="object" type="object"
icon="STOCK_GO_DOWN"/> icon="STOCK_GO_DOWN"
<field name="has_child"/> />
<field name="complete_bom_hierarchy_code"/> <field name="has_child" />
<field name="bom_hierarchy_indent"/> <field name="complete_bom_hierarchy_code" />
<field name="sequence"/> <field name="bom_hierarchy_indent" />
<field name="code"/> <field name="sequence" />
<field name="position"/> <field name="code" />
<field name="name"/> <field name="position" />
<field name="bom_id"/> <field name="name" />
<field name="is_parent" invisible="1"/> <field name="bom_id" />
<field name="product_id" context="{'default_supply_method':'produce'}" on_change="onchange_product_id(product_id, name)"/> <field name="is_parent" invisible="1" />
<field name="product_has_own_bom"/> <field
<button string="View product's BOM" name="product_id"
name="action_openProductBOMTreeView" context="{'default_supply_method':'produce'}"
type="object" on_change="onchange_product_id(product_id, name)"
icon="terp-folder-orange" />
attrs="{'invisible': [('is_parent', '=', True)]}"/> <field name="product_has_own_bom" />
<field name="product_qty"/> <button
<field name="product_uom" on_change="onchange_uom(product_id, product_uom)" groups="product.group_uom"/> string="View product's BOM"
<field name="type"/> name="action_openProductBOMTreeView"
<field name="method"/> type="object"
<field name="routing_id" groups="mrp.group_mrp_routings"/> icon="terp-folder-orange"
<field name="date_start"/> attrs="{'invisible': [('is_parent', '=', True)]}"
<field name="date_stop"/> />
<field name="product_qty" />
<field
name="product_uom"
on_change="onchange_uom(product_id, product_uom)"
groups="product.group_uom"
/>
<field name="type" />
<field name="method" />
<field name="routing_id" groups="mrp.group_mrp_routings" />
<field name="date_start" />
<field name="date_stop" />
</tree> </tree>
</field> </field>
</record> </record>
<record id="mrp.mrp_bom_form_action2" model="ir.actions.act_window"> <record id="mrp.mrp_bom_form_action2" model="ir.actions.act_window">
<field name="view_id" ref="mrp_bom_hierarchy_tree_view"/> <field name="view_id" ref="mrp_bom_hierarchy_tree_view" />
</record> </record>
<record id="mrp.mrp_bom_form_action" model="ir.actions.act_window"> <record id="mrp.mrp_bom_form_action" model="ir.actions.act_window">
<field name="view_id" ref="mrp_bom_hierarchy_tree_view"/> <field name="view_id" ref="mrp_bom_hierarchy_tree_view" />
</record> </record>
<record id="action_mrp_bom_hierarchy_tree2" <record id="action_mrp_bom_hierarchy_tree2" model="ir.actions.act_window">
model="ir.actions.act_window">
<field name="name">Bill of Material Hierarchy</field> <field name="name">Bill of Material Hierarchy</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.bom</field> <field name="res_model">mrp.bom</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_id" ref="mrp_bom_hierarchy_tree_view"/> <field name="view_id" ref="mrp_bom_hierarchy_tree_view" />
<field name="domain">[]</field> <field name="domain">[]</field>
</record> </record>
</data> </data>
</openerp> </odoo>

View File

@@ -0,0 +1 @@
../../../../mrp_bom_hierarchy

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)