Skip to content

Commit

Permalink
[MIG] stock_request_mrp: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaisLForgeFlow committed May 23, 2024
1 parent 6c68f1f commit 6c44fc1
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 42 deletions.
10 changes: 8 additions & 2 deletions stock_request_mrp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Stock Request MRP

|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.
This module allows users to be able to display Manufacturing Orders that
have been created as a consequence of Stock Requests.

**Table of contents**

Expand All @@ -43,6 +43,12 @@ 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.

Navigate to Stock Requests and create a new stock request. Upon
confirmation of the stock request, the system will automatically
generate the corresponding manufacturing order. View and manage the
generated manufacturing orders directly from the stock request record or
through Manufacturing.

Known issues / Roadmap
======================

Expand Down
4 changes: 2 additions & 2 deletions stock_request_mrp/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2017-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2017-24 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": "16.0.1.0.1",
"version": "17.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-request",
"author": "ForgeFlow, Odoo Community Association (OCA)",
Expand Down
20 changes: 10 additions & 10 deletions stock_request_mrp/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2020-24 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

import logging
Expand All @@ -8,17 +8,17 @@
logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
def post_init_hook(env):
"""
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)
link_existing_mos_to_stock_request(env)


def link_existing_mos_to_stock_request(cr):
env = api.Environment(cr, SUPERUSER_ID, dict())
def link_existing_mos_to_stock_request(env):
env = api.Environment(env.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"]
Expand All @@ -29,7 +29,7 @@ def link_existing_mos_to_stock_request(cr):
[("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)
stock_request = stock_requests.filtered(lambda x, mo=mo: x.name == mo.origin)
if stock_request:
# Link SR to MO
mo.stock_request_ids = [(6, 0, stock_request.ids)]
Expand Down Expand Up @@ -59,13 +59,13 @@ def link_existing_mos_to_stock_request(cr):
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
quantity = ml.product_uom_id._compute_quantity(

Check warning on line 62 in stock_request_mrp/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_request_mrp/hooks.py#L62

Added line #L62 was not covered by tests
ml.quantity, ml.product_id.uom_id
)
to_allocate_qty = ml.qty_done
to_allocate_qty = ml.quantity

Check warning on line 65 in stock_request_mrp/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_request_mrp/hooks.py#L65

Added line #L65 was not covered by tests
for allocation in ml.move_id.allocation_ids:
if allocation.open_product_qty:
allocated_qty = min(allocation.open_product_qty, qty_done)
allocated_qty = min(allocation.open_product_qty, quantity)
allocation.allocated_product_qty += allocated_qty
to_allocate_qty -= allocated_qty
stock_request.check_done()

Check warning on line 71 in stock_request_mrp/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_request_mrp/hooks.py#L68-L71

Added lines #L68 - L71 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion stock_request_mrp/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2020-24 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
Expand Down
2 changes: 1 addition & 1 deletion stock_request_mrp/models/stock_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2020-24 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
Expand Down
2 changes: 1 addition & 1 deletion stock_request_mrp/models/stock_request_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2020-24 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
Expand Down
2 changes: 1 addition & 1 deletion stock_request_mrp/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2020-24 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models

Expand Down
2 changes: 1 addition & 1 deletion stock_request_mrp/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This module allows for users to be able to display manufacturing orders
This module allows users to be able to display Manufacturing Orders
that have been created as a consequence of Stock Requests.
4 changes: 4 additions & 0 deletions stock_request_mrp/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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.

Navigate to Stock Requests and create a new stock request.
Upon confirmation of the stock request, the system will automatically generate the corresponding manufacturing order.
View and manage the generated manufacturing orders directly from the stock request record or through Manufacturing.
9 changes: 7 additions & 2 deletions stock_request_mrp/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ <h1 class="title">Stock Request MRP</h1>
!! source digest: sha256:f6a1ec65a0741589dfbce1eedd9b245fcc1df92be32de0e1a87d92fe14e044d2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-request/tree/17.0/stock_request_mrp"><img alt="OCA/stock-logistics-request" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--request-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-request-17-0/stock-logistics-request-17-0-stock_request_mrp"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-request&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows for users to be able to display manufacturing orders
that have been created as a consequence of Stock Requests.</p>
<p>This module allows users to be able to display Manufacturing Orders that
have been created as a consequence of Stock Requests.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -390,6 +390,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>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.</p>
<p>Navigate to Stock Requests and create a new stock request. Upon
confirmation of the stock request, the system will automatically
generate the corresponding manufacturing order. View and manage the
generated manufacturing orders directly from the stock request record or
through Manufacturing.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
Expand Down
65 changes: 50 additions & 15 deletions stock_request_mrp/tests/test_stock_request_mrp.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022 Tecnativa - Pedro M. Baeza
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2016-24 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022-24 Tecnativa - Pedro M. Baeza
# Copyright 2022-24 Tecnativa - Víctor Martínez
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields
from odoo.tests import Form
from odoo.tests import Form, common, new_test_user

from odoo.addons.stock_request.tests.test_stock_request import TestStockRequest


class TestStockRequestMrp(TestStockRequest):
class TestStockRequestMrp(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.mrp_user_group = cls.env.ref("mrp.group_mrp_user")
cls.main_company = cls.env.ref("base.main_company")
cls.company_2 = cls.env["res.company"].create(
{"name": "Company2", "parent_id": cls.main_company.id}
)
cls.request_order = cls.env["stock.request.order"]
# common data
cls.stock_request_user = new_test_user(
cls.env,
login="stock_request_user",
groups="stock_request.group_stock_request_user",
company_ids=[(6, 0, [cls.main_company.id, cls.company_2.id])],
)
cls.stock_request_user.write({"groups_id": [(4, cls.mrp_user_group.id)]})

cls.stock_request_manager = new_test_user(
cls.env,
login="stock_request_manager",
groups="stock_request.group_stock_request_manager",
company_ids=[(6, 0, [cls.main_company.id, cls.company_2.id])],
)
cls.stock_request_manager.write({"groups_id": [(4, cls.mrp_user_group.id)]})

cls.warehouse = cls.env.ref("stock.warehouse0")
cls.route_manufacture = cls.warehouse.manufacture_pull_id.route_id

cls.product = cls._create_product("SH", "Shoes", False)
cls.product.write({"route_ids": [(6, 0, cls.route_manufacture.ids)]})

cls.raw_1 = cls._create_product("SL", "Sole", False)
cls._update_qty_in_location(cls, cls.warehouse.lot_stock_id, cls.raw_1, 10)
cls._update_qty_in_location(cls.warehouse.lot_stock_id, cls.raw_1, 10)
cls.raw_2 = cls._create_product("LC", "Lace", False)
cls._update_qty_in_location(cls, cls.warehouse.lot_stock_id, cls.raw_2, 10)

cls.bom = cls._create_mrp_bom(cls, cls.product, [cls.raw_1, cls.raw_2])
cls._update_qty_in_location(cls.warehouse.lot_stock_id, cls.raw_2, 10)
cls.bom = cls._create_mrp_bom(cls.product, [cls.raw_1, cls.raw_2])

cls.categ_unit = cls.env.ref("uom.product_uom_categ_unit")
cls.uom_pair = cls.env["uom.uom"].create(
{
"name": "Test-Pair",
Expand All @@ -36,9 +57,22 @@ def setUpClass(cls):
}
)

@classmethod
def _create_product(cls, default_code, name, company_id):
return cls.env["product.product"].create(
{
"default_code": default_code,
"name": name,
"type": "product",
"company_id": company_id,
}
)

@classmethod
def _update_qty_in_location(self, location, product, quantity):
self.env["stock.quant"]._update_available_quantity(product, location, quantity)

@classmethod
def _create_mrp_bom(self, product_id, raw_materials):
bom = self.env["mrp.bom"].create(
{
Expand Down Expand Up @@ -95,10 +129,11 @@ def test_create_request_01(self):
manufacturing_order.company_id, order.stock_request_ids[0].company_id
)
res = manufacturing_order.button_mark_done()
wizard_model = (
self.env[res["res_model"]].with_context(**res["context"]).create({})
)
wizard_model.process()
if isinstance(res, dict):
wizard_model = (

Check warning on line 133 in stock_request_mrp/tests/test_stock_request_mrp.py

View check run for this annotation

Codecov / codecov/patch

stock_request_mrp/tests/test_stock_request_mrp.py#L133

Added line #L133 was not covered by tests
self.env[res["res_model"]].with_context(**res["context"]).create({})
)
wizard_model.process()

Check warning on line 136 in stock_request_mrp/tests/test_stock_request_mrp.py

View check run for this annotation

Codecov / codecov/patch

stock_request_mrp/tests/test_stock_request_mrp.py#L136

Added line #L136 was not covered by tests
self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0)
self.assertEqual(order.stock_request_ids.qty_done, 5.0)
order2 = order.copy()
Expand Down
4 changes: 2 additions & 2 deletions stock_request_mrp/views/mrp_production_views.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<!-- Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
<!-- Copyright 2020-24 ForgeFlow S.L. (https://www.forgeflow.com)
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
<record id="mrp_production_form_view" model="ir.ui.view">
Expand All @@ -13,7 +13,7 @@
name="action_view_stock_request"
class="oe_stat_button"
icon="fa-chain"
attrs="{'invisible':[('stock_request_count', '=', 0)]}"
invisible="stock_request_count == 0"
groups="stock_request.group_stock_request_user"
>
<field
Expand Down
4 changes: 2 additions & 2 deletions stock_request_mrp/views/stock_request_order_views.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
<!-- Copyright 2020-24 ForgeFlow S.L. (https://www.forgeflow.com)
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
<record id="stock_request_order_form" model="ir.ui.view">
Expand All @@ -18,7 +18,7 @@
name="action_view_mrp_production"
class="oe_stat_button"
icon="fa-wrench"
attrs="{'invisible': [('production_count', '=', 0)]}"
invisible="production_count == 0"
groups="mrp.group_mrp_user"
>
<field name="production_count" widget="statinfo" string="MOs" />
Expand Down
4 changes: 2 additions & 2 deletions stock_request_mrp/views/stock_request_views.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
<!-- Copyright 2020-24 ForgeFlow S.L. (https://www.forgeflow.com)
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
<record id="view_stock_request_form" model="ir.ui.view">
Expand All @@ -18,7 +18,7 @@
name="action_view_mrp_production"
class="oe_stat_button"
icon="fa-wrench"
attrs="{'invisible': [('production_count', '=', 0)]}"
invisible="production_count == 0"
groups="mrp.group_mrp_user"
>
<field name="production_count" widget="statinfo" string="MOs" />
Expand Down

0 comments on commit 6c44fc1

Please sign in to comment.