Skip to content

Commit

Permalink
[IMP] ddmrp: Add links
Browse files Browse the repository at this point in the history
- Add link to Stock Demand Estimates from Stock Buffer
- Add link to MRP BoM from Stock Buffer
- Add link to Stock Buffers from Product Variants
- Add link to Stock Buffer from MRP BoM Line
  • Loading branch information
BernatPForgeFlow committed Apr 24, 2023
1 parent 2e85155 commit b1a2333
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
1 change: 1 addition & 0 deletions ddmrp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"views/mrp_production_view.xml",
"views/purchase_order_view.xml",
"views/purchase_order_line_view.xml",
"views/product_view.xml",
"views/mrp_bom_view.xml",
"views/stock_move_views.xml",
"views/stock_buffer_view.xml",
Expand Down
12 changes: 12 additions & 0 deletions ddmrp/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Product(models.Model):
inverse_name="product_id",
)

buffer_count = fields.Integer(compute="_compute_buffer_count")

def write(self, values):
res = super().write(values)
if values.get("active") is False:
Expand All @@ -21,3 +23,13 @@ def write(self, values):
)
buffers.write({"active": False})
return res

def _compute_buffer_count(self):
for rec in self:
rec.buffer_count = len(rec.buffer_ids)

Check warning on line 29 in ddmrp/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/product_product.py#L29

Added line #L29 was not covered by tests

def action_view_stock_buffers(self):
action = self.env["ir.actions.actions"]._for_xml_id("ddmrp.action_stock_buffer")
action["context"] = {}
action["domain"] = [("id", "in", self.buffer_ids.ids)]
return action

Check warning on line 35 in ddmrp/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/product_product.py#L32-L35

Added lines #L32 - L35 were not covered by tests
16 changes: 16 additions & 0 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def action_view_yearly_consumption(self):
action["domain"] = self._past_moves_domain(date_from, date_to, locations)
return action

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

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L202

Added line #L202 was not covered by tests
"stock_demand_estimate.stock_demand_estimate_action"
)
recs = self.env["stock.demand.estimate"].search(

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L205

Added line #L205 was not covered by tests
[
("product_id", "=", self.product_id.id),
("location_id", "=", self.location_id.id),
]
)
result["domain"] = [("id", "in", recs.ids)]
return result

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L211-L212

Added lines #L211 - L212 were not covered by tests

def action_view_bom(self):
return self.product_id.action_view_bom()

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

View check run for this annotation

Codecov / codecov/patch

ddmrp/models/stock_buffer.py#L215

Added line #L215 was not covered by tests

@api.constrains("product_id")
def _check_product_uom(self):
if any(
Expand Down
10 changes: 10 additions & 0 deletions ddmrp/views/mrp_bom_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@
</xpath>
</field>
</record>
<record id="mrp_bom_line_view_form" model="ir.ui.view">
<field name="name">mrp.bom.line.form</field>
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form" />
<field name="arch" type="xml">
<field name="parent_product_tmpl_id" position="after">
<field name="buffer_id" />
</field>
</field>
</record>
</odoo>
30 changes: 30 additions & 0 deletions ddmrp/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="product_normal_form_view_inherit" model="ir.ui.view">
<field name="name">product.product.form.inherit</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath
expr="//div[@name='button_box']/button[@name='action_view_mrp_area_parameters']"
position="after"
>
<button
type="object"
name="action_view_stock_buffers"
class="oe_stat_button"
icon="fa-flask"
attrs="{'invisible': [('buffer_count', '=', 0)]}"
>
<field
name="buffer_count"
widget="statinfo"
string="Stock Buffers"
/>
</button>
</xpath>
</field>
</record>

</odoo>
30 changes: 23 additions & 7 deletions ddmrp/views/stock_buffer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@
string="Consumption"
icon="fa-fire"
/>
<button
type="object"
name="action_view_stock_demand_estimates"
class="oe_stat_button"
string="Estimates"
icon="fa-signal"
attrs="{'invisible': [('adu_calculation_method_type', '!=', 'future')]}"
/>
<button
type="object"
name="action_view_bom"
class="oe_stat_button"
string="Bill of Materials"
icon="fa-flask"
attrs="{'invisible': [('item_type', '!=', 'manufactured')]}"
/>
<button
type="object"
name="action_view_mrp_productions"
Expand All @@ -125,13 +141,6 @@
icon="fa-credit-card"
attrs="{'invisible': [('item_type', '!=', 'purchased')]}"
/>
<button
string="Refresh Buffer"
name="refresh_buffer"
class="oe_stat_button"
icon="fa-refresh"
type="object"
/>
<button
class="oe_stat_button"
name="action_used_in_bom"
Expand All @@ -145,6 +154,13 @@
widget="statinfo"
/>
</button>
<button
string="Refresh Buffer"
name="refresh_buffer"
class="oe_stat_button"
icon="fa-refresh"
type="object"
/>
</div>
<widget
name="web_ribbon"
Expand Down

0 comments on commit b1a2333

Please sign in to comment.