[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:
ThiagoMForgeFlow
2022-11-11 09:29:29 +01:00
committed by Christopher Ormaza
parent 7f9f48c6e0
commit 03bcf03d21
12 changed files with 129 additions and 0 deletions

View File

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

View 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,
}

View File

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

View 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)

View File

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

View File

@@ -0,0 +1 @@
This module shows a valuation button in the unbuild orders that is connected with valuation layers of the order.

View File

@@ -0,0 +1,2 @@
#. Go to *Manufacturing > Operations > Unbuild Orders* and select one that has the status = "Done".
#. Press the button *Valuation*.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

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

View File

@@ -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",
)

View 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>