Skip to content

Commit

Permalink
Merge PR #248 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Apr 28, 2023
2 parents e2bfcb0 + 61a1f99 commit 2e5b268
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
1 change: 1 addition & 0 deletions ddmrp/__manifest__.py
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
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)

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
25 changes: 25 additions & 0 deletions ddmrp/models/stock_buffer.py
Expand Up @@ -198,6 +198,31 @@ 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(
"stock_demand_estimate.stock_demand_estimate_action"
)
recs = self.env["stock.demand.estimate"].search(
[
("product_id", "=", self.product_id.id),
("location_id", "=", self.location_id.id),
]
)
result["domain"] = [("id", "in", recs.ids)]
return result

def action_view_bom(self):
action = self.product_id.action_view_bom()
locations = self.env["stock.location"].search(
[("id", "child_of", [self.location_id.id])]
)
action["domain"] += [
"|",
("location_id", "in", locations.ids),
("location_id", "=", False),
]
return action

@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
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
@@ -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
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 2e5b268

Please sign in to comment.