Skip to content

Commit

Permalink
[IMP] ddmrp: Add customized Stock Moves view
Browse files Browse the repository at this point in the history
When checking incoming quantities or qualified demand moves, we will use a customized view that allows to redirect to the source document of that move.
  • Loading branch information
BernatPForgeFlow committed Apr 18, 2024
1 parent 135cfcd commit fc183e7
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ddmrp/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,49 @@ def _update_ddmrp_nfp(self):
buffer.cron_actions(only_nfp="out")
for buffer in in_buffers.with_context(no_ddmrp_history=True):
buffer.cron_actions(only_nfp="in")

def action_open_ddmrp_source(self):
moves = self
if self.move_orig_ids:
moves = self.move_orig_ids
while moves.mapped("move_orig_ids"):
moves = moves.mapped("move_orig_ids")
if self.move_dest_ids:
moves = self.move_dest_ids
while moves.mapped("move_dest_ids"):
moves = moves.mapped("move_dest_ids")
if moves.mapped("purchase_line_id").filtered(lambda x: x.state != "cancel"):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
result["domain"] = [
(
"id",
"in",
moves.filtered(lambda x: x.state != "cancel").mapped(
"purchase_line_id.order_id.id"
),
)
]
elif moves.mapped("sale_line_id"):
result = self.env["ir.actions.actions"]._for_xml_id(
"sale.action_quotations"
)
result["domain"] = [("id", "in", moves.mapped("sale_line_id.order_id.id"))]
elif moves.mapped("production_id"):
result = self.env["ir.actions.actions"]._for_xml_id(
"mrp.mrp_production_action"
)
result["domain"] = [("id", "in", moves.mapped("production_id.id"))]
elif moves.mapped("raw_material_production_id"):
result = self.env["ir.actions.actions"]._for_xml_id(
"mrp.mrp_production_action"
)
result["domain"] = [
("id", "in", moves.mapped("raw_material_production_id.id"))
]
else:
result = self.env["ir.actions.actions"]._for_xml_id(
"stock.action_picking_tree_all"
)
result["domain"] = [("id", "in", moves.mapped("picking_id.id"))]
result["context"] = {}
return result
58 changes: 58 additions & 0 deletions ddmrp/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,45 @@
<odoo>
<!--Fixes to show date on stock move report-->
<!--If someday Odoo corrects this, we could remove this views-->
<record id="view_move_tree_ddmrp" model="ir.ui.view">
<field name="name">stock.move.tree.ddmrp</field>
<field name="model">stock.move</field>
<field name="arch" type="xml">
<tree create="0">
<field
name="date"
decoration-danger="(state not in ('cancel','done')) and date > current_date"
/>
<field name="product_id" />
<field name="location_id" options="{'no_create': True}" string="From" />
<field
name="location_dest_id"
options="{'no_create': True}"
string="To"
/>
<field name="product_uom_qty" />
<field
name="product_uom"
options="{'no_open': True, 'no_create': True}"
string="Unit of Measure"
groups="uom.group_uom"
/>
<field name="company_id" groups="base.group_multi_company" />
<field
name="state"
widget='badge'
decoration-success="state == 'done'"
decoration-info="state not in ('done', 'cancel')"
/>
<button
title="Go to Source"
name="action_open_ddmrp_source"
icon="fa-arrow-right"
type="object"
/>
</tree>
</field>
</record>
<record id="view_move_tree" model="ir.ui.view">
<field name="name">stock.move.tree</field>
<field name="model">stock.move</field>
Expand Down Expand Up @@ -48,4 +87,23 @@
<field name="domain" />
<field name="view_mode">pivot</field>
</record>
<record id="stock_move_action_ddmrp" model="ir.actions.act_window">
<field name="name">Stock Moves</field>
<field name="res_model">stock.move</field>
<field name="type">ir.actions.act_window</field>
<field name="view_id" ref="view_move_tree_ddmrp" />
<field name="search_view_id" ref="stock.view_move_search" />
<field
name="context"
>{'search_default_done': 1, 'search_default_groupby_location_id': 1}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
No stock move found
</p><p>
This menu gives you the full traceability of inventory
operations on a specific product. You can filter on the product
to see all the past or future movements for the product.
</p>
</field>
</record>
</odoo>

0 comments on commit fc183e7

Please sign in to comment.