feat: Discount Filters
- Discount filters in filters section
- Code cleanup
diff --git a/erpnext/templates/generators/item_group.html b/erpnext/templates/generators/item_group.html
index 233b169..a27b566 100644
--- a/erpnext/templates/generators/item_group.html
+++ b/erpnext/templates/generators/item_group.html
@@ -1,3 +1,4 @@
+{% from "erpnext/templates/includes/macros.html" import field_filter_section, attribute_filter_section, discount_range_filters %}
{% extends "templates/web.html" %}
{% block header %}
@@ -63,68 +64,16 @@
<div class="mb-4 filters-title" > {{ _('Filters') }} </div>
<a class="mb-4 clear-filters" href="/{{ doc.route }}">{{ _('Clear All') }}</a>
</div>
- {% for field_filter in field_filters %}
- {%- set item_field = field_filter[0] %}
- {%- set values = field_filter[1] %}
- <div class="mb-4 filter-block pb-5">
- <div class="filter-label mb-3">{{ item_field.label }}</div>
+ <!-- field filters -->
+ {{ field_filter_section(field_filters) }}
- {% if values | len > 20 %}
- <!-- show inline filter if values more than 20 -->
- <input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
- {% endif %}
+ <!-- attribute filters -->
+ {{ attribute_filter_section(attribute_filters) }}
- {% if values %}
- <div class="filter-options">
- {% for value in values %}
- <div class="checkbox" data-value="{{ value }}">
- <label for="{{value}}">
- <input type="checkbox"
- class="product-filter field-filter"
- id="{{value}}"
- data-filter-name="{{ item_field.fieldname }}"
- data-filter-value="{{ value }}"
- >
- <span class="label-area">{{ value }}</span>
- </label>
- </div>
- {% endfor %}
- </div>
- {% else %}
- <i class="text-muted">{{ _('No values') }}</i>
- {% endif %}
- </div>
- {% endfor %}
-
- {% for attribute in attribute_filters %}
- <div class="mb-4 filter-block pb-5">
- <div class="filter-label mb-3">{{ attribute.name}}</div>
- {% if values | len > 20 %}
- <!-- show inline filter if values more than 20 -->
- <input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
- {% endif %}
-
- {% if attribute.item_attribute_values %}
- <div class="filter-options">
- {% for attr_value in attribute.item_attribute_values %}
- <div class="checkbox">
- <label data-value="{{ value }}">
- <input type="checkbox"
- class="product-filter attribute-filter"
- id="{{attr_value.name}}"
- data-attribute-name="{{ attribute.name }}"
- data-attribute-value="{{ attr_value.attribute_value }}"
- {% if attr_value.checked %} checked {% endif %}>
- <span class="label-area">{{ attr_value.attribute_value }}</span>
- </label>
- </div>
- {% endfor %}
- </div>
- {% else %}
- <i class="text-muted">{{ _('No values') }}</i>
- {% endif %}
- </div>
- {% endfor %}
+ <!-- discount filters -->
+ {% if discount_filters %}
+ {{ discount_range_filters(discount_filters) }}
+ {% endif %}
</div>
<script>
diff --git a/erpnext/templates/includes/macros.html b/erpnext/templates/includes/macros.html
index 1063704..2c5f7b9 100644
--- a/erpnext/templates/includes/macros.html
+++ b/erpnext/templates/includes/macros.html
@@ -315,3 +315,91 @@
{% endfor %}
</div>
{%- endmacro -%}
+
+{%- macro field_filter_section(filters)-%}
+{% for field_filter in filters %}
+ {%- set item_field = field_filter[0] %}
+ {%- set values = field_filter[1] %}
+ <div class="mb-4 filter-block pb-5">
+ <div class="filter-label mb-3">{{ item_field.label }}</div>
+
+ {% if values | len > 20 %}
+ <!-- show inline filter if values more than 20 -->
+ <input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
+ {% endif %}
+
+ {% if values %}
+ <div class="filter-options">
+ {% for value in values %}
+ <div class="checkbox" data-value="{{ value }}">
+ <label for="{{value}}">
+ <input type="checkbox"
+ class="product-filter field-filter"
+ id="{{value}}"
+ data-filter-name="{{ item_field.fieldname }}"
+ data-filter-value="{{ value }}"
+ >
+ <span class="label-area">{{ value }}</span>
+ </label>
+ </div>
+ {% endfor %}
+ </div>
+ {% else %}
+ <i class="text-muted">{{ _('No values') }}</i>
+ {% endif %}
+ </div>
+{% endfor %}
+{%- endmacro -%}
+
+{%- macro attribute_filter_section(filters)-%}
+{% for attribute in filters %}
+ <div class="mb-4 filter-block pb-5">
+ <div class="filter-label mb-3">{{ attribute.name}}</div>
+ {% if values | len > 20 %}
+ <!-- show inline filter if values more than 20 -->
+ <input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
+ {% endif %}
+
+ {% if attribute.item_attribute_values %}
+ <div class="filter-options">
+ {% for attr_value in attribute.item_attribute_values %}
+ <div class="checkbox">
+ <label data-value="{{ value }}">
+ <input type="checkbox"
+ class="product-filter attribute-filter"
+ id="{{attr_value.name}}"
+ data-attribute-name="{{ attribute.name }}"
+ data-attribute-value="{{ attr_value.attribute_value }}"
+ {% if attr_value.checked %} checked {% endif %}>
+ <span class="label-area">{{ attr_value.attribute_value }}</span>
+ </label>
+ </div>
+ {% endfor %}
+ </div>
+ {% else %}
+ <i class="text-muted">{{ _('No values') }}</i>
+ {% endif %}
+ </div>
+{% endfor %}
+{%- endmacro -%}
+
+{%- macro discount_range_filters(filters)-%}
+<div class="mb-4 filter-block pb-5">
+ <div class="filter-label mb-3">{{ _("Discounts") }}</div>
+ <div class="filter-options">
+ {% for entry in filters %}
+ <div class="checkbox">
+ <label data-value="{{ entry[0] }}">
+ <input type="radio" class="product-filter discount-filter"
+ name="discount" id="{{ entry[0] }}"
+ data-filter-name="discount" data-filter-value="{{ entry[0] }}"
+ >
+ <span class="label-area" for="{{ entry[0] }}">
+ {{ entry[1] }}
+ </span>
+ </label>
+ </div>
+ {% endfor %}
+ </div>
+</div>
+{%- endmacro -%}