-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
24 changed files
with
1,212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_request_mrp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
================= | ||
Stock Request MRP | ||
================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github | ||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_request_mrp | ||
:alt: OCA/stock-logistics-warehouse | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_request_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/153/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows for users to be able to display manufacturing orders that have | ||
been created as a consequence of Stock Requests. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
In case that the confirmation of the Stock Request results in an immediate | ||
Manufacturing Order, the user will be able to display the MO's from the Stock | ||
Request form view. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* When a Stock Request is cancelled, it does not cancel the quantity included | ||
in the Manufacturing Order. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/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/stock-logistics-warehouse/issues/new?body=module:%20stock_request_mrp%0Aversion:%2013.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 | ||
~~~~~~~~~~~~ | ||
|
||
* Héctor Villarreal <[email protected]>. | ||
|
||
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/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_request_mrp>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2017-20 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
{ | ||
"name": "Stock Request MRP", | ||
"summary": "Manufacturing request for stock", | ||
"version": "15.0.1.0.0", | ||
"license": "LGPL-3", | ||
"website": "https://github.com/OCA/stock-logistics-warehouse", | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"category": "Warehouse Management", | ||
"depends": ["stock_request", "mrp"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/stock_request_views.xml", | ||
"views/stock_request_order_views.xml", | ||
"views/mrp_production_views.xml", | ||
], | ||
"installable": True, | ||
"auto_install": True, | ||
"post_init_hook": "post_init_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
import logging | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
""" | ||
The objective of this hook is to link existing MOs | ||
coming from a Stock Request. | ||
""" | ||
logger.info("Linking existing MOs coming from a Stock Request") | ||
link_existing_mos_to_stock_request(cr) | ||
|
||
|
||
def link_existing_mos_to_stock_request(cr): | ||
env = api.Environment(cr, SUPERUSER_ID, dict()) | ||
stock_request_obj = env["stock.request"] | ||
stock_request_order_obj = env["stock.request.order"] | ||
stock_request_allocation_obj = env["stock.request.allocation"] | ||
mrp_production_obj = env["mrp.production"] | ||
mos_with_sr = mrp_production_obj.search([("origin", "ilike", "SR/%")]) | ||
logger.info("Linking %s MOs records" % len(mos_with_sr)) | ||
stock_requests = stock_request_obj.search( | ||
[("name", "in", [mo.origin for mo in mos_with_sr])] | ||
) | ||
for mo in mos_with_sr: | ||
stock_request = stock_requests.filtered(lambda x: x.name == mo.origin) | ||
if stock_request: | ||
# Link SR to MO | ||
mo.stock_request_ids = [(6, 0, stock_request.ids)] | ||
logger.info("MO {} linked to SR {}".format(mo.name, stock_request.name)) | ||
if ( | ||
not stock_request_allocation_obj.search( | ||
[("stock_request_id", "=", stock_request.id)] | ||
) | ||
and mo.state != "cancel" | ||
): | ||
# Create allocation for finish move | ||
logger.info("Create allocation for {}".format(stock_request.name)) | ||
mo.move_finished_ids[0].allocation_ids = [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"stock_request_id": request.id, | ||
"requested_product_uom_qty": request.product_qty, | ||
}, | ||
) | ||
for request in mo.stock_request_ids | ||
] | ||
|
||
# Update allocations | ||
logger.info("Updating Allocations for SR %s" % stock_request.name) | ||
for ml in mo.finished_move_line_ids.filtered( | ||
lambda m: m.exists() and m.move_id.allocation_ids | ||
): | ||
qty_done = ml.product_uom_id._compute_quantity( | ||
ml.qty_done, ml.product_id.uom_id | ||
) | ||
to_allocate_qty = ml.qty_done | ||
for allocation in ml.move_id.allocation_ids: | ||
if allocation.open_product_qty: | ||
allocated_qty = min(allocation.open_product_qty, qty_done) | ||
allocation.allocated_product_qty += allocated_qty | ||
to_allocate_qty -= allocated_qty | ||
stock_request.check_done() | ||
# Update production_ids from SROs | ||
stock_request_order_obj.search([])._compute_production_ids() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * stock_request_mrp | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \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: stock_request_mrp | ||
#: model_terms:ir.ui.view,arch_db:stock_request_mrp.stock_request_order_form | ||
#: model_terms:ir.ui.view,arch_db:stock_request_mrp.view_stock_request_form | ||
msgid "MOs" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_stock_request__production_ids | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_stock_request_order__production_ids | ||
msgid "Manufacturing Orders" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_stock_request__production_count | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_stock_request_order__production_count | ||
msgid "Manufacturing Orders count" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model,name:stock_request_mrp.model_mrp_production | ||
msgid "Production Order" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model,name:stock_request_mrp.model_stock_request | ||
msgid "Stock Request" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_mrp_production__stock_request_count | ||
msgid "Stock Request #" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model,name:stock_request_mrp.model_stock_request_order | ||
msgid "Stock Request Order" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model.fields,field_description:stock_request_mrp.field_mrp_production__stock_request_ids | ||
#: model_terms:ir.ui.view,arch_db:stock_request_mrp.mrp_production_form_view | ||
msgid "Stock Requests" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: model:ir.model,name:stock_request_mrp.model_stock_rule | ||
msgid "Stock Rule" | ||
msgstr "" | ||
|
||
#. module: stock_request_mrp | ||
#: code:addons/stock_request_mrp/models/stock_request.py:0 | ||
#, python-format | ||
msgid "" | ||
"You have linked to a Manufacture Order that belongs to another company." | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import mrp_production | ||
from . import stock_rule | ||
from . import stock_request | ||
from . import stock_request_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class MrpProduction(models.Model): | ||
_inherit = "mrp.production" | ||
|
||
stock_request_ids = fields.Many2many( | ||
"stock.request", | ||
"mrp_production_stock_request_rel", | ||
"mrp_production_id", | ||
"stock_request_id", | ||
string="Stock Requests", | ||
) | ||
stock_request_count = fields.Integer( | ||
"Stock Request #", compute="_compute_stock_request_ids" | ||
) | ||
|
||
@api.depends("stock_request_ids") | ||
def _compute_stock_request_ids(self): | ||
for rec in self: | ||
rec.stock_request_count = len(rec.stock_request_ids) | ||
|
||
def action_view_stock_request(self): | ||
""" | ||
:return dict: dictionary value for created view | ||
""" | ||
action = self.env.ref("stock_request.action_stock_request_form").read()[0] | ||
|
||
requests = self.mapped("stock_request_ids") | ||
if len(requests) > 1: | ||
action["domain"] = [("id", "in", requests.ids)] | ||
elif requests: | ||
action["views"] = [ | ||
(self.env.ref("stock_request.view_stock_request_form").id, "form") | ||
] | ||
action["res_id"] = requests.id | ||
return action | ||
|
||
def _get_move_finished_values( | ||
self, | ||
product_id, | ||
product_uom_qty, | ||
product_uom, | ||
operation_id=False, | ||
byproduct_id=False, | ||
cost_share=0, | ||
): | ||
res = super()._get_move_finished_values( | ||
product_id, | ||
product_uom_qty, | ||
product_uom, | ||
operation_id=operation_id, | ||
byproduct_id=byproduct_id, | ||
cost_share=cost_share, | ||
) | ||
if self.stock_request_ids: | ||
res["allocation_ids"] = [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"stock_request_id": request.id, | ||
"requested_product_uom_qty": request.product_qty, | ||
}, | ||
) | ||
for request in self.stock_request_ids | ||
] | ||
return res |
Oops, something went wrong.