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

[16.0][IMP] ddmrp_warning: add filters in the buffer view #422

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 89 additions & 0 deletions ddmrp_warning/models/stock_buffer.py
Expand Up @@ -19,6 +19,95 @@
readonly=True,
)

ddmrp_warning_definition_name = fields.Char(
compute="_compute_ddmrp_warning_definition_name",
search="_search_ddmrp_warning_definition_name",
)

has_high_ddmrp_warnings = fields.Boolean(
compute="_compute_has_ddmrp_warnings",
search="_search_has_high_ddmrp_warnings",
)

has_medium_ddmrp_warnings = fields.Boolean(
compute="_compute_has_ddmrp_warnings",
search="_search_has_medium_ddmrp_warnings",
)

has_low_ddmrp_warnings = fields.Boolean(
compute="_compute_has_ddmrp_warnings",
search="_search_has_low_ddmrp_warnings",
)

@api.depends("ddmrp_warning_item_ids")
def _compute_ddmrp_warning_definition_name(self):
for rec in self:
rec.ddmrp_warning_definition_name = ""

Check warning on line 45 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L45

Added line #L45 was not covered by tests
for item in rec.ddmrp_warning_item_ids:
rec.ddmrp_warning_definition_name += (

Check warning on line 47 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L47

Added line #L47 was not covered by tests
item.warning_definition_id.name + ","
)

@api.depends("ddmrp_warning_item_ids")
def _compute_has_high_ddmrp_warnings(self):
for rec in self:
rec.has_high_ddmrp_warnings = False
rec.has_medium_ddmrp_warnings = False
rec.has_low_ddmrp_warnings = False

Check warning on line 56 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L54-L56

Added lines #L54 - L56 were not covered by tests

severities = rec.ddmrp_warning_item_ids.mapped("severity")

Check warning on line 58 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L58

Added line #L58 was not covered by tests
if "3_high" in severities:
rec.has_high_ddmrp_warnings = True

Check warning on line 60 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L60

Added line #L60 was not covered by tests
if "2_mid" in severities:
rec.has_medium_ddmrp_warnings = True

Check warning on line 62 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L62

Added line #L62 was not covered by tests
if "1_low" in severities:
rec.has_low_ddmrp_warnings = True

Check warning on line 64 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L64

Added line #L64 was not covered by tests

@api.model
def _search_ddmrp_warning_definition_name(self, operator, value):
buffers = self.search([("ddmrp_warning_item_ids", "!=", [])])

Check warning on line 68 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L68

Added line #L68 was not covered by tests
buffers_filtered = buffers.filtered(
lambda b: value
in " ".join(b.ddmrp_warning_item_ids.warning_definition_id.mapped("name"))
)
if value:
return [("id", "in", buffers_filtered.ids)]

Check warning on line 74 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L74

Added line #L74 was not covered by tests
else:
return [("id", "not in", buffers_filtered.ids)]

Check warning on line 76 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L76

Added line #L76 was not covered by tests

@api.model
def _search_has_high_ddmrp_warnings(self, operator, value):
buffers = self.search([("ddmrp_warning_item_ids", "!=", [])])

Check warning on line 80 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L80

Added line #L80 was not covered by tests
buffers_high = buffers.filtered(
lambda b: "3_high" in b.ddmrp_warning_item_ids.mapped("severity")
)
if value:
return [("id", "in", buffers_high.ids)]

Check warning on line 85 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L85

Added line #L85 was not covered by tests
else:
return [("id", "not in", buffers_high.ids)]

Check warning on line 87 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L87

Added line #L87 was not covered by tests

@api.model
def _search_has_medium_ddmrp_warnings(self, operator, value):
buffers = self.search([("ddmrp_warning_item_ids", "!=", [])])

Check warning on line 91 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L91

Added line #L91 was not covered by tests
buffers_medium = buffers.filtered(
lambda b: "2_mid" in b.ddmrp_warning_item_ids.mapped("severity")
)
if value:
return [("id", "in", buffers_medium.ids)]

Check warning on line 96 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L96

Added line #L96 was not covered by tests
else:
return [("id", "not in", buffers_medium.ids)]

Check warning on line 98 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L98

Added line #L98 was not covered by tests

@api.model
def _search_has_low_ddmrp_warnings(self, operator, value):
buffers = self.search([("ddmrp_warning_item_ids", "!=", [])])

Check warning on line 102 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L102

Added line #L102 was not covered by tests
buffers_low = buffers.filtered(
lambda b: "1_low" in b.ddmrp_warning_item_ids.mapped("severity")
)
if value:
return [("id", "in", buffers_low.ids)]

Check warning on line 107 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L107

Added line #L107 was not covered by tests
else:
return [("id", "not in", buffers_low.ids)]

Check warning on line 109 in ddmrp_warning/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

ddmrp_warning/models/stock_buffer.py#L109

Added line #L109 was not covered by tests

def _generate_ddmrp_warnings(self):
definitions = self.env["ddmrp.warning.definition"].search([])
item_model = self.env["ddmrp.warning.item"]
Expand Down
21 changes: 21 additions & 0 deletions ddmrp_warning/views/ddmrp_buffer_view.xml
Expand Up @@ -36,6 +36,12 @@
<field name="model">stock.buffer</field>
<field name="inherit_id" ref="ddmrp.stock_buffer_search" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field
name="ddmrp_warning_definition_name"
string="Warning Definition"
/>
</field>
<group name="procure_recommendation" position="after">
<separator />
<group name="warnings">
Expand All @@ -44,6 +50,21 @@
string="With Warnings"
domain="[('ddmrp_warning_item_ids', '!=', False)]"
/>
<filter
name="has_high_ddmrp_warnings"
string="With High Warnings"
domain="[('has_high_ddmrp_warnings', '=', True)]"
/>
<filter
name="has_medium_ddmrp_warnings"
string="With Medium Warnings"
domain="[('has_medium_ddmrp_warnings', '=', True)]"
/>
<filter
name="has_low_ddmrp_warnings"
string="With Low Warnings"
domain="[('has_low_ddmrp_warnings', '=', True)]"
/>
</group>
</group>
</field>
Expand Down