From b995d78621d89db8bf1185a25bf92d8b397b6826 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 1 Sep 2021 17:21:17 +0200 Subject: [PATCH] [14.0][ADD] mrp_production_serial_matrix --- mrp_production_serial_matrix/README.rst | 111 +++++ mrp_production_serial_matrix/__init__.py | 2 + mrp_production_serial_matrix/__manifest__.py | 21 + .../models/__init__.py | 1 + .../models/mrp_production.py | 14 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 6 + .../readme/ROADMAP.rst | 5 + mrp_production_serial_matrix/readme/USAGE.rst | 18 + .../security/ir.model.access.csv | 3 + .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 461 ++++++++++++++++++ .../tests/__init__.py | 1 + .../test_mrp_production_serial_matrix.py | 283 +++++++++++ .../views/mrp_production_views.xml | 20 + .../wizards/__init__.py | 2 + .../wizards/mrp_production_serial_matrix.py | 344 +++++++++++++ .../mrp_production_serial_matrix_line.py | 38 ++ .../mrp_production_serial_matrix_view.xml | 96 ++++ .../odoo/addons/mrp_production_serial_matrix | 1 + setup/mrp_production_serial_matrix/setup.py | 6 + 21 files changed, 1436 insertions(+) create mode 100644 mrp_production_serial_matrix/README.rst create mode 100644 mrp_production_serial_matrix/__init__.py create mode 100644 mrp_production_serial_matrix/__manifest__.py create mode 100644 mrp_production_serial_matrix/models/__init__.py create mode 100644 mrp_production_serial_matrix/models/mrp_production.py create mode 100644 mrp_production_serial_matrix/readme/CONTRIBUTORS.rst create mode 100644 mrp_production_serial_matrix/readme/DESCRIPTION.rst create mode 100644 mrp_production_serial_matrix/readme/ROADMAP.rst create mode 100644 mrp_production_serial_matrix/readme/USAGE.rst create mode 100644 mrp_production_serial_matrix/security/ir.model.access.csv create mode 100644 mrp_production_serial_matrix/static/description/icon.png create mode 100644 mrp_production_serial_matrix/static/description/index.html create mode 100644 mrp_production_serial_matrix/tests/__init__.py create mode 100644 mrp_production_serial_matrix/tests/test_mrp_production_serial_matrix.py create mode 100644 mrp_production_serial_matrix/views/mrp_production_views.xml create mode 100644 mrp_production_serial_matrix/wizards/__init__.py create mode 100644 mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py create mode 100644 mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py create mode 100644 mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_view.xml create mode 120000 setup/mrp_production_serial_matrix/odoo/addons/mrp_production_serial_matrix create mode 100644 setup/mrp_production_serial_matrix/setup.py diff --git a/mrp_production_serial_matrix/README.rst b/mrp_production_serial_matrix/README.rst new file mode 100644 index 000000000..b00422bfa --- /dev/null +++ b/mrp_production_serial_matrix/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow `_: + + * Lois Rilo + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_production_serial_matrix/__init__.py b/mrp_production_serial_matrix/__init__.py new file mode 100644 index 000000000..976591c99 --- /dev/null +++ b/mrp_production_serial_matrix/__init__.py @@ -0,0 +1,2 @@ +from . import wizards +from . import models diff --git a/mrp_production_serial_matrix/__manifest__.py b/mrp_production_serial_matrix/__manifest__.py new file mode 100644 index 000000000..4af7d9481 --- /dev/null +++ b/mrp_production_serial_matrix/__manifest__.py @@ -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, +} diff --git a/mrp_production_serial_matrix/models/__init__.py b/mrp_production_serial_matrix/models/__init__.py new file mode 100644 index 000000000..a9e5f13e4 --- /dev/null +++ b/mrp_production_serial_matrix/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_production diff --git a/mrp_production_serial_matrix/models/mrp_production.py b/mrp_production_serial_matrix/models/mrp_production.py new file mode 100644 index 000000000..2a2d38cee --- /dev/null +++ b/mrp_production_serial_matrix/models/mrp_production.py @@ -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" diff --git a/mrp_production_serial_matrix/readme/CONTRIBUTORS.rst b/mrp_production_serial_matrix/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..1a927bdc4 --- /dev/null +++ b/mrp_production_serial_matrix/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `_: + + * Lois Rilo diff --git a/mrp_production_serial_matrix/readme/DESCRIPTION.rst b/mrp_production_serial_matrix/readme/DESCRIPTION.rst new file mode 100644 index 000000000..4d223a1a6 --- /dev/null +++ b/mrp_production_serial_matrix/readme/DESCRIPTION.rst @@ -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. diff --git a/mrp_production_serial_matrix/readme/ROADMAP.rst b/mrp_production_serial_matrix/readme/ROADMAP.rst new file mode 100644 index 000000000..267a3befc --- /dev/null +++ b/mrp_production_serial_matrix/readme/ROADMAP.rst @@ -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. diff --git a/mrp_production_serial_matrix/readme/USAGE.rst b/mrp_production_serial_matrix/readme/USAGE.rst new file mode 100644 index 000000000..9c1f5e853 --- /dev/null +++ b/mrp_production_serial_matrix/readme/USAGE.rst @@ -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. diff --git a/mrp_production_serial_matrix/security/ir.model.access.csv b/mrp_production_serial_matrix/security/ir.model.access.csv new file mode 100644 index 000000000..267d70ea5 --- /dev/null +++ b/mrp_production_serial_matrix/security/ir.model.access.csv @@ -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 diff --git a/mrp_production_serial_matrix/static/description/icon.png b/mrp_production_serial_matrix/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)( z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~AW`Yue4kFa^LM3X`8x|}ZUeMnqr}>kH zG%WWW>3ml$Yez?i%)2pbKPI7?5o?hydokgQyZsNEr{a|mLdt;X2TX(#B1j35xPnPW z*bMSSOauW>o;*=kO8ojw91VX!qoOQb)zHJ!odWB}d+*K?#sY_jqPdg{Sm2HdYzdEx zOGVPhVRTGPtv0o}RfVP;Nd(|CB)I;*t&QO8h zFfekr30S!-LHmV_Su-W+rEwYXJ^;6&3|L$mMC8*bQptyOo9;>Qb9Q9`ySe3%V$A*9 zeKEe+b0{#KWGp$F+tga)0RtI)nhMa-K@JS}2krK~n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/mrp_production_serial_matrix/static/description/index.html new file mode 100644 index 000000000..f7876d1e0 --- /dev/null +++ b/mrp_production_serial_matrix/static/description/index.html @@ -0,0 +1,461 @@ + + + + + + +MRP Production Serial Matrix + + + +
+

MRP Production Serial Matrix

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runbot

+

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

+ +
+

Usage

+

Go to a Manufacturing Order with the characteristics described above, then +proceed as follows:

+
    +
  1. Click on the button “Serial Numbers Matrix”.
  2. +
  3. Fill the Finished Product Serials Numbers. As you fill them you will see +how the matrix below is updated.
  4. +
  5. 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.
  6. +
  7. Click on Validate. You will be redirected to all the MOs generated.
  8. +
+

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. +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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mrp_production_serial_matrix/tests/__init__.py b/mrp_production_serial_matrix/tests/__init__.py new file mode 100644 index 000000000..50ad4dea5 --- /dev/null +++ b/mrp_production_serial_matrix/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_production_serial_matrix diff --git a/mrp_production_serial_matrix/tests/test_mrp_production_serial_matrix.py b/mrp_production_serial_matrix/tests/test_mrp_production_serial_matrix.py new file mode 100644 index 000000000..89738b4dc --- /dev/null +++ b/mrp_production_serial_matrix/tests/test_mrp_production_serial_matrix.py @@ -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) diff --git a/mrp_production_serial_matrix/views/mrp_production_views.xml b/mrp_production_serial_matrix/views/mrp_production_views.xml new file mode 100644 index 000000000..6e51c6a43 --- /dev/null +++ b/mrp_production_serial_matrix/views/mrp_production_views.xml @@ -0,0 +1,20 @@ + + + + mrp.production.form - mrp_production_serial_matrix + mrp.production + + + + + + diff --git a/mrp_production_serial_matrix/wizards/__init__.py b/mrp_production_serial_matrix/wizards/__init__.py new file mode 100644 index 000000000..24a607e4a --- /dev/null +++ b/mrp_production_serial_matrix/wizards/__init__.py @@ -0,0 +1,2 @@ +from . import mrp_production_serial_matrix +from . import mrp_production_serial_matrix_line diff --git a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py new file mode 100644 index 000000000..7d1fb2e9b --- /dev/null +++ b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py @@ -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, + ) diff --git a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py new file mode 100644 index 000000000..54cc15245 --- /dev/null +++ b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py @@ -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") diff --git a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_view.xml b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_view.xml new file mode 100644 index 000000000..313ac0dc7 --- /dev/null +++ b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_view.xml @@ -0,0 +1,96 @@ + + + + mrp.production.serial.matrix.form + mrp.production.serial.matrix + +
+ + + + + + +

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.

+
+ +
+ +

Fill each cell with the lot/serial number consumed to produce each finished product serial number

+
+ + + + + + + + + + + + +
+
+
+ +
+
+ + + Serial Numbers and Lot Consumption Matrix + mrp.production.serial.matrix + ir.actions.act_window + form + new + + +
diff --git a/setup/mrp_production_serial_matrix/odoo/addons/mrp_production_serial_matrix b/setup/mrp_production_serial_matrix/odoo/addons/mrp_production_serial_matrix new file mode 120000 index 000000000..e55bec17f --- /dev/null +++ b/setup/mrp_production_serial_matrix/odoo/addons/mrp_production_serial_matrix @@ -0,0 +1 @@ +../../../../mrp_production_serial_matrix \ No newline at end of file diff --git a/setup/mrp_production_serial_matrix/setup.py b/setup/mrp_production_serial_matrix/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_production_serial_matrix/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)