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 Mar 21, 2024
1 parent 4a78bae commit 0b8fab7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
33 changes: 21 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 @@ -23,6 +23,7 @@ class StockBuffer(models.Model):
)
pre_daf_adu = fields.Float(readonly=True)
daf_applied = fields.Float(default=-1, readonly=True)
parent_daf_applied = fields.Float(default=-1, readonly=True)

def _daf_to_apply_domain(self, current=True):
self.ensure_one()
Expand Down Expand Up @@ -122,16 +123,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 +175,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 +193,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>
13 changes: 12 additions & 1 deletion ddmrp_adjustment/views/stock_buffer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</xpath>
<button name="action_view_future_adu_indirect_demand" position="after">
<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)]}"
Expand All @@ -28,6 +28,17 @@
<field name="daf_applied" readonly="1" />
</div>
</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)]}"
>
<div name="daf_applied" class="o_row">
P. DAFs: +
<field name="parent_daf_applied" readonly="1" />
</div>
</button>
</button>
</field>
</record>
Expand Down

0 comments on commit 0b8fab7

Please sign in to comment.