mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[14.0][ADD] mrp_unbuild_valuation_layer_link
[14.0][FIX] mrp_unbuild_valuation_layer_link: add assertTrue to the test
This commit is contained in:
0
mrp_unbuild_valuation_layer_link/README.rst
Normal file
0
mrp_unbuild_valuation_layer_link/README.rst
Normal file
1
mrp_unbuild_valuation_layer_link/__init__.py
Normal file
1
mrp_unbuild_valuation_layer_link/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
12
mrp_unbuild_valuation_layer_link/__manifest__.py
Normal file
12
mrp_unbuild_valuation_layer_link/__manifest__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "Valuation layers for unbuild orders",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"license": "LGPL-3",
|
||||||
|
"category": "Manufacture",
|
||||||
|
"summary": "Unbuild orders display the connected valuation layers",
|
||||||
|
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||||
|
"website": "https://github.com/OCA/manufacture",
|
||||||
|
"depends": ["mrp_account"],
|
||||||
|
"data": ["views/mrp_unbuild_views.xml"],
|
||||||
|
"installable": True,
|
||||||
|
}
|
||||||
1
mrp_unbuild_valuation_layer_link/models/__init__.py
Normal file
1
mrp_unbuild_valuation_layer_link/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import mrp_unbuild
|
||||||
27
mrp_unbuild_valuation_layer_link/models/mrp_unbuild.py
Normal file
27
mrp_unbuild_valuation_layer_link/models/mrp_unbuild.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from ast import literal_eval
|
||||||
|
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class MrpUnbuild(models.Model):
|
||||||
|
_inherit = "mrp.unbuild"
|
||||||
|
|
||||||
|
def action_view_stock_valuation_layers(self):
|
||||||
|
self.ensure_one()
|
||||||
|
domain = [
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
"in",
|
||||||
|
(
|
||||||
|
self.produce_line_ids + self.consume_line_ids
|
||||||
|
).stock_valuation_layer_ids.ids,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
action = self.env["ir.actions.actions"]._for_xml_id(
|
||||||
|
"stock_account.stock_valuation_layer_action"
|
||||||
|
)
|
||||||
|
context = literal_eval(action["context"])
|
||||||
|
context.update(self.env.context)
|
||||||
|
context["no_at_date"] = True
|
||||||
|
context["search_default_group_by_product_id"] = False
|
||||||
|
return dict(action, domain=domain, context=context)
|
||||||
3
mrp_unbuild_valuation_layer_link/readme/CONTRIBUTORS.rst
Normal file
3
mrp_unbuild_valuation_layer_link/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
* `ForgeFlow <https://www.forgeflow.com>`_:
|
||||||
|
|
||||||
|
* Thiago Mulero <thiago.mulero@forgeflow.com>
|
||||||
1
mrp_unbuild_valuation_layer_link/readme/DESCRIPTION.rst
Normal file
1
mrp_unbuild_valuation_layer_link/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This module shows a valuation button in the unbuild orders that is connected with valuation layers of the order.
|
||||||
2
mrp_unbuild_valuation_layer_link/readme/USAGE.rst
Normal file
2
mrp_unbuild_valuation_layer_link/readme/USAGE.rst
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#. Go to *Manufacturing > Operations > Unbuild Orders* and select one that has the status = "Done".
|
||||||
|
#. Press the button *Valuation*.
|
||||||
BIN
mrp_unbuild_valuation_layer_link/static/description/icon.png
Normal file
BIN
mrp_unbuild_valuation_layer_link/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
1
mrp_unbuild_valuation_layer_link/tests/__init__.py
Normal file
1
mrp_unbuild_valuation_layer_link/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_mrp__unbuild_valuation_layer_link
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
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_valuation_layer(self):
|
||||||
|
"""This test creates an Unbuild order from a Manufacturing order and then check if the
|
||||||
|
valuation button links to the valuation layer of the order.
|
||||||
|
"""
|
||||||
|
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()
|
||||||
|
layers_before_unbuild = (
|
||||||
|
self.env["stock.move"].search([]).stock_valuation_layer_ids.ids
|
||||||
|
)
|
||||||
|
|
||||||
|
x = Form(self.env["mrp.unbuild"])
|
||||||
|
x.product_id = p_final
|
||||||
|
x.bom_id = bom
|
||||||
|
x.product_qty = 5
|
||||||
|
unbuild = x.save()
|
||||||
|
unbuild.action_unbuild()
|
||||||
|
layers_after_unbuild = (
|
||||||
|
self.env["stock.move"].search([]).stock_valuation_layer_ids.ids
|
||||||
|
)
|
||||||
|
|
||||||
|
result = unbuild.action_view_stock_valuation_layers()
|
||||||
|
domain = result["domain"]
|
||||||
|
unbuild_valuation_layers = domain[0][2]
|
||||||
|
difference_layers = list(set(layers_after_unbuild) - set(layers_before_unbuild))
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
difference_layers, "There should be new layers after doing the unbuild"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
result["res_model"],
|
||||||
|
"stock.valuation.layer",
|
||||||
|
"You should access to the model stock.valuation.layer",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
difference_layers,
|
||||||
|
unbuild_valuation_layers,
|
||||||
|
"You should have as domain the ids of the stock valuation belonging "
|
||||||
|
"to the ids of the stock moves of produce_line and consume_line",
|
||||||
|
)
|
||||||
21
mrp_unbuild_valuation_layer_link/views/mrp_unbuild_views.xml
Normal file
21
mrp_unbuild_valuation_layer_link/views/mrp_unbuild_views.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<odoo>
|
||||||
|
<record id="mrp_unbuild_form_view_inherited" model="ir.ui.view">
|
||||||
|
<field name="name">mrp.unbuild.view.inherited - Button Valuation</field>
|
||||||
|
<field name="model">mrp.unbuild</field>
|
||||||
|
<field name="inherit_id" ref="mrp.mrp_unbuild_form_view" />
|
||||||
|
<field name="groups_id" eval="[(4, ref('stock.group_stock_manager'))]" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[@name='button_box']" position="inside">
|
||||||
|
<button
|
||||||
|
string="Valuation"
|
||||||
|
type="object"
|
||||||
|
name="action_view_stock_valuation_layers"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-dollar"
|
||||||
|
groups="base.group_no_one"
|
||||||
|
attrs="{'invisible': [('state', '=', 'draft')]}"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../mrp_unbuild_valuation_layer_link
|
||||||
6
setup/mrp_unbuild_valuation_layer_link/setup.py
Normal file
6
setup/mrp_unbuild_valuation_layer_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