Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] ddmrp_warning: various improvements #491

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddmrp_warning/data/ddmrp_warning_definition_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<field name="name">Quantity multiple bigger than MOQ</field>
<field
name="python_code"
>buffer.minimum_order_quantity &lt; buffer.qty_multiple</field>
>buffer.minimum_order_quantity &gt; 0 and buffer.minimum_order_quantity &lt; buffer.qty_multiple</field>
<field name="severity">2_mid</field>
</record>
<record
Expand Down
12 changes: 12 additions & 0 deletions ddmrp_warning/models/ddmrp_warning_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class DdmrpWarningDefinition(models.Model):
help="Domain based on Stock Buffer, to define if the "
"warning is applicable or not.",
)
ddmrp_warning_item_ids = fields.One2many(
comodel_name="ddmrp.warning.item",
inverse_name="warning_definition_id",
readonly=True,
)

def _eval_warning_domain(self, buffer, domain):
buffer_domain = [("id", "=", buffer.id)]
Expand Down Expand Up @@ -65,3 +70,10 @@ def evaluate_definition(self, buffer):
% ({"name": self._name, "error": error})
) from error
return res

def write(self, vals):
# Unlink warning items when definition is archived
res = super().write(vals)
if "active" in vals and not vals.get("active"):
self.ddmrp_warning_item_ids.unlink()
return res
1 change: 1 addition & 0 deletions ddmrp_warning/models/ddmrp_warning_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DdmrpWarningItem(models.Model):

warning_definition_id = fields.Many2one(
comodel_name="ddmrp.warning.definition",
ondelete="cascade",
)
buffer_id = fields.Many2one(comodel_name="stock.buffer", ondelete="cascade")
name = fields.Char(
Expand Down
7 changes: 7 additions & 0 deletions ddmrp_warning/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ def cron_generate_ddmrp_warnings(self, automatic=False):
if auto_commit:
self._cr.commit() # pylint: disable=E8102
return True

def write(self, vals):
# Unlink warning items when buffer is archived
res = super().write(vals)
if "active" in vals and not vals.get("active"):
self.ddmrp_warning_item_ids.unlink()
return res
14 changes: 14 additions & 0 deletions ddmrp_warning/tests/test_ddmrp_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ def test_01_buffer_with_warnings(self):
self._refresh_involved_buffers()
new_count = len(self.buffer_warnings.ddmrp_warning_item_ids)
self.assertEqual(prev_count - new_count, 1)

def test_02_buffer_archive(self):
self._refresh_involved_buffers()
self.assertTrue(self.buffer_warnings.ddmrp_warning_item_ids)
self.buffer_warnings.active = False
self.assertFalse(self.buffer_warnings.ddmrp_warning_item_ids)

def test_03_definition_archive(self):
self._refresh_involved_buffers()
self.assertTrue(self.spike_warning.ddmrp_warning_item_ids)
self.assertTrue(self.buffer_warnings.ddmrp_warning_item_ids)
self.spike_warning.active = False
self.assertFalse(self.spike_warning.ddmrp_warning_item_ids)
self.assertFalse(self.buffer_warnings.ddmrp_warning_item_ids)
Loading