mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] mrp_bom_tracking
This commit is contained in:
committed by
Joan Sisquella
parent
22a45ae07a
commit
3c44e64ec0
53
mrp_bom_tracking/README.rst
Normal file
53
mrp_bom_tracking/README.rst
Normal file
@@ -0,0 +1,53 @@
|
||||
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
|
||||
:target: https://www.gnu.org/licenses/lgpl
|
||||
:alt: License: LGPL-3
|
||||
|
||||
================
|
||||
MRP BoM Tracking
|
||||
================
|
||||
|
||||
This module adds track visibility to some fields of mrp boms. Also,
|
||||
it log notes for any change in the bom lines (components).
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. 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/11.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/manufacture/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
|
||||
------------
|
||||
|
||||
* Miquel Raïch <miquel.raich@eficent.com>
|
||||
|
||||
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.
|
||||
3
mrp_bom_tracking/__init__.py
Normal file
3
mrp_bom_tracking/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from . import models
|
||||
19
mrp_bom_tracking/__manifest__.py
Normal file
19
mrp_bom_tracking/__manifest__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
|
||||
{
|
||||
"name": "MRP BoM Tracking",
|
||||
"version": "11.0.1.0.0",
|
||||
"author": "Eficent, Odoo Community Association (OCA)",
|
||||
"summary": "Add track visibility to some fields of mrp boms.",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"category": "Manufacturing",
|
||||
"depends": [
|
||||
"mrp",
|
||||
],
|
||||
"data": [
|
||||
"views/bom_template.xml",
|
||||
],
|
||||
"license": "LGPL-3",
|
||||
'installable': True,
|
||||
}
|
||||
3
mrp_bom_tracking/models/__init__.py
Normal file
3
mrp_bom_tracking/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from . import mrp_bom
|
||||
104
mrp_bom_tracking/models/mrp_bom.py
Normal file
104
mrp_bom_tracking/models/mrp_bom.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = "mrp.bom"
|
||||
|
||||
code = fields.Char(
|
||||
track_visibility="onchange",
|
||||
)
|
||||
product_tmpl_id = fields.Many2one(
|
||||
track_visibility="always",
|
||||
)
|
||||
product_qty = fields.Float(
|
||||
track_visibility="onchange",
|
||||
)
|
||||
picking_type_id = fields.Many2one(
|
||||
track_visibility="onchange",
|
||||
)
|
||||
type = fields.Selection(
|
||||
track_visibility="onchange",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
bom_line_ids = {}
|
||||
if 'bom_line_ids' in values:
|
||||
for bom in self:
|
||||
del_lines = []
|
||||
for line in values['bom_line_ids']:
|
||||
if line[0] == 2:
|
||||
del_lines.append(line[1])
|
||||
if del_lines:
|
||||
bom.message_post_with_view(
|
||||
'mrp_bom_tracking.track_bom_template',
|
||||
values={
|
||||
'lines': self.env["mrp.bom.line"].browse(
|
||||
del_lines),
|
||||
'mode': 'Removed',
|
||||
},
|
||||
subtype_id=self.env.ref('mail.mt_note').id,
|
||||
)
|
||||
bom_line_ids[bom.id] = bom.bom_line_ids
|
||||
res = super(MrpBom, self).write(values)
|
||||
if 'bom_line_ids' in values:
|
||||
for bom in self:
|
||||
new_lines = bom.bom_line_ids - bom_line_ids[bom.id]
|
||||
if new_lines:
|
||||
bom.message_post_with_view(
|
||||
'mrp_bom_tracking.track_bom_template',
|
||||
values={
|
||||
'lines': new_lines,
|
||||
'mode': 'New',
|
||||
},
|
||||
subtype_id=self.env.ref('mail.mt_note').id,
|
||||
)
|
||||
return res
|
||||
|
||||
|
||||
class MrpBomLine(models.Model):
|
||||
_inherit = "mrp.bom.line"
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
if 'product_id' in values:
|
||||
for bom in self.mapped('bom_id'):
|
||||
lines = self.filtered(lambda l: l.bom_id == bom)
|
||||
product_id = values.get('product_id')
|
||||
if product_id:
|
||||
product_id = self.env["product.product"].browse(
|
||||
product_id)
|
||||
product_id = product_id or lines.product_id
|
||||
if lines:
|
||||
bom.message_post_with_view(
|
||||
'mrp_bom_tracking.track_bom_template_2',
|
||||
values={
|
||||
'lines': lines,
|
||||
'product_id': product_id,
|
||||
},
|
||||
subtype_id=self.env.ref('mail.mt_note').id,
|
||||
)
|
||||
elif 'product_qty' in values or 'product_uom_id' in values:
|
||||
for bom in self.mapped('bom_id'):
|
||||
lines = self.filtered(lambda l: l.bom_id == bom)
|
||||
if lines:
|
||||
product_qty = values.get(
|
||||
'product_qty') or lines.product_qty
|
||||
product_uom_id = values.get('product_uom_id')
|
||||
if product_uom_id:
|
||||
product_uom_id = self.env["product.uom"].browse(
|
||||
product_uom_id)
|
||||
product_uom_id = product_uom_id or lines.product_uom_id
|
||||
bom.message_post_with_view(
|
||||
'mrp_bom_tracking.track_bom_line_template',
|
||||
values={
|
||||
'lines': lines,
|
||||
'product_qty': product_qty,
|
||||
'product_uom_id': product_uom_id,
|
||||
},
|
||||
subtype_id=self.env.ref('mail.mt_note').id,
|
||||
)
|
||||
return super(MrpBomLine, self).write(values)
|
||||
1
mrp_bom_tracking/readme/CONTRIBUTORS.rst
Normal file
1
mrp_bom_tracking/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
||||
* Miquel Raïch <miquel.raich@eficent.com>
|
||||
2
mrp_bom_tracking/readme/DESCRIPTION.rst
Normal file
2
mrp_bom_tracking/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
This module adds track visibility to some fields of mrp boms. Also,
|
||||
it log notes for any change in the bom lines (components).
|
||||
44
mrp_bom_tracking/views/bom_template.xml
Normal file
44
mrp_bom_tracking/views/bom_template.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). -->
|
||||
|
||||
<odoo>
|
||||
<template id="track_bom_line_template">
|
||||
<div>
|
||||
<strong>The component quantities or UoMs have been updated.</strong>
|
||||
<ul>
|
||||
<t t-foreach="lines" t-as="line">
|
||||
<li><t t-esc="line.product_id.display_name"/>:</li>
|
||||
Product Quantity: <t t-esc="line.product_qty" /><t t-if='line.product_qty != product_qty'> -> <t t-esc="float(product_qty)"/></t><br/>
|
||||
Product Unit of Measure: <t t-esc="line.product_uom_id.display_name" /><t t-if='line.product_uom_id != product_uom_id'> -> <t t-esc="product_uom_id.display_name"/></t><br/>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="track_bom_template">
|
||||
<div>
|
||||
<strong>The components have changed.</strong>
|
||||
<ul>
|
||||
<t t-foreach="lines" t-as="line">
|
||||
<li><t t-esc="line.product_id.display_name"/>:
|
||||
<t t-esc="mode"/> component<br/></li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="track_bom_template_2">
|
||||
<div>
|
||||
<strong>The components have changed.</strong>
|
||||
<ul>
|
||||
<t t-foreach="lines" t-as="line">
|
||||
<li><t t-esc="line.product_id.display_name"/>:
|
||||
Removed component<br/></li>
|
||||
<li><t t-esc="product_id.display_name"/>:
|
||||
New component<br/></li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user