mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[14.0][ADD] mrp_unbuild_move_link: link the stock move of a ubuild with its MO
This commit is contained in:
0
mrp_unbuild_move_link/README.rst
Normal file
0
mrp_unbuild_move_link/README.rst
Normal file
1
mrp_unbuild_move_link/__init__.py
Normal file
1
mrp_unbuild_move_link/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
14
mrp_unbuild_move_link/__manifest__.py
Normal file
14
mrp_unbuild_move_link/__manifest__.py
Normal 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,
|
||||
}
|
||||
2
mrp_unbuild_move_link/models/__init__.py
Normal file
2
mrp_unbuild_move_link/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import mrp_unbuild
|
||||
from . import stock_move
|
||||
14
mrp_unbuild_move_link/models/mrp_unbuild.py
Normal file
14
mrp_unbuild_move_link/models/mrp_unbuild.py
Normal 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
|
||||
12
mrp_unbuild_move_link/models/stock_move.py
Normal file
12
mrp_unbuild_move_link/models/stock_move.py
Normal 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",
|
||||
)
|
||||
3
mrp_unbuild_move_link/readme/CONTRIBUTORS.rst
Normal file
3
mrp_unbuild_move_link/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,3 @@
|
||||
* `ForgeFlow <https://www.forgeflow.com>`_:
|
||||
|
||||
* Thiago Mulero <thiago.mulero@forgeflow.com>
|
||||
1
mrp_unbuild_move_link/readme/DESCRIPTION.rst
Normal file
1
mrp_unbuild_move_link/readme/DESCRIPTION.rst
Normal 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
|
||||
BIN
mrp_unbuild_move_link/static/description/icon.png
Normal file
BIN
mrp_unbuild_move_link/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
1
mrp_unbuild_move_link/tests/__init__.py
Normal file
1
mrp_unbuild_move_link/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_mrp_unbuild_move_link
|
||||
56
mrp_unbuild_move_link/tests/test_mrp_unbuild_move_link.py
Normal file
56
mrp_unbuild_move_link/tests/test_mrp_unbuild_move_link.py
Normal 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",
|
||||
)
|
||||
13
mrp_unbuild_move_link/views/stock_move_views.xml
Normal file
13
mrp_unbuild_move_link/views/stock_move_views.xml
Normal 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>
|
||||
1
setup/mrp_unbuild_move_link/odoo/addons/mrp_unbuild_move_link
Symbolic link
1
setup/mrp_unbuild_move_link/odoo/addons/mrp_unbuild_move_link
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../mrp_unbuild_move_link
|
||||
6
setup/mrp_unbuild_move_link/setup.py
Normal file
6
setup/mrp_unbuild_move_link/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user