Skip to content

Commit

Permalink
[IMP] Improved the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandresh-OSI committed Sep 1, 2021
1 parent a47529b commit 052f6a2
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 17 deletions.
112 changes: 112 additions & 0 deletions sale_product_approval_mrp/README.rst
@@ -0,0 +1,112 @@
===============================
Manufacturing Approval Workflow
===============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/14.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-14-0/sale-workflow-14-0-sale_product_approval_mrp
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/14.0
:alt: Try me on Runbot

|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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_product_approval_mrp%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
~~~~~~~

* 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/14.0/sale_product_approval_mrp>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
13 changes: 12 additions & 1 deletion sale_product_approval_mrp/models/mrp_production.py
Expand Up @@ -10,18 +10,29 @@ 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"
)

@api.depends("move_raw_ids.approved_mrp_component_ok")
def _compute_mo_exceptions(self):
for rec in self:
# rec.mo_exceptions = True if not rec.approved_mrp_ok else False
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)
Expand Down
17 changes: 2 additions & 15 deletions sale_product_approval_mrp/models/product_template.py
Expand Up @@ -45,7 +45,7 @@ def _compute_mrp_ok_product(self):
order_ids = self.env["mrp.production"].search(
[
("product_id", "in", product.product_variant_ids.ids),
("state", "in", ["draft", "confirmed"]),
("state", "in", ["draft", "confirmed", "progress"]),
("mo_exceptions", "=", True),
]
)
Expand All @@ -70,7 +70,7 @@ def _compute_mrp_component_ok_product(self):
(
"raw_material_production_id.state",
"in",
["draft", "sent"],
["draft", "confirmed", "progress"],
),
("approved_mrp_component_ok", "=", True),
]
Expand All @@ -86,16 +86,3 @@ def _compute_bom_ok_product(self):
product.bom_ok = (
product.candidate_bom and product.product_state_id.approved_bom
)
# if not product.sale_ok:
# order_ids = (
# self.env["sale.order.line"]
# .search(
# [
# ("product_id", "in", product.product_variant_ids.ids),
# ("state", "in", ["draft", "sent"]),
# ("approved_sale", "=", True),
# ]
# )
# .mapped("order_id")
# )
# order_ids._log_exception_activity_sale(product)
3 changes: 3 additions & 0 deletions sale_product_approval_mrp/readme/CONFIGURE.rst
@@ -0,0 +1,3 @@
* 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.
5 changes: 5 additions & 0 deletions sale_product_approval_mrp/readme/CONTRIBUTORS.rst
@@ -0,0 +1,5 @@
* `Open Source Integrators <https://opensourceintegrators.com>`_.

* Chandresh Thakkar <cthakkar@opensourceintegrators.com>
* Daniel Reis <dreis@opensourceintegrators.com>
* Patrick Wilson <pwilson@opensourceintegrators.com>
1 change: 1 addition & 0 deletions sale_product_approval_mrp/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
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.
9 changes: 9 additions & 0 deletions sale_product_approval_mrp/readme/USAGE.rst
@@ -0,0 +1,9 @@
* 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.
20 changes: 19 additions & 1 deletion sale_product_approval_mrp/views/mrp_production.xml
Expand Up @@ -45,11 +45,29 @@
<div name="button_box" position="after">
<div
attrs="{'invisible':[('mo_line_exceptions','=',False),
('mo_exceptions','=',True)]}"
('mo_exceptions','=',True),('bom_mo_exception','=',False)]}"
class="alert alert-warning text-center"
role="alert"
>Exception: A product on this Order is in a status which needs to be fixed before moving forward.</div>
</div>
<xpath expr="//sheet/group/group/field[@name='bom_id']" position="replace">
<label for="bom_id" attrs="{'readonly': [('state', '!=', 'draft')]}" />
<div>
<field
name="bom_id"
context="{'default_product_tmpl_id': product_tmpl_id}"
attrs="{'readonly': [('state', '!=', 'draft')]}"
/>
<field name="bom_mo_exception" invisible="1" />
<button
style="margin-left: 25px;"
class="fa fa-exclamation-triangle"
attrs="{'invisible':[('bom_mo_exception','=',False)]}"
title="A product on this BoM has been marked as not allowed."
/>

</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 052f6a2

Please sign in to comment.