add 10.0-mrp_bom_component_find and FIX oca rules

This commit is contained in:
Tony Galmiche
2018-04-23 09:54:33 +02:00
committed by Lois Rilo
parent e73d339e2d
commit af968f2141
13 changed files with 451 additions and 2 deletions

View File

@@ -0,0 +1,74 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
======================
MRP BOM Component Find
======================
This module add MRP BOM component find functionality (Use Case).
Allows you to find the product usages across all Bill of Materials.
Usage
=====
* From the form of a component click on the button 'Component find'.
* or click on the 'Master Data / Component find' and choose a component.
* The result displays the list of finished products containing this
component and in which level of the bom this component appears
.. image:: static/description/mrp_bom_component_find.png
:alt: Sample Component find
:width: 95 %
:align: center
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/129/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/mrp_bom_component_find/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Tony Galmiche <tony.galmiche@infosaone.com> (http://infosaone.com)
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Tony Galmiche - InfoSaône <tony.galmiche@infosaone.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'MRB BOM Component Find (Product Use Case)',
'version': '10.0.1.0.0',
'category': 'mrp',
'summary': 'Know the case of multi-level use of a component from bom',
'author': 'Tony Galmiche,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/manufacture',
'license': 'AGPL-3',
'depends': [
'mrp',
],
'data': [
'views/product_views.xml',
'wizard/mrp_bom_component_find_wizard.xml',
],
'update_xml': [],
'demo_xml': [],
'installable': True,
'application': False,
}

View File

@@ -0,0 +1,130 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_bom_component_find
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-23 07:49+0000\n"
"PO-Revision-Date: 2018-04-23 07:49+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mrp_bom_component_find
#: model:ir.ui.view,arch_db:mrp_bom_component_find.mrp_bom_component_find_wizard_form
msgid "Cancel"
msgstr "Annuler"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_component_id
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_product_id
msgid "Component"
msgstr "Composant"
#. module: mrp_bom_component_find
#: model:ir.actions.act_window,name:mrp_bom_component_find.mrp_bom_component_find_wizard_action
#: model:ir.ui.menu,name:mrp_bom_component_find.mrp_bom_component_find_menu
#: model:ir.ui.view,arch_db:mrp_bom_component_find.mrp_bom_component_find_wizard_form
#: model:ir.ui.view,arch_db:mrp_bom_component_find.product_product_form_view_use_case_button
#: model:ir.ui.view,arch_db:mrp_bom_component_find.product_template_form_view_use_case_button
msgid "Component find"
msgstr "Recherche composant"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_create_uid
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_create_uid
msgid "Created by"
msgstr "Créé par"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_create_date
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_create_date
msgid "Created on"
msgstr "Créé le"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_display_name
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_display_name
msgid "Display Name"
msgstr "Nom affiché"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_id
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_id
msgid "ID"
msgstr "ID"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line___last_update
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard___last_update
msgid "Last Modified on"
msgstr "Dernière Modification le"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_write_uid
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_write_uid
msgid "Last Updated by"
msgstr "Dernière mise à jour par"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_write_date
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_wizard_write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_level
msgid "Level"
msgstr "Niveau"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_line
msgid "Line"
msgstr "Ligne"
#. module: mrp_bom_component_find
#: model:ir.ui.view,arch_db:mrp_bom_component_find.mrp_bom_component_find_wizard_form
msgid "OK"
msgstr "OK"
#. module: mrp_bom_component_find
#: model:ir.model,name:mrp_bom_component_find.model_product_product
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_mrp_bom_id
msgid "Product"
msgstr "Article"
#. module: mrp_bom_component_find
#: model:ir.model,name:mrp_bom_component_find.model_product_template
msgid "Product Template"
msgstr "Modèle d'article"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_quantity
msgid "Quantity"
msgstr "Quantité"
#. module: mrp_bom_component_find
#: model:ir.model.fields,field_description:mrp_bom_component_find.field_mrp_bom_component_find_line_wizard_id
msgid "Wizard"
msgstr "Assistant"
#. module: mrp_bom_component_find
#: model:ir.model,name:mrp_bom_component_find.model_mrp_bom_component_find_line
msgid "mrp.bom.component.find.line"
msgstr "mrp.bom.component.find.line"
#. module: mrp_bom_component_find
#: model:ir.model,name:mrp_bom_component_find.model_mrp_bom_component_find_wizard
msgid "mrp.bom.component.find.wizard"
msgstr "mrp.bom.component.find.wizard"
#. module: mrp_bom_component_find
#: model:ir.ui.view,arch_db:mrp_bom_component_find.mrp_bom_component_find_wizard_form
msgid "or"
msgstr "ou"

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import product

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class ProductTemplate(models.Model):
_inherit = "product.template"
@api.multi
def use_case_action(self):
for obj in self:
products = self.env['product.product'].search([
('product_tmpl_id', '=', obj.id)
])
for product in products:
return product.use_case_action()
class ProductProduct(models.Model):
_inherit = "product.product"
@api.multi
def use_case_action(self):
for obj in self:
vals = {
'product_id': obj.id
}
wizard = self.env['mrp.bom.component.find.wizard'].create(vals)
return wizard.do_search_component()

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="product_template_form_view_use_case_button" model="ir.ui.view">
<field name="name">product.template.procurement</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="use_case_action" type="object" string="Component find"
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-sitemap">
</button>
</div>
</field>
</record>
<record id="product_product_form_view_use_case_button" model="ir.ui.view">
<field name="name">product.product.procurement</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="use_case_action" type="object" string="Component find"
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" icon="fa-sitemap">
</button>
</div>
</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import mrp_bom_component_find_wizard

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.addons import decimal_precision as dp
class MrpBomComponentFindWizard(models.TransientModel):
_name = 'mrp.bom.component.find.wizard'
product_id = fields.Many2one('product.product', 'Component', required=True)
@api.multi
def mrp_bom_component_find(self, wizard_id, component_id, level):
cr = self._cr
cr.execute("""
select
mbl.sequence,
mbl.product_id,
mbl.product_qty,
mb.product_tmpl_id,
mb.id mb_id,
(select id from product_product
where product_tmpl_id=mb.product_tmpl_id limit 1) compose_id
from mrp_bom_line mbl inner join mrp_bom mb on mbl.bom_id=mb.id
where mbl.product_id=%s
""", (str(component_id),))
result = cr.fetchall()
for row in result:
compose_id = row[5]
level_txt = ''
for i in range(1, level):
level_txt = level_txt + u'-'
level_txt = level_txt + str(level)
vals = {
'wizard_id': wizard_id,
'level': level_txt,
'component_id': component_id,
'line': row[0],
'quantity': row[2],
'mrp_bom_id': row[4],
}
self.env['mrp.bom.component.find.line'].create(vals)
self.mrp_bom_component_find(wizard_id, compose_id, level + 1)
@api.multi
def do_search_component(self):
for obj in self:
if obj.product_id:
self.mrp_bom_component_find(obj.id, obj.product_id.id, 1)
return {
'name': "Component find %s " % obj.product_id.name,
'view_mode': 'tree,form',
'view_type': 'form',
'res_model': 'mrp.bom.component.find.line',
'type': 'ir.actions.act_window',
'domain': [('wizard_id', '=', obj.id)],
}
class MrpBomComponentFindLine(models.TransientModel):
_name = 'mrp.bom.component.find.line'
wizard_id = fields.Many2one('mrp.bom.component.find.wizard', 'Wizard')
level = fields.Char('Level')
component_id = fields.Many2one('product.product', 'Component')
line = fields.Integer('Line')
quantity = fields.Float(
'Quantity', digits=dp.get_precision('Product Unit of Measure'))
mrp_bom_id = fields.Many2one('mrp.bom', 'Product')

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="mrp_bom_component_find_wizard_form" model="ir.ui.view">
<field name="name">mrp.bom.component.find.wizard.form</field>
<field name="model">mrp.bom.component.find.wizard</field>
<field name="arch" type="xml">
<form string="Component find">
<group>
<field name="product_id"/>
<label string=""/>
</group>
<footer>
<button name="do_search_component" string="OK" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="mrp_bom_component_find_wizard_action" model="ir.actions.act_window">
<field name="name">Component find</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.bom.component.find.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="mrp_bom_component_find_wizard_form"/>
<field name="target">new</field>
</record>
<record model="ir.ui.view" id="mrp_bom_component_find_line_form_view">
<field name="name">mrp_bom_component_find_line_form_view</field>
<field name="model">mrp.bom.component.find.line</field>
<field name="arch" type="xml">
<form create="false" editable="false">
<sheet>
<group>
<field name="level" />
<field name="component_id" />
<field name="line" />
<field name="quantity" />
<field name="mrp_bom_id" />
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="mrp_bom_component_find_line_tree_view">
<field name="name">mrp_bom_component_find_line_tree_view</field>
<field name="model">mrp.bom.component.find.line</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree create="false">
<field name="level" />
<field name="component_id"/>
<field name="line" />
<field name="quantity" />
<field name="mrp_bom_id"/>
</tree>
</field>
</record>
<record id="mrp_bom_component_find_line_search_view" model="ir.ui.view">
<field name="name">mrp_bom_component_find_line_search_view</field>
<field name="model">mrp.bom.component.find.line</field>
<field name="arch" type="xml">
<search>
<field name="level" />
<field name="component_id"/>
<field name="line" />
<field name="mrp_bom_id"/>
</search>
</field>
</record>
<menuitem
id="mrp_bom_component_find_menu"
action="mrp_bom_component_find_wizard_action"
sequence="900"
name="Component find"
parent="mrp.menu_mrp_bom"
/>
</odoo>

View File

@@ -29,9 +29,10 @@ To configure this module, you need to:
standard behavior.
If you want to use the second mode, based on forecast quantity
#. Go to the warehouse you want to follow this behaviour.
#. In the view form go to the tab *Warehouse Configuration* and set the
*MRP MTO with forecast stock*. You still need to configure the products
#. In the view form go to the tab *Warehouse Configuration* and set the *MRP
MTO with forecast stock*. You still need to configure the products
like described in last step.
Usage