[14.0][ADD] mrp_production_serial_matrix

This commit is contained in:
Lois Rilo
2021-09-01 17:21:17 +02:00
parent 62dc6e1ec4
commit b995d78621
21 changed files with 1436 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
============================
MRP Production Serial Matrix
============================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/14.0/mrp_production_serial_matrix
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_production_serial_matrix
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/129/14.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module aims to ease the processing of Manufacturing Orders with the
following characteristics:
* The finished product is tracked by unique serial numbers.
* The quantity to be produced is more than one unit.
* Some of the components are tracked by serial numbers and/or lots.
**Table of contents**
.. contents::
:local:
Usage
=====
Go to a Manufacturing Order with the characteristics described above, then
proceed as follows:
#. Click on the button "Serial Numbers Matrix".
#. Fill the *Finished Product Serials Numbers*. As you fill them you will see
how the matrix below is updated.
#. Fill the matrix. The matrix is composed of one row per final serial number
and one column per component serial number or lot needed to complete the
production.
#. Click on *Validate*. You will be redirected to all the MOs generated.
Take into account the following:
* You need to attend all the warnings at the bottom before validating the
matrix. They help you to identify error in the input (duplicated serial
numbers, not enough stock...).
* Rows with no final lot are ignored. You will have a backorder MO for the
remaining quantity.
Known issues / Roadmap
======================
Currently, there are some limitations :
* Components tracked by lots will only have one column. This means that all the
quantity needed of this component to manufacture a finished product unit (
serial number) will be consuming a single lot.
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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_production_serial_matrix%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* ForgeFlow
Contributors
~~~~~~~~~~~~
* `ForgeFlow <https://www.forgeflow.com>`_:
* Lois Rilo <lois.rilo@forgeflow.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
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.
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/mrp_production_serial_matrix>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1,2 @@
from . import wizards
from . import models

View File

@@ -0,0 +1,21 @@
# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "MRP Production Serial Matrix",
"version": "14.0.1.0.0",
"category": "Manufacturing",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"depends": [
"mrp",
"web_widget_x2many_2d_matrix",
],
"data": [
"security/ir.model.access.csv",
"wizards/mrp_production_serial_matrix_view.xml",
"views/mrp_production_views.xml",
],
"installable": True,
}

View File

@@ -0,0 +1 @@
from . import mrp_production

View File

@@ -0,0 +1,14 @@
# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import fields, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
show_serial_matrix = fields.Boolean(compute="_compute_show_serial_matrix")
def _compute_show_serial_matrix(self):
for rec in self:
rec.show_serial_matrix = rec.product_id.tracking == "serial"

View File

@@ -0,0 +1,3 @@
* `ForgeFlow <https://www.forgeflow.com>`_:
* Lois Rilo <lois.rilo@forgeflow.com>

View File

@@ -0,0 +1,6 @@
This module aims to ease the processing of Manufacturing Orders with the
following characteristics:
* The finished product is tracked by unique serial numbers.
* The quantity to be produced is more than one unit.
* Some of the components are tracked by serial numbers and/or lots.

View File

@@ -0,0 +1,5 @@
Currently, there are some limitations :
* Components tracked by lots will only have one column. This means that all the
quantity needed of this component to manufacture a finished product unit (
serial number) will be consuming a single lot.

View File

@@ -0,0 +1,18 @@
Go to a Manufacturing Order with the characteristics described above, then
proceed as follows:
#. Click on the button "Serial Numbers Matrix".
#. Fill the *Finished Product Serials Numbers*. As you fill them you will see
how the matrix below is updated.
#. Fill the matrix. The matrix is composed of one row per final serial number
and one column per component serial number or lot needed to complete the
production.
#. Click on *Validate*. You will be redirected to all the MOs generated.
Take into account the following:
* You need to attend all the warnings at the bottom before validating the
matrix. They help you to identify error in the input (duplicated serial
numbers, not enough stock...).
* Rows with no final lot are ignored. You will have a backorder MO for the
remaining quantity.

View File

@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_mrp_production_serial_matrix,access mrp.production.serial.matrix,model_mrp_production_serial_matrix,base.group_user,1,1,1,1
access_mrp_production_serial_matrix_line,access mrp.production.serial.matrix.line,model_mrp_production_serial_matrix_line,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_mrp_production_serial_matrix access mrp.production.serial.matrix model_mrp_production_serial_matrix base.group_user 1 1 1 1
3 access_mrp_production_serial_matrix_line access mrp.production.serial.matrix.line model_mrp_production_serial_matrix_line base.group_user 1 1 1 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,461 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>MRP Production Serial Matrix</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="mrp-production-serial-matrix">
<h1 class="title">MRP Production Serial Matrix</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_production_serial_matrix"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_production_serial_matrix"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/129/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module aims to ease the processing of Manufacturing Orders with the
following characteristics:</p>
<ul class="simple">
<li>The finished product is tracked by unique serial numbers.</li>
<li>The quantity to be produced is more than one unit.</li>
<li>Some of the components are tracked by serial numbers and/or lots.</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>Go to a Manufacturing Order with the characteristics described above, then
proceed as follows:</p>
<ol class="arabic simple">
<li>Click on the button “Serial Numbers Matrix”.</li>
<li>Fill the <em>Finished Product Serials Numbers</em>. As you fill them you will see
how the matrix below is updated.</li>
<li>Fill the matrix. The matrix is composed of one row per final serial number
and one column per component serial number or lot needed to complete the
production.</li>
<li>Click on <em>Validate</em>. You will be redirected to all the MOs generated.</li>
</ol>
<p>Take into account the following:</p>
<ul class="simple">
<li>You need to attend all the warnings at the bottom before validating the
matrix. They help you to identify error in the input (duplicated serial
numbers, not enough stock…).</li>
<li>Rows with no final lot are ignored. You will have a backorder MO for the
remaining quantity.</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
<p>Currently, there are some limitations :</p>
<ul class="simple">
<li>Components tracked by lots will only have one column. This means that all the
quantity needed of this component to manufacture a finished product unit (
serial number) will be consuming a single lot.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_production_serial_matrix%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.forgeflow.com">ForgeFlow</a>:<ul>
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_production_serial_matrix">OCA/manufacture</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1 @@
from . import test_mrp_production_serial_matrix

View File

@@ -0,0 +1,283 @@
# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests.common import SavepointCase
class TestMrpProductionSerialMatrix(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.mo_obj = cls.env["mrp.production"]
cls.product_obj = cls.env["product.product"]
cls.lot_obj = cls.env["stock.production.lot"]
cls.quant_obj = cls.env["stock.quant"]
cls.bom_obj = cls.env["mrp.bom"]
cls.bom_line_obj = cls.env["mrp.bom.line"]
cls.move_line_obj = cls.env["stock.move.line"]
cls.wiz_obj = cls.env["mrp.production.serial.matrix"]
cls.company = cls.env.ref("base.main_company")
cls.stock_loc = cls.env.ref("stock.stock_location_stock")
# Products and lots:
cls.final_product = cls.product_obj.create(
{
"name": "Finished Product tracked by Serial Numbers",
"type": "product",
"tracking": "serial",
}
)
cls.component_1_serial = cls.product_obj.create(
{
"name": "Component 1 tracked by Serial Numbers",
"type": "product",
"tracking": "serial",
}
)
cls.serial_1_001 = cls._create_serial_number(cls.component_1_serial, "1-001")
cls.serial_1_002 = cls._create_serial_number(cls.component_1_serial, "1-002")
cls.serial_1_003 = cls._create_serial_number(cls.component_1_serial, "1-003")
cls.component_2_serial = cls.product_obj.create(
{
"name": "Component 2 tracked by Serial Numbers",
"type": "product",
"tracking": "serial",
}
)
cls.serial_2_001 = cls._create_serial_number(cls.component_2_serial, "2-001")
cls.serial_2_002 = cls._create_serial_number(cls.component_2_serial, "2-002")
cls.serial_2_003 = cls._create_serial_number(cls.component_2_serial, "2-003")
cls.serial_2_004 = cls._create_serial_number(cls.component_2_serial, "2-004")
cls.serial_2_005 = cls._create_serial_number(cls.component_2_serial, "2-005")
cls.serial_2_006 = cls._create_serial_number(cls.component_2_serial, "2-006")
cls.component_3_lot = cls.product_obj.create(
{
"name": "Component 3 tracked by Lots",
"type": "product",
"tracking": "lot",
}
)
cls.lot_3_001 = cls._create_serial_number(
cls.component_3_lot, "3-001", qty=10.0
)
cls.lot_3_002 = cls._create_serial_number(cls.component_3_lot, "3-002", qty=8.0)
cls.lot_3_003 = cls._create_serial_number(
cls.component_3_lot, "3-003", qty=12.0
)
cls.component_4_no_track = cls.product_obj.create(
{
"name": "Component 4 Not tracked",
"type": "product",
"tracking": "none",
}
)
cls.quant_obj.create(
{
"product_id": cls.component_4_no_track.id,
"location_id": cls.stock_loc.id,
"quantity": 20.0,
}
)
# BoM
cls.bom_1 = cls.bom_obj.create(
{
"product_tmpl_id": cls.final_product.product_tmpl_id.id,
"product_id": cls.final_product.id,
"product_qty": 1.0,
}
)
cls.bom_line_obj.create(
{
"bom_id": cls.bom_1.id,
"product_id": cls.component_1_serial.id,
"product_qty": 1.0,
}
)
cls.bom_line_obj.create(
{
"bom_id": cls.bom_1.id,
"product_id": cls.component_2_serial.id,
"product_qty": 2.0,
}
)
cls.bom_line_obj.create(
{
"bom_id": cls.bom_1.id,
"product_id": cls.component_3_lot.id,
"product_qty": 4.0,
}
)
cls.bom_line_obj.create(
{
"bom_id": cls.bom_1.id,
"product_id": cls.component_4_no_track.id,
"product_qty": 1.0,
}
)
@classmethod
def _create_serial_number(cls, product, name, qty=1.0):
lot = cls.lot_obj.create(
{
"product_id": product.id,
"name": name,
"company_id": cls.company.id,
}
)
if qty > 0:
cls.quant_obj.create(
{
"product_id": product.id,
"location_id": cls.stock_loc.id,
"quantity": qty,
"lot_id": lot.id,
}
)
return lot
@classmethod
def _create_mo(cls, qty):
production_form = Form(cls.mo_obj)
production_form.product_id = cls.final_product
production_form.bom_id = cls.bom_1
production_form.product_qty = qty
production_form.product_uom_id = cls.final_product.uom_id
production_1 = production_form.save()
production_1.action_confirm()
production_1.action_assign()
return production_1
@classmethod
def _find_move_lines(cls, mo, component):
return cls.move_line_obj.search(
[
("move_id.raw_material_production_id", "=", mo.id),
("product_id", "=", component.id),
]
)
def test_01_process_mo_with_matrix(self):
"""Extensive test including all the possibilities for components:
- 1 tracked by serials.
- 1 tracked by serials and needing more than one unit.
- 1 tracked by lots.
- 1 untracked.
"""
production_1 = self._create_mo(3.0)
self.assertEqual(production_1.state, "confirmed")
# Start matrix:
wizard_form = Form(
self.wiz_obj.with_context(
active_id=production_1.id, active_model="mrp.production"
)
)
expected = 3 * 4
self.assertEqual(len(wizard_form.line_ids), expected)
self.assertEqual(wizard_form.lot_selection_warning_count, 0)
serial_fp_1 = self._create_serial_number(self.final_product, "ABC101", qty=0)
serial_fp_2 = self._create_serial_number(self.final_product, "ABC102", qty=0)
wizard_form.finished_lot_ids.add(serial_fp_1)
self.assertEqual(wizard_form.lot_selection_warning_count, 1)
wizard_form.finished_lot_ids.add(serial_fp_2)
self.assertEqual(wizard_form.lot_selection_warning_count, 2)
wizard = wizard_form.save()
lines = wizard.line_ids
# Fill first row:
cell_1_1 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_1
and l.component_id == self.component_1_serial
)
cell_1_1.component_lot_id = self.serial_1_001
cell_1_2and3 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_1
and l.component_id == self.component_2_serial
)
self.assertEqual(len(cell_1_2and3), 2)
for n, cell in enumerate(cell_1_2and3):
if n == 0:
cell.component_lot_id = self.serial_2_001
elif n == 1:
cell.component_lot_id = self.serial_2_002
cell_1_4 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_1
and l.component_id == self.component_3_lot
)
cell_1_4.component_lot_id = self.lot_3_003
# Fill second row:
cell_2_1 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_2
and l.component_id == self.component_1_serial
)
# Simulate a mistake and select the same lot than before:
cell_2_1.component_lot_id = self.serial_1_001
cell_2_2and3 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_2
and l.component_id == self.component_2_serial
)
self.assertEqual(len(cell_2_2and3), 2)
for n, cell in enumerate(cell_2_2and3):
if n == 0:
cell.component_lot_id = self.serial_2_005
elif n == 1:
cell.component_lot_id = self.serial_2_004
cell_2_4 = lines.filtered(
lambda l: l.finished_lot_id == serial_fp_2
and l.component_id == self.component_3_lot
)
cell_2_4.component_lot_id = self.lot_3_002
# There should be an error:
self.assertEqual(wizard.lot_selection_warning_count, 1)
with self.assertRaises(UserError):
wizard.button_validate()
# Fix error:
cell_2_1.component_lot_id = self.serial_1_003
# Validate and check result:
wizard.button_validate()
mos = production_1.procurement_group_id.mrp_production_ids
self.assertEqual(len(mos), 3)
mo_1 = mos.filtered(lambda mo: mo.lot_producing_id == serial_fp_1)
self.assertEqual(mo_1.state, "done")
ml_c1 = self._find_move_lines(mo_1, self.component_1_serial)
self.assertEqual(ml_c1.qty_done, 1.0)
self.assertEqual(ml_c1.lot_id, self.serial_1_001)
ml_c2 = self._find_move_lines(mo_1, self.component_2_serial)
self.assertEqual(len(ml_c2), 2)
for ml in ml_c2:
self.assertEqual(ml.qty_done, 1.0)
self.assertEqual(ml_c2.mapped("lot_id"), self.serial_2_001 + self.serial_2_002)
ml_c3 = self._find_move_lines(mo_1, self.component_3_lot)
self.assertEqual(ml_c3.qty_done, 4.0)
self.assertEqual(ml_c3.lot_id, self.lot_3_003)
ml_c4 = self._find_move_lines(mo_1, self.component_4_no_track)
self.assertEqual(ml_c4.qty_done, 1.0)
self.assertFalse(ml_c4.lot_id)
mo_2 = mos.filtered(lambda mo: mo.lot_producing_id == serial_fp_2)
self.assertEqual(mo_2.state, "done")
ml_c1 = self._find_move_lines(mo_2, self.component_1_serial)
self.assertEqual(ml_c1.qty_done, 1.0)
self.assertEqual(ml_c1.lot_id, self.serial_1_003)
ml_c2 = self._find_move_lines(mo_2, self.component_2_serial)
self.assertEqual(len(ml_c2), 2)
for ml in ml_c2:
self.assertEqual(ml.qty_done, 1.0)
self.assertEqual(ml_c2.mapped("lot_id"), self.serial_2_005 + self.serial_2_004)
ml_c3 = self._find_move_lines(mo_2, self.component_3_lot)
self.assertEqual(ml_c3.qty_done, 4.0)
self.assertEqual(ml_c3.lot_id, self.lot_3_002)
ml_c4 = self._find_move_lines(mo_2, self.component_4_no_track)
self.assertEqual(ml_c4.qty_done, 1.0)
self.assertFalse(ml_c4.lot_id)
# MO holding the remaining qty
mo_3 = mos.filtered(lambda mo: not mo.lot_producing_id)
self.assertEqual(mo_3.state, "confirmed")
self.assertEqual(mo_3.product_qty, 1.0)

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="name">mrp.production.form - mrp_production_serial_matrix</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<button name="action_confirm" position="after">
<field name="show_serial_matrix" invisible="1" />
<button
name="%(mrp_production_serial_matrix.action_mrp_production_serial_matrix)d"
type="action"
class="oe_highlight"
string="Serial Numbers Matrix"
attrs="{'invisible':['|', ('show_serial_matrix', '=', False), ('state','in',('draft', 'cancel', 'done'))]}"
/>
</button>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,2 @@
from . import mrp_production_serial_matrix
from . import mrp_production_serial_matrix_line

View File

@@ -0,0 +1,344 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero
class MrpProductionSerialMatrix(models.TransientModel):
_name = "mrp.production.serial.matrix"
_description = "Mrp Production Serial Matrix"
production_id = fields.Many2one(
comodel_name="mrp.production",
string="Manufacturing Order",
readonly=True,
)
product_id = fields.Many2one(
related="production_id.product_id",
readonly=True,
)
company_id = fields.Many2one(
related="production_id.company_id",
readonly=True,
)
finished_lot_ids = fields.Many2many(
string="Finished Product Serial Numbers",
comodel_name="stock.production.lot",
domain="[('product_id', '=', product_id)]",
)
line_ids = fields.One2many(
string="Matrix Cell",
comodel_name="mrp.production.serial.matrix.line",
inverse_name="wizard_id",
)
lot_selection_warning_msg = fields.Char(compute="_compute_lot_selection_warning")
lot_selection_warning_ids = fields.Many2many(
comodel_name="stock.production.lot", compute="_compute_lot_selection_warning"
)
lot_selection_warning_count = fields.Integer(
compute="_compute_lot_selection_warning"
)
@api.depends("line_ids", "line_ids.component_lot_id")
def _compute_lot_selection_warning(self):
for rec in self:
warning_lots = self.env["stock.production.lot"]
warning_msgs = []
# Serials:
serial_lines = rec.line_ids.filtered(
lambda l: l.component_id.tracking == "serial"
)
serial_counter = {}
for sl in serial_lines:
if not sl.component_lot_id:
continue
serial_counter.setdefault(sl.component_lot_id, 0)
serial_counter[sl.component_lot_id] += 1
for lot, counter in serial_counter.items():
if counter > 1:
warning_lots += lot
warning_msgs.append(
"Serial number %s selected several times" % lot.name
)
# Lots
lot_lines = rec.line_ids.filtered(
lambda l: l.component_id.tracking == "lot"
)
lot_consumption = {}
for ll in lot_lines:
if not ll.component_lot_id:
continue
lot_consumption.setdefault(ll.component_lot_id, 0)
available_quantity = self.env["stock.quant"]._get_available_quantity(
ll.component_id,
ll.production_id.location_src_id,
lot_id=ll.component_lot_id,
)
if (
available_quantity - lot_consumption[ll.component_lot_id]
< ll.lot_qty
):
warning_lots += ll.component_lot_id
warning_msgs.append(
"Lot %s not available at the needed qty (%s/%s)"
% (ll.component_lot_id.name, available_quantity, ll.lot_qty)
)
lot_consumption[ll.component_lot_id] += ll.lot_qty
not_filled_lines = rec.line_ids.filtered(
lambda l: l.finished_lot_id and not l.component_lot_id
)
if not_filled_lines:
not_filled_finshed_lots = not_filled_lines.mapped("finished_lot_id")
warning_lots += not_filled_finshed_lots
warning_msgs.append(
"Some cells are not filled for some finished serial number (%s)"
% ", ".join(not_filled_finshed_lots.mapped("name"))
)
rec.lot_selection_warning_msg = ", ".join(warning_msgs)
rec.lot_selection_warning_ids = warning_lots
rec.lot_selection_warning_count = len(warning_lots)
@api.model
def default_get(self, fields):
res = super().default_get(fields)
production_id = self.env.context["active_id"]
active_model = self.env.context["active_model"]
if not production_id:
return res
assert active_model == "mrp.production", "Bad context propagation"
production = self.env["mrp.production"].browse(production_id)
if not production.show_serial_matrix:
raise UserError(
_("The finished product of this MO is not tracked by serial numbers.")
)
finished_lots = self.env["stock.production.lot"]
if production.lot_producing_id:
finished_lots = production.lot_producing_id
matrix_lines = self._get_matrix_lines(production, finished_lots)
res.update(
{
"line_ids": [(0, 0, x) for x in matrix_lines],
"production_id": production_id,
"finished_lot_ids": [(4, lot_id, 0) for lot_id in finished_lots.ids],
}
)
return res
def _get_matrix_lines(self, production, finished_lots):
tracked_components = []
for line in production.bom_id.bom_line_ids:
if line.product_id.tracking == "serial":
# TODO: factor if parent is not 1.
# TODO: uom.
for i in range(1, int(line.product_qty) + 1):
tracked_components.append((line.product_id, i, 1))
elif line.product_id.tracking == "lot":
tracked_components.append((line.product_id, 0, line.product_qty))
matrix_lines = []
current_lot = False
new_lot_number = 0
for _i in range(int(production.product_qty)):
if finished_lots:
current_lot = finished_lots[0]
else:
new_lot_number += 1
for component_tuple in tracked_components:
line = self._prepare_matrix_line(
component_tuple, finished_lot=current_lot, number=new_lot_number
)
matrix_lines.append(line)
if current_lot:
finished_lots -= current_lot
current_lot = False
return matrix_lines
def _prepare_matrix_line(self, component_tuple, finished_lot=None, number=None):
component, lot_no, lot_qty = component_tuple
column_name = component.display_name
if lot_no > 0:
column_name += " (%s)" % lot_no
res = {
"component_id": component.id,
"component_column_name": column_name,
"lot_qty": lot_qty,
}
if finished_lot:
if isinstance(finished_lot.id, models.NewId):
# NewId instances are not handled correctly later, this is a
# small workaround. In future versions it might not be needed.
lot_id = finished_lot.id.origin
else:
lot_id = finished_lot.id
res.update(
{
"finished_lot_id": lot_id,
"finished_lot_name": finished_lot.name,
}
)
elif isinstance(number, int):
res.update(
{
"finished_lot_name": _("(New Lot %s)") % number,
}
)
return res
@api.onchange("finished_lot_ids")
def _onchange_finished_lot_ids(self):
for rec in self:
matrix_lines = self._get_matrix_lines(
rec.production_id,
rec.finished_lot_ids,
)
rec.line_ids = False
rec.write({"line_ids": [(0, 0, x) for x in matrix_lines]})
def button_validate(self):
self.ensure_one()
if self.lot_selection_warning_count > 0:
raise UserError(
_("Some issues has been detected in your selection: %s")
% self.lot_selection_warning_msg
)
mos = self.env["mrp.production"]
current_mo = self.production_id
for fp_lot in self.finished_lot_ids:
# Apply selected lots in matrix and set the qty producing
current_mo.lot_producing_id = fp_lot
current_mo.qty_producing = 1.0
current_mo._set_qty_producing()
for move in current_mo.move_raw_ids:
if move.product_id.tracking in ["serial", "lot"]:
# We filter using the lot nane because the ORM sometimes
# is not storing correctly the finished_lot_id in the lines
# after passing through the `_onchange_finished_lot_ids`
# method.
matrix_lines = self.line_ids.filtered(
lambda l: (
l.finished_lot_id == fp_lot
or l.finished_lot_name == fp_lot.name
)
and l.component_id == move.product_id
)
if matrix_lines:
self._amend_reservations(move, matrix_lines)
self._consume_selected_lots(move, matrix_lines)
# Complete MO and create backorder if needed.
mos += current_mo
res = current_mo.button_mark_done()
backorder_wizard = self.env["mrp.production.backorder"]
if isinstance(res, dict) and res.get("res_model") == backorder_wizard._name:
# create backorders...
lines = res.get("context", {}).get(
"default_mrp_production_backorder_line_ids"
)
wizard = backorder_wizard.create(
{
"mrp_production_ids": current_mo.ids,
"mrp_production_backorder_line_ids": lines,
}
)
wizard.action_backorder()
backorder_ids = (
current_mo.procurement_group_id.mrp_production_ids.filtered(
lambda mo: mo.state not in ["done", "cancel"]
)
)
current_mo = backorder_ids[0] if backorder_ids else False
if not current_mo:
break
else:
break
# TODO: not specified lots: auto create lots?
if not mos:
mos = self.production_id
res = {
"domain": [("id", "in", mos.ids)],
"name": _("Manufacturing Orders"),
"src_model": "mrp.production.serial.matrix",
"view_type": "form",
"view_mode": "tree,form",
"view_id": False,
"views": False,
"res_model": "mrp.production",
"type": "ir.actions.act_window",
}
return res
def _amend_reservations(self, move, matrix_lines):
lots_to_consume = matrix_lines.mapped("component_lot_id")
lots_in_move = move.move_line_ids.mapped("lot_id")
lots_to_reserve = lots_to_consume - lots_in_move
if lots_to_reserve:
to_unreserve_lots = lots_in_move - lots_to_consume
move.move_line_ids.filtered(
lambda l: l.lot_id in to_unreserve_lots
).unlink()
for lot in lots_to_reserve:
if move.product_id.tracking == "lot":
qty = sum(
matrix_lines.filtered(
lambda l: l.component_lot_id == lot
).mapped("lot_qty")
)
qty = qty
else:
qty = 1.0
self._reserve_lot_in_move(move, lot, qty=qty)
return True
def _consume_selected_lots(self, move, matrix_lines):
lots_to_consume = matrix_lines.mapped("component_lot_id")
precision_digits = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for ml in move.move_line_ids:
if ml.lot_id in lots_to_consume:
if move.product_id.tracking == "lot":
qty = sum(
matrix_lines.filtered(
lambda l: l.component_lot_id == ml.lot_id
).mapped("lot_qty")
)
ml.qty_done = qty
else:
ml.qty_done = ml.product_qty
elif float_is_zero(ml.product_qty, precision_digits=precision_digits):
ml.unlink()
else:
ml.qty_done = 0.0
def _reserve_lot_in_move(self, move, lot, qty):
precision_digits = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
available_quantity = self.env["stock.quant"]._get_available_quantity(
move.product_id,
move.location_id,
lot_id=lot,
)
if (
float_compare(available_quantity, 0.0, precision_digits=precision_digits)
<= 0
):
raise ValidationError(
_("Serial/Lot number '%s' not available at source location.") % lot.name
)
move._update_reserved_quantity(
qty,
available_quantity,
move.location_id,
lot_id=lot,
strict=True,
)

View File

@@ -0,0 +1,38 @@
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class MrpProductionSerialMatrix(models.TransientModel):
_name = "mrp.production.serial.matrix.line"
_description = "Mrp Production Serial Matrix Line"
wizard_id = fields.Many2one(
comodel_name="mrp.production.serial.matrix",
)
production_id = fields.Many2one(related="wizard_id.production_id")
component_id = fields.Many2one(comodel_name="product.product")
component_column_name = fields.Char()
finished_lot_id = fields.Many2one(comodel_name="stock.production.lot")
finished_lot_name = fields.Char()
component_lot_id = fields.Many2one(
comodel_name="stock.production.lot",
domain="[('id', 'in', allowed_component_lot_ids)]",
)
allowed_component_lot_ids = fields.Many2many(
comodel_name="stock.production.lot",
compute="_compute_allowed_component_lot_ids",
)
lot_qty = fields.Float(digits="Product Unit of Measure")
def _compute_allowed_component_lot_ids(self):
for rec in self:
available_quants = self.env["stock.quant"].search(
[
("location_id", "child_of", rec.production_id.location_src_id.id),
("product_id", "=", rec.component_id.id),
("quantity", ">", 0),
]
)
rec.allowed_component_lot_ids = available_quants.mapped("lot_id")

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" ?>
<odoo>
<record id="mrp_production_serial_matrix_view_form" model="ir.ui.view">
<field name="name">mrp.production.serial.matrix.form</field>
<field name="model">mrp.production.serial.matrix</field>
<field name="arch" type="xml">
<form>
<group name="info">
<field name="production_id" options='{"no_open": True}' />
<field name="product_id" options='{"no_open": True}' />
<field
name="company_id"
options='{"no_open": True}'
invisible="1"
/>
</group>
<group name="finished_lots" string="Finished Product Serial Numbers">
<p
class="oe_grey"
colspan="2"
>Select the Serial Numbers of the Finished Products that are going to be produced in this MO. You can create new ones on the fly if needed.</p>
<br />
<field
name="finished_lot_ids"
widget="many2many_tags"
context="{'default_product_id': product_id, 'default_company_id': company_id}"
/>
</group>
<group
name="serial_matrix"
string="Components Lot/Serial Numbers Matrix"
>
<p
class="oe_grey"
colspan="2"
>Fill each cell with the lot/serial number consumed to produce each finished product serial number</p>
<br />
<field
name="line_ids"
nolabel="1"
widget="x2many_2d_matrix"
field_x_axis="component_column_name"
field_y_axis="finished_lot_name"
field_value="component_lot_id"
colspan="2"
>
<tree editable="True" nolabel="1" create="false">
<field name="component_column_name" />
<field name="finished_lot_name" />
<field
name="component_lot_id"
options='{"no_create": True}'
/>
<field name="component_id" invisible="1" />
<field name="lot_qty" invisible="1" />
<field name="finished_lot_id" invisible="1" />
<field name="allowed_component_lot_ids" invisible="1" />
</tree>
</field>
<div
class="alert alert-warning text-center"
role="alert"
attrs="{'invisible': [('lot_selection_warning_count', '=', 0)]}"
style="margin-bottom:0px;"
>
<p><i
class="fa fa-info-circle"
/> Some issues has been detected in your selection:
<br />
<field name="lot_selection_warning_msg" nolabel="1" />
<field name="lot_selection_warning_count" invisible="1" />
</p>
</div>
</group>
<footer>
<button
name="button_validate"
string="Validate"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_mrp_production_serial_matrix" model="ir.actions.act_window">
<field name="name">Serial Numbers and Lot Consumption Matrix</field>
<field name="res_model">mrp.production.serial.matrix</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>