[MIG] stock_request_mrp: Migration to 14.0

This commit is contained in:
Pedro M. Baeza
2022-10-09 01:24:43 +02:00
committed by Víctor Martínez
parent 53b7339152
commit cd7da198fd
8 changed files with 43 additions and 48 deletions

View File

@@ -14,13 +14,13 @@ Stock Request MRP
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3 :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github .. |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 :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_request_mrp
:alt: OCA/stock-logistics-warehouse :alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_request_mrp
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/13.0 :target: https://runbot.odoo-community.org/runbot/153/14.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -52,7 +52,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_. 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. 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 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**>`_. `feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_request_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. Do not contact contributors directly about support or help with technical issues.
@@ -68,6 +68,9 @@ Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Héctor Villarreal <hector.villarreal@forgeflow.com>. * Héctor Villarreal <hector.villarreal@forgeflow.com>.
* `Tecnativa <https://www.tecnativa.com>`__:
* Pedro M. Baeza
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@@ -82,6 +85,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. 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. This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_request_mrp>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -1,10 +1,11 @@
# Copyright 2017-20 ForgeFlow S.L. (https://www.forgeflow.com) # Copyright 2017-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{ {
"name": "Stock Request MRP", "name": "Stock Request MRP",
"summary": "Manufacturing request for stock", "summary": "Manufacturing request for stock",
"version": "13.0.1.0.0", "version": "14.0.1.0.0",
"license": "LGPL-3", "license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-warehouse", "website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "ForgeFlow, Odoo Community Association (OCA)", "author": "ForgeFlow, Odoo Community Association (OCA)",

View File

@@ -1,4 +1,5 @@
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) # Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models from odoo import api, fields, models
@@ -27,8 +28,9 @@ class MrpProduction(models.Model):
""" """
:return dict: dictionary value for created view :return dict: dictionary value for created view
""" """
action = self.env.ref("stock_request.action_stock_request_form").read()[0] action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_request.action_stock_request_form"
)
requests = self.mapped("stock_request_ids") requests = self.mapped("stock_request_ids")
if len(requests) > 1: if len(requests) > 1:
action["domain"] = [("id", "in", requests.ids)] action["domain"] = [("id", "in", requests.ids)]
@@ -39,7 +41,7 @@ class MrpProduction(models.Model):
action["res_id"] = requests.id action["res_id"] = requests.id
return action return action
def _get_finished_move_value( def _get_move_finished_values(
self, self,
product_id, product_id,
product_uom_qty, product_uom_qty,
@@ -47,7 +49,8 @@ class MrpProduction(models.Model):
operation_id=False, operation_id=False,
byproduct_id=False, byproduct_id=False,
): ):
res = super()._get_finished_move_value( """Inject stock request allocations when creating the finished move."""
res = super()._get_move_finished_values(
product_id, product_id,
product_uom_qty, product_uom_qty,
product_uom, product_uom,
@@ -61,7 +64,7 @@ class MrpProduction(models.Model):
0, 0,
{ {
"stock_request_id": request.id, "stock_request_id": request.id,
"requested_product_uom_qty": request.product_qty, "requested_product_uom_qty": product_uom_qty,
}, },
) )
for request in self.stock_request_ids for request in self.stock_request_ids

View File

@@ -44,7 +44,9 @@ class StockRequest(models.Model):
) )
def action_view_mrp_production(self): def action_view_mrp_production(self):
action = self.env.ref("mrp.mrp_production_action").read()[0] action = self.env["ir.actions.act_window"]._for_xml_id(
"mrp.mrp_production_action"
)
productions = self.mapped("production_ids") productions = self.mapped("production_ids")
if len(productions) > 1: if len(productions) > 1:
action["domain"] = [("id", "in", productions.ids)] action["domain"] = [("id", "in", productions.ids)]

View File

@@ -26,7 +26,9 @@ class StockRequestOrder(models.Model):
req.production_count = len(req.production_ids) req.production_count = len(req.production_ids)
def action_view_mrp_production(self): def action_view_mrp_production(self):
action = self.env.ref("mrp.mrp_production_action").read()[0] action = self.env["ir.actions.act_window"]._for_xml_id(
"mrp.mrp_production_action"
)
productions = self.mapped("production_ids") productions = self.mapped("production_ids")
if len(productions) > 1: if len(productions) > 1:
action["domain"] = [("id", "in", productions.ids)] action["domain"] = [("id", "in", productions.ids)]

View File

@@ -1 +1,4 @@
* Héctor Villarreal <hector.villarreal@forgeflow.com>. * Héctor Villarreal <hector.villarreal@forgeflow.com>.
* `Tecnativa <https://www.tecnativa.com>`__:
* Pedro M. Baeza

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Stock Request MRP</title> <title>Stock Request MRP</title>
<style type="text/css"> <style type="text/css">
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_request_mrp"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-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" href="https://runbot.odoo-community.org/runbot/153/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" 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" 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" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_request_mrp"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-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" href="https://runbot.odoo-community.org/runbot/153/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows for users to be able to display manufacturing orders that have <p>This module allows for users to be able to display manufacturing orders that have
been created as a consequence of Stock Requests.</p> been created as a consequence of Stock Requests.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
@@ -402,7 +402,7 @@ in the Manufacturing Order.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="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**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_request_mrp%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -417,6 +417,10 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id6">Contributors</a></h2> <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Héctor Villarreal &lt;<a class="reference external" href="mailto:hector.villarreal&#64;forgeflow.com">hector.villarreal&#64;forgeflow.com</a>&gt;.</li> <li>Héctor Villarreal &lt;<a class="reference external" href="mailto:hector.villarreal&#64;forgeflow.com">hector.villarreal&#64;forgeflow.com</a>&gt;.</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
</ul>
</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@@ -426,7 +430,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_request_mrp">OCA/stock-logistics-warehouse</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_request_mrp">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,5 @@
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com) # Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
from odoo import fields from odoo import fields
@@ -8,11 +9,8 @@ from odoo.tests import Form, common
class TestStockRequestMrp(common.TransactionCase): class TestStockRequestMrp(common.TransactionCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
# common models # common models
self.stock_request = self.env["stock.request"] self.stock_request = self.env["stock.request"]
self.produce_wiz = self.env["mrp.product.produce"]
# refs # refs
self.stock_request_user_group = self.env.ref( self.stock_request_user_group = self.env.ref(
"stock_request.group_stock_request_user" "stock_request.group_stock_request_user"
@@ -24,7 +22,6 @@ class TestStockRequestMrp(common.TransactionCase):
self.main_company = self.env.ref("base.main_company") self.main_company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0") self.warehouse = self.env.ref("stock.warehouse0")
self.categ_unit = self.env.ref("uom.product_uom_categ_unit") self.categ_unit = self.env.ref("uom.product_uom_categ_unit")
# common data # common data
self.company_2 = self.env["res.company"].create({"name": "Comp2"}) self.company_2 = self.env["res.company"].create({"name": "Comp2"})
self.wh2 = self.env["stock.warehouse"].search( self.wh2 = self.env["stock.warehouse"].search(
@@ -44,14 +41,11 @@ class TestStockRequestMrp(common.TransactionCase):
self.product = self._create_product( self.product = self._create_product(
"SH", "Shoes", False, self.route_manufacture.ids "SH", "Shoes", False, self.route_manufacture.ids
) )
self.raw_1 = self._create_product("SL", "Sole", False, []) self.raw_1 = self._create_product("SL", "Sole", False, [])
self._update_qty_in_location(self.warehouse.lot_stock_id, self.raw_1, 10) self._update_qty_in_location(self.warehouse.lot_stock_id, self.raw_1, 10)
self.raw_2 = self._create_product("LC", "Lace", False, []) self.raw_2 = self._create_product("LC", "Lace", False, [])
self._update_qty_in_location(self.warehouse.lot_stock_id, self.raw_2, 10) self._update_qty_in_location(self.warehouse.lot_stock_id, self.raw_2, 10)
self.bom = self._create_mrp_bom(self.product, [self.raw_1, self.raw_2]) self.bom = self._create_mrp_bom(self.product, [self.raw_1, self.raw_2])
self.uom_pair = self.env["uom.uom"].create( self.uom_pair = self.env["uom.uom"].create(
{ {
"name": "Test-Pair", "name": "Test-Pair",
@@ -111,13 +105,9 @@ class TestStockRequestMrp(common.TransactionCase):
return bom return bom
def _produce(self, mo, qty=0.0): def _produce(self, mo, qty=0.0):
wiz = Form( mo_form = Form(mo)
self.produce_wiz.with_context({"active_id": mo.id, "active_ids": [mo.id]}) mo_form.qty_producing = qty
) mo_form.save()
wiz.qty_producing = qty or mo.product_qty
produce_wizard = wiz.save()
produce_wizard.do_produce()
return True
def test_create_request_01(self): def test_create_request_01(self):
"""Single Stock request with buy rule""" """Single Stock request with buy rule"""
@@ -143,32 +133,27 @@ class TestStockRequestMrp(common.TransactionCase):
) )
], ],
} }
order = ( order = (
self.env["stock.request.order"] self.env["stock.request.order"]
.with_user(self.stock_request_user) .with_user(self.stock_request_user)
.create(vals) .create(vals)
) )
order.action_confirm() order.action_confirm()
self.assertEqual(order.state, "open") self.assertEqual(order.state, "open")
self.assertEqual(order.stock_request_ids.state, "open") self.assertEqual(order.stock_request_ids.state, "open")
order.refresh()
self.assertEqual(len(order.production_ids), 1) self.assertEqual(len(order.production_ids), 1)
self.assertEqual(len(order.stock_request_ids.production_ids), 1) self.assertEqual(len(order.stock_request_ids.production_ids), 1)
self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0) self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0)
manufacturing_order = order.production_ids[0] manufacturing_order = order.production_ids[0]
self.assertEqual( self.assertEqual(
manufacturing_order.company_id, order.stock_request_ids[0].company_id manufacturing_order.company_id, order.stock_request_ids[0].company_id
) )
# We need to use sudo() to avoid getting a permissions error in Form()
self._produce(manufacturing_order, 5.0) # related to account.move.line.
# This error is NOT reproduced in UX with user with the same permissions.
self._produce(manufacturing_order.sudo(), 5.0)
self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0) self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0)
self.assertEqual(order.stock_request_ids.qty_done, 0.0) self.assertEqual(order.stock_request_ids.qty_done, 0.0)
manufacturing_order.button_mark_done() manufacturing_order.button_mark_done()
self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0) self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0)
self.assertEqual(order.stock_request_ids.qty_done, 5.0) self.assertEqual(order.stock_request_ids.qty_done, 5.0)
@@ -196,23 +181,15 @@ class TestStockRequestMrp(common.TransactionCase):
) )
], ],
} }
order = self.env["stock.request.order"].create(vals) order = self.env["stock.request.order"].create(vals)
order.action_confirm() order.action_confirm()
stock_request = order.stock_request_ids stock_request = order.stock_request_ids
action = stock_request.action_view_mrp_production() action = stock_request.action_view_mrp_production()
self.assertEqual("views" in action.keys(), True) self.assertEqual("views" in action.keys(), True)
self.assertEqual(action["res_id"], stock_request.production_ids[0].id) self.assertEqual(action["res_id"], stock_request.production_ids[0].id)
action = stock_request.production_ids[0].action_view_stock_request() action = stock_request.production_ids[0].action_view_stock_request()
self.assertEqual(action["type"], "ir.actions.act_window") self.assertEqual(action["type"], "ir.actions.act_window")
self.assertEqual(action["res_id"], stock_request.id) self.assertEqual(action["res_id"], stock_request.id)
action = order.action_view_mrp_production() action = order.action_view_mrp_production()
self.assertEqual("views" in action.keys(), True) self.assertEqual("views" in action.keys(), True)
self.assertEqual(action["res_id"], order.production_ids[0].id) self.assertEqual(action["res_id"], order.production_ids[0].id)