Skip to content

Commit

Permalink
[17.0][ADD] sale_product_approval_mrp
Browse files Browse the repository at this point in the history
Depends on PR OCA#3108
  • Loading branch information
Patrick Wilson committed Sep 19, 2024
1 parent 0ad838f commit 8fd1d50
Show file tree
Hide file tree
Showing 20 changed files with 1,165 additions and 0 deletions.
128 changes: 128 additions & 0 deletions sale_product_approval_mrp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
===============================
Manufacturing Approval Workflow
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bdf3dfa4897efbfca5919619134f13978e68bb4a216a462c4d5adda8e3e6c84b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/17.0/sale_product_approval_mrp
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_product_approval_mrp
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the manufacturing related settings to products and the
product states then control whether or not the product can be
manufactured, a component of a manufacturing order or on a bom in the
particular state.

.. 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::
:local:

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

- The product states are configured to allow/block workflows for the
manufacturing processes.
- The product is configured via check boxes.
- The 'Can be' check boxes are readonly and controlled by the state
configuration boxes and set accordingly based on the product state
settings.

Usage
=====

- A User will not be able to manually add a product that is not in an
approved state for manufacturing to the MO. If a product is moved to
a state where the 'Approved to be Manufactured' is not set, then the
manufacturing order will show an exception: Same for if a product is
moved to a state where the 'Approved to be a Component on a
Manufacturing Order' is not set, then the manufacturing order will
show an exception In both of the above cases, if a user tries clicks
either the 'Confirm' or 'Mark as Done' buttons, then a warning shows
informing the user that there is an exception.
- For Work Orders on a Manufacturing Order which has an exception, if
the user clicks either the 'Start' or 'Done' buttons, a warning shows
information the user that there is an exception on the manufacturing
order.
- For Bill of Materials, same logic applies as above so if a product
that is on a BoM. If an existing product on a BoM is moved to a
non-approved state then the BoM will show the exceptions. A User will
not be able to manually add a product that is not in an approved
state for manufacturing to the BoM.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/OCA/sale-workflow/issues/new?body=module:%20sale_product_approval_mrp%0Aversion:%2017.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
-------

* Open Source Integrators

Contributors
------------

- `Open Source Integrators <https://opensourceintegrators.com>`__.

- Chandresh Thakkar <cthakkar@opensourceintegrators.com>
- Daniel Reis <dreis@opensourceintegrators.com>
- Patrick Wilson <pwilson@opensourceintegrators.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.

.. |maintainer-dreispt| image:: https://github.com/dreispt.png?size=40px
:target: https://github.com/dreispt
:alt: dreispt

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-dreispt|

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/sale_product_approval_mrp>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions sale_product_approval_mrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
23 changes: 23 additions & 0 deletions sale_product_approval_mrp/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Manufacturing Approval Workflow",
"summary": "Manufacturing Product Apploval Workflow",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/sale-workflow",
"category": "Products",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"maintainers": ["dreispt"],
"development_status": "Alpha",
"depends": ["mrp", "sale_product_approval"],
"data": [
"views/product_state.xml",
"views/product_template.xml",
"views/mrp_production.xml",
"views/mrp_bom.xml",
"views/mrp_production_exception.xml",
],
}
4 changes: 4 additions & 0 deletions sale_product_approval_mrp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import product_state
from . import product_template
from . import mrp_production
from . import mrp_bom
36 changes: 36 additions & 0 deletions sale_product_approval_mrp/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class MRPBoM(models.Model):
_inherit = "mrp.bom"

bom_line_exceptions = fields.Boolean(
compute="_compute_bom_exceptions", string="BoM Line Exceptions"
)
bom_exceptions = fields.Boolean(
compute="_compute_bom_exceptions", string="BoM Exceptions"
)

@api.depends("bom_line_ids.approved_bom_ok")
def _compute_bom_exceptions(self):
for rec in self:
rec.bom_line_exceptions = any(
not line.approved_bom_ok for line in rec.bom_line_ids
)
rec.bom_exceptions = (
True
if (
(rec.product_id and not rec.product_id.bom_ok)
or (rec.product_tmpl_id and not rec.product_tmpl_id.bom_ok)
)
else False
)


class MRPBoMLine(models.Model):
_inherit = "mrp.bom.line"

approved_bom_ok = fields.Boolean(related="product_id.bom_ok")
91 changes: 91 additions & 0 deletions sale_product_approval_mrp/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import date

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


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

mo_exceptions = fields.Boolean(
related="product_id.mrp_ok",
string="MO Exceptions",
)
bom_mo_exception = fields.Boolean(
compute="_compute_bom_exception", string="BoM Exception"
)
mo_line_exceptions = fields.Boolean(
compute="_compute_mo_exceptions", string="MO Line Exceptions"
)
override_mo_exception = fields.Boolean("Override MO Exception")

@api.depends("move_raw_ids.approved_mrp_component_ok")
def _compute_mo_exceptions(self):
for rec in self:
rec.mo_line_exceptions = any(
not line.approved_mrp_component_ok for line in rec.move_raw_ids
)

@api.depends("bom_id")
def _compute_bom_exception(self):
for rec in self:
rec.bom_mo_exception = (
True
if (rec.bom_id.bom_line_exceptions or rec.bom_id.bom_exceptions)
else False
)

def _log_exception_activity_mrp(self, product_id):
for order in self:
note = self._render_product_state_excep(order, product_id)
order.activity_schedule(
"mail.mail_activity_data_warning",
date.today(),
note=note,
user_id=order.user_id.id or SUPERUSER_ID,
)

def _render_product_state_excep(self, order, product_id):
values = {"mrp_order_ref": order, "product_ref": product_id}
return self.env.ref(
"sale_product_approval_mrp.exception_on_mrp_production"
)._render(values=values)

def action_confirm(self):
res = super(MRPProduction, self).action_confirm()
for mo in self:
if (
(mo.mo_line_exceptions or mo.bom_mo_exception)
and not mo.override_mo_exception
and not self._context.get("override_ex")
):
raise UserError(
_(
"You can not confirm this manufacturing order "
"because some products are not allowed in this order."
)
)
return res

def button_mark_done(self):
res = super(MRPProduction, self).button_mark_done()
for mo in self:
if (
mo.mo_line_exceptions or mo.bom_mo_exception
) and not mo.override_mo_exception:
raise UserError(
_(
"You can not mark done because some products are not "
"allowed in this order."
)
)
return res


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

approved_mrp_component_ok = fields.Boolean(related="product_id.mrp_component_ok")
14 changes: 14 additions & 0 deletions sale_product_approval_mrp/models/product_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductState(models.Model):
_inherit = "product.state"

approved_mrp = fields.Boolean(string="Approved to be Manufactured", default=True)
approved_component_mrp = fields.Boolean(
string="Approved to be a Component on a Manufacturing Order", default=True
)
approved_bom = fields.Boolean(string="Approved to be on a BoM", default=True)
Loading

0 comments on commit 8fd1d50

Please sign in to comment.