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 authored and PauBForgeFlow committed Dec 27, 2023
1 parent b653100 commit 2eaef3e
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

Check warning on line 89 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L89

Added line #L89 was not covered by tests
if self.move_orig_ids:
moves = self.move_orig_ids

Check warning on line 91 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L91

Added line #L91 was not covered by tests
while moves.mapped("move_orig_ids"):
moves = moves.mapped("move_orig_ids")

Check warning on line 93 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L93

Added line #L93 was not covered by tests
if self.move_dest_ids:
moves = self.move_dest_ids

Check warning on line 95 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L95

Added line #L95 was not covered by tests
while moves.mapped("move_dest_ids"):
moves = moves.mapped("move_dest_ids")

Check warning on line 97 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L97

Added line #L97 was not covered by tests
if moves.mapped("purchase_line_id").filtered(lambda x: x.state != "cancel"):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")

Check warning on line 99 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L99

Added line #L99 was not covered by tests
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(

Check warning on line 110 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L110

Added line #L110 was not covered by tests
"sale.action_quotations"
)
result["domain"] = [("id", "in", moves.mapped("sale_line_id.order_id.id"))]

Check warning on line 113 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L113

Added line #L113 was not covered by tests
elif moves.mapped("production_id"):
result = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 115 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L115

Added line #L115 was not covered by tests
"mrp.mrp_production_action"
)
result["domain"] = [("id", "in", moves.mapped("production_id.id"))]

Check warning on line 118 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L118

Added line #L118 was not covered by tests
elif moves.mapped("raw_material_production_id"):
result = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 120 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L120

Added line #L120 was not covered by tests
"mrp.mrp_production_action"
)
result["domain"] = [

Check warning on line 123 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L123

Added line #L123 was not covered by tests
("id", "in", moves.mapped("raw_material_production_id.id"))
]
else:
result = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 127 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L127

Added line #L127 was not covered by tests
"stock.action_picking_tree_all"
)
result["domain"] = [("id", "in", moves.mapped("picking_id.id"))]
result["context"] = {}
return result

Check warning on line 132 in ddmrp/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_move.py#L130-L132

Added lines #L130 - L132 were not covered by tests
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 2eaef3e

Please sign in to comment.