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 Nov 28, 2023
1 parent 1c8c815 commit c22db19
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,43 +1912,43 @@ def action_view_supply_moves_inside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 1912 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1912

Added line #L1912 was not covered by tests
"ddmrp.stock_move_action_ddmrp"
)
result["context"] = {}
result["context"] = {"outgoing": False}
result["domain"] = [("id", "in", self.stock_moves_inside_dlt_ids.ids)]
return result

Check warning on line 1917 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1915-L1917

Added lines #L1915 - L1917 were not covered by tests

def action_view_supply_moves_outside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 1920 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1920

Added line #L1920 was not covered by tests
"ddmrp.stock_move_action_ddmrp"
)
result["context"] = {}
result["context"] = {"outgoing": False}
result["domain"] = [("id", "in", self.stock_moves_outside_dlt_ids.ids)]

Check warning on line 1924 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1923-L1924

Added lines #L1923 - L1924 were not covered by tests
return result

def action_view_supply_rfq_inside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
result["context"] = {}
result["context"] = {"outgoing": False}
result["domain"] = [("id", "in", self.rfq_inside_dlt_ids.order_id.ids)]
return result

Check warning on line 1931 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1928-L1931

Added lines #L1928 - L1931 were not covered by tests

def action_view_supply_rfq_outside_dlt_window(self):
result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq")
result["context"] = {}
result["context"] = {"outgoing": False}
result["domain"] = [("id", "in", self.rfq_outside_dlt_ids.order_id.ids)]
return result

Check warning on line 1937 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1934-L1937

Added lines #L1934 - L1937 were not covered by tests

def action_view_qualified_demand_moves(self):
result = self.env["ir.actions.actions"]._for_xml_id(
"ddmrp.stock_move_action_ddmrp"
)
result["context"] = {}
result["context"] = {"outgoing": True}
result["domain"] = [("id", "in", self.qualified_demand_stock_move_ids.ids)]

Check warning on line 1944 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1943-L1944

Added lines #L1943 - L1944 were not covered by tests
return result

def action_view_qualified_demand_mrp(self):
result = self.env["ir.actions.actions"]._for_xml_id(
"mrp_multi_level.mrp_move_action"
)
result["context"] = {}
result["context"] = {"outgoing": True}
result["domain"] = [("id", "in", self.qualified_demand_mrp_move_ids.ids)]

Check warning on line 1952 in ddmrp/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L1951-L1952

Added lines #L1951 - L1952 were not covered by tests
return result

Expand Down
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 not self.env.context.get("outgoing", True) and 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.env.context.get("outgoing", False) and 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.mapped("purchase_line_id")
.filtered(lambda x: x.state != "cancel")
.mapped("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 c22db19

Please sign in to comment.