[14.0][ADD] mrp_unbuild_move_link: link the stock move of a ubuild with its MO

This commit is contained in:
ThiagoMForgeFlow
2022-11-11 09:29:29 +01:00
parent f4dfcb893a
commit a136d4e214
14 changed files with 124 additions and 0 deletions

View File

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,14 @@
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock moves of manufacturing orders added to unbuild orders",
"version": "14.0.1.0.0",
"license": "LGPL-3",
"category": "Manufacture",
"summary": "Link the stock moves of manufacturing orders to the respective unbuild orders",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"depends": ["mrp_account"],
"data": ["views/stock_move_views.xml"],
"installable": True,
}

View File

@@ -0,0 +1,2 @@
from . import mrp_unbuild
from . import stock_move

View File

@@ -0,0 +1,14 @@
from odoo import models
class MrpUnbuild(models.Model):
_inherit = "mrp.unbuild"
def _generate_move_from_existing_move(
self, move, factor, location_id, location_dest_id
):
result = super(MrpUnbuild, self)._generate_move_from_existing_move(
move, factor, location_id, location_dest_id
)
result.origin_mrp_manufacture_move_id = move.id
return result

View File

@@ -0,0 +1,12 @@
from odoo import fields, models
class StockMove(models.Model):
_inherit = "stock.move"
origin_mrp_manufacture_move_id = fields.Many2one(
"stock.move",
string="Manufacturing order stock move",
checkcompany=True,
help="Stock move id of the previous manufacturing order",
)

View File

@@ -0,0 +1,3 @@
* `ForgeFlow <https://www.forgeflow.com>`_:
* Thiago Mulero <thiago.mulero@forgeflow.com>

View File

@@ -0,0 +1 @@
This module associates the id of the stock move of a manufacturing order to the stock move created from its unbuild order

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1 @@
from . import test_mrp_unbuild_move_link

View File

@@ -0,0 +1,56 @@
from odoo.tests import Form
from odoo.addons.mrp.tests.common import TestMrpCommon
class TestUnbuild(TestMrpCommon):
def setUp(self):
super(TestUnbuild, self).setUp()
self.stock_location = self.env.ref("stock.stock_location_stock")
self.env.ref("base.group_user").write(
{"implied_ids": [(4, self.env.ref("stock.group_production_lot").id)]}
)
def test_unbuild_with_move_mrp_link(self):
"""This test creates an Unbuild order from a Manufacturing order and then
check if the unbuild order has the id of the manufacturing order stock move.
"""
mo, bom, p_final, p1, p2 = self.generate_mo()
self.env["stock.quant"]._update_available_quantity(p1, self.stock_location, 100)
self.env["stock.quant"]._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
mo_form = Form(mo)
mo_form.qty_producing = 5.0
mo = mo_form.save()
mo.button_mark_done()
a = mo.button_unbuild()
unbuild = self.env["mrp.unbuild"].create(
{
"product_id": a["context"]["default_product_id"],
"mo_id": a["context"]["default_mo_id"],
"company_id": a["context"]["default_company_id"],
"location_id": a["context"]["default_location_id"],
"location_dest_id": a["context"]["default_location_dest_id"],
"product_uom_id": mo["product_uom_id"].id,
"product_qty": 1,
}
)
unbuild.action_validate()
mo_stock_move_id = mo.move_finished_ids.id
so = self.env["stock.move"].browse(unbuild.produce_line_ids.ids[0])
unbuild_mo_stock_move_id = so.origin_mrp_manufacture_move_id.id
self.assertTrue(
unbuild_mo_stock_move_id,
"You should have one value in origin_mrp_manufacture_move_id field"
"in the stock move of the unbuild order",
)
self.assertEqual(
mo_stock_move_id,
unbuild_mo_stock_move_id,
"You should have the origin manufacturing order stock move "
"in the stock move of the unbuild order",
)

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_move_form_inhereted" model="ir.ui.view">
<field name="name">stock.move.form.inhereted - MO move link</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="procure_method" position="after">
<field name="origin_mrp_manufacture_move_id" />
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
../../../../mrp_unbuild_move_link

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)