Skip to content

Commit

Permalink
[IMP] ddmrp_adjustment: visualize parent DAFs
Browse files Browse the repository at this point in the history
Adds a button next to ADU to clearly see if the demand is being affected by a parent DAF.
  • Loading branch information
DavidJForgeFlow committed Jun 11, 2024
1 parent 0b13945 commit 4094024
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
41 changes: 29 additions & 12 deletions ddmrp_adjustment/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from datetime import timedelta as td

from odoo import _, api, fields, models
from odoo import api, fields, models

from ..models.ddmrp_adjustment import DAF_string, LTAF_string

Expand All @@ -21,8 +21,17 @@ class StockBuffer(models.Model):
help="Demand associated to Demand Adjustment Factors applied to "
"parent buffers.",
)
daf_text = fields.Char(compute="_compute_daf_text")
parent_daf_text = fields.Char(compute="_compute_daf_text")
pre_daf_adu = fields.Float(readonly=True)
daf_applied = fields.Float(default=-1, readonly=True)
parent_daf_applied = fields.Float(default=-1, readonly=True)

@api.depends("daf_applied", "parent_daf_applied")
def _compute_daf_text(self):
for rec in self:
rec.daf_text = "DAF: *" + str(rec.daf_applied)
rec.parent_daf_text = "P. DAF: +" + str(rec.parent_daf_applied)

def _daf_to_apply_domain(self, current=True):
self.ensure_one()
Expand Down Expand Up @@ -122,16 +131,18 @@ def cron_ddmrp_adu(self, automatic=False):
res = super().cron_ddmrp_adu(automatic)
today = fields.Date.today()
for op in self.search([]).filtered("extra_demand_ids"):
to_add = sum(
op.parent_daf_applied = -1
daf_parent = sum(
op.extra_demand_ids.filtered(
lambda r: r.date_start <= today <= r.date_end
).mapped("extra_demand")
)
if to_add:
op.adu += to_add
if daf_parent:
op.parent_daf_applied = daf_parent
op.adu += op.parent_daf_applied
_logger.debug(
"DAFs-originated demand applied. {}: ADU += {}".format(
op.name, to_add
op.name, op.parent_daf_applied
)
)
return res
Expand Down Expand Up @@ -172,13 +183,11 @@ def action_view_demand_to_components(self):
.search([("buffer_origin_id", "=", self.id)])
.ids
)
return {
"name": _("Demand Allocated to Components"),
"type": "ir.actions.act_window",
"res_model": "ddmrp.adjustment.demand",
"view_mode": "tree",
"domain": [("id", "in", demand_ids)],
}
action = self.env["ir.actions.act_window"]._for_xml_id(
"ddmrp_adjustment.ddmrp_adjustment_demand_action"
)
action["domain"] = [("id", "in", demand_ids)]
return action

def action_view_affecting_adu(self):
demand_ids = (
Expand All @@ -192,3 +201,11 @@ def action_view_affecting_adu(self):
action["domain"] = [("id", "in", demand_ids)]
action["context"] = {"search_default_current": 1}
return action

def action_view_parent_affecting_adu(self):
demand_ids = self.extra_demand_ids.ids
action = self.env["ir.actions.act_window"]._for_xml_id(
"ddmrp_adjustment.ddmrp_adjustment_demand_action"
)
action["domain"] = [("id", "in", demand_ids)]
return action
1 change: 1 addition & 0 deletions ddmrp_adjustment/tests/test_adu_dlt_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ def test_dummy(self):
# Run actions
self.assertTrue(self.buffer.action_view_demand_to_components())
self.assertTrue(self.buffer.action_view_affecting_adu())
self.assertTrue(self.buffer.action_view_parent_affecting_adu())
6 changes: 6 additions & 0 deletions ddmrp_adjustment/views/ddmrp_adjustment_demand_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
</tree>
</field>
</record>
<record id="ddmrp_adjustment_demand_action" model="ir.actions.act_window">
<field name="name">Buffer Adjustments Demand</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ddmrp.adjustment.demand</field>
<field name="view_mode">tree</field>
</record>
</odoo>
17 changes: 12 additions & 5 deletions ddmrp_adjustment/views/stock_buffer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
/>
</xpath>
<button name="action_view_future_adu_indirect_demand" position="after">
<field name="daf_applied" invisible="1" />
<field name="parent_daf_applied" invisible="1" />
<button
title="View DAF Affecting Actual ADU"
title="View DAFs Affecting Actual ADU"
name="action_view_affecting_adu"
type="object"
attrs="{'invisible': [('daf_applied', '=', -1)]}"
>
<div name="daf_applied" class="o_row">
DAF: *
<field name="daf_applied" readonly="1" />
</div>
<field name="daf_text" readonly="1" />
</button>
<button
title="View Demand from parent DAFs Affecting Actual ADU"
name="action_view_parent_affecting_adu"
type="object"
attrs="{'invisible': [('parent_daf_applied', '=', -1)]}"
>
<field name="parent_daf_text" readonly="1" />
</button>
</button>
</field>
Expand Down

0 comments on commit 4094024

Please sign in to comment.