Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions mrp_production_bom_create/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Mrp create bom from production
!! source digest: sha256:1967022c5265c66430f0bdcbde4db2625631a8555c0f2f67d5e0afb76eb32642
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
Expand All @@ -28,6 +28,11 @@ Mrp create bom from production

This module add a button to production to create a BOM from consumed products.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
Expand Down
8 changes: 7 additions & 1 deletion mrp_production_bom_create/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,14 @@ <h1>Mrp create bom from production</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1967022c5265c66430f0bdcbde4db2625631a8555c0f2f67d5e0afb76eb32642
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/efatto/e-efatto/tree/14.0/mrp_production_bom_create"><img alt="efatto/e-efatto" src="https://img.shields.io/badge/github-efatto%2Fe--efatto-lightgray.png?logo=github" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/efatto/e-efatto/tree/14.0/mrp_production_bom_create"><img alt="efatto/e-efatto" src="https://img.shields.io/badge/github-efatto%2Fe--efatto-lightgray.png?logo=github" /></a></p>
<p>This module add a button to production to create a BOM from consumed products.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
</div>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down
74 changes: 74 additions & 0 deletions mrp_production_lot_custom_assign/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

================================
MRP Production Lot Custom Assign
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ba91ee9d172cce966e128a2e62c88ccf88539477ed3c6d2a053ff9f3ba659bfa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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-efatto%2Fe--efatto-lightgray.png?logo=github
:target: https://github.com/efatto/e-efatto/tree/14.0/mrp_production_lot_custom_assign
:alt: efatto/e-efatto

|badge1| |badge2| |badge3|

This module automate user selected lot assignment to workorders from production.

**Table of contents**

.. contents::
:local:

Configuration
=============

Questo modulo forza la creazione delle righe dei prodotti finiti alla creazione della produzione:

.. image:: https://raw.githubusercontent.com/efatto/e-efatto/14.0/mrp_production_lot_custom_assign/static/description/righe.png
:alt: Righe prodotti finiti

In questo modo, sbloccando la produzione, è possibile già assegnare i lotti/seriali, che verranno imputati in automatico negli ordini di lavorazione (se non inseriti manualmente).

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/efatto/e-efatto/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/efatto/e-efatto/issues/new?body=module:%20mrp_production_lot_custom_assign%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
~~~~~~~

* Sergio Corato

Contributors
~~~~~~~~~~~~

* Sergio Corato <https://github.com/sergiocorato>

Maintainers
~~~~~~~~~~~

This module is part of the `efatto/e-efatto <https://github.com/efatto/e-efatto/tree/14.0/mrp_production_lot_custom_assign>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions mrp_production_lot_custom_assign/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions mrp_production_lot_custom_assign/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "MRP Production Lot Custom Assign",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"license": "AGPL-3",
"category": "Manufacturing",
"author": "Sergio Corato",
"website": "https://github.com/efatto/e-efatto",
"summary": "Enable selection of lot in production for auto-assignment on "
"workorders.",
"depends": [
"mrp_production_demo",
"mrp_routing",
],
"data": [],
"installable": True,
}
46 changes: 46 additions & 0 deletions mrp_production_lot_custom_assign/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_production_lot_custom_assign
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-09 09:06+0000\n"
"PO-Revision-Date: 2022-05-09 09:06+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mrp_production_lot_custom_assign
#: code:addons/mrp_production_lot_custom_assign/models/mrp_workorder.py:23
#, python-format
msgid "Final lot not in expected lots %s!"
msgstr "Il lotto finale non è nei lotti attesi %s!"

#. module: mrp_production_lot_custom_assign
#: code:addons/mrp_production_lot_custom_assign/models/mrp_production.py:29
#, python-format
msgid "Missing final lot/serial number in finished product!\n"
"(tip: unlock manufacturing order, set lots and lock to continue)"
msgstr "Lotto/seriale mancante nei prodotti finiti!\n"
"(tip: sbloccare la produzione, impostare i lotti e ribloccare per continuare)"

#. module: mrp_production_lot_custom_assign
#: model:ir.model,name:mrp_production_lot_custom_assign.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Movimenti prodotto (riga movimento magazzino)"

#. module: mrp_production_lot_custom_assign
#: model:ir.model,name:mrp_production_lot_custom_assign.model_mrp_production
msgid "Production Order"
msgstr "Ordine di Produzione"

#. module: mrp_production_lot_custom_assign
#: model:ir.model,name:mrp_production_lot_custom_assign.model_mrp_workorder
msgid "Work Order"
msgstr "Ordine di Lavoro"

3 changes: 3 additions & 0 deletions mrp_production_lot_custom_assign/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mrp_production
from . import mrp_workorder
from . import stock_move_line
52 changes: 52 additions & 0 deletions mrp_production_lot_custom_assign/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2020 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import UserError


class MrpProduction(models.Model):
_inherit = "mrp.production"

@api.model
def create(self, values):
production = super().create(values)
if production.bom_id.routing_id and production.product_id.tracking != "none":
# force qty change to create finished product rows to let user assign lots
self.env["change.production.qty"].create(
{
"mo_id": production.id,
"product_qty": production.product_qty,
}
).change_prod_qty()
return production

def button_plan(self):
orders_to_plan = self.filtered(
lambda mo: mo.bom_id.routing_id and mo.state == "confirmed"
)
for order in orders_to_plan:
if order.product_id.tracking != "none" and not order.mapped(
"finished_move_line_ids.lot_id"
):
raise UserError(
_(
"Missing final lot/serial number in finished product!\n"
"(tip: unlock manufacturing order, set lots and lock to continue)"
)
)
res = super().button_plan()
for order in orders_to_plan:
# assign first lot to final workorder
# serial will be assigned recording production
if (
order.product_id.tracking != "none"
and order.finished_move_line_ids[0].lot_id
):
lot = order.finished_move_line_ids[0].lot_id
order.workorder_ids.filtered(lambda x: not x.next_work_order_id).write(
{
"finished_lot_id": lot.id,
}
)
return res
39 changes: 39 additions & 0 deletions mrp_production_lot_custom_assign/models/mrp_workorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from odoo import _, models
from odoo.exceptions import UserError


class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

def button_done(self):
if not self:
return True
self.ensure_one()
finished_lot_id = self.finished_lot_id
if not self.next_work_order_id:
expected_final_lots = self.production_id.mapped(
"finished_move_line_ids.lot_id"
)
if expected_final_lots and finished_lot_id not in expected_final_lots:
raise UserError(
_(
"Final lot not in expected lots %s!"
% expected_final_lots.mapped("name")
)
)
res = super().button_done()
if (
finished_lot_id
and self.production_id.product_id.tracking != "none"
and self.state != "done"
and not self.next_work_order_id
):
# set the next lot to workorders for lot or serial tracking
lots = self.production_id.mapped("finished_move_line_ids.lot_id")
used_lots = self.production_id.mapped("move_raw_ids.move_line_ids.lot_id")
available_lots = lots - (finished_lot_id + used_lots)
if available_lots:
# override only if not in available lots
if self.finished_lot_id not in available_lots:
self.finished_lot_id = available_lots[0]
return res
41 changes: 41 additions & 0 deletions mrp_production_lot_custom_assign/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2022 Sergio Corato <https://github.com/sergiocorato>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

@api.onchange("lot_name", "lot_id")
def _onchange_serial_number(self):
res = super()._onchange_serial_number()
if self.product_id.tracking == "serial":
if isinstance(self.id, models.NewId):
move_id = self._origin.move_id
else:
move_id = self.move_id
if move_id.production_id:
# remove switch to 1 for serial product to avoid duplication in
# the manufacturing process
self.qty_done = 0
return res

@api.onchange("product_id", "product_uom_id")
def _onchange_product_id(self):
res = super()._onchange_product_id()
# FIXME I don't understand the note below
# this is needed as stock move in NewId, as is stock move line, so it is
# impossible to retrieve lot ids from this recursive NewId
if self._context.get("default_production_id", False):
production = self.env["mrp.production"].browse(
self._context["default_production_id"]
)
lots = production.move_finished_ids.mapped("move_line_ids.lot_id")
if lots:
res["domain"].update(
{
"lot_produced_id": [("id", "in", lots.ids)],
}
)
return res
6 changes: 6 additions & 0 deletions mrp_production_lot_custom_assign/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Questo modulo forza la creazione delle righe dei prodotti finiti alla creazione della produzione:

.. image:: ../static/description/righe.png
:alt: Righe prodotti finiti

In questo modo, sbloccando la produzione, è possibile già assegnare i lotti/seriali, che verranno imputati in automatico negli ordini di lavorazione (se non inseriti manualmente).
1 change: 1 addition & 0 deletions mrp_production_lot_custom_assign/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sergio Corato <https://github.com/sergiocorato>
1 change: 1 addition & 0 deletions mrp_production_lot_custom_assign/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module automate user selected lot assignment to workorders from production.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading