Merge pull request #6332 from rmehta/item-group-paging

[fix] paging for item group
This commit is contained in:
Nabin Hait 2016-09-12 13:01:54 +05:30 committed by GitHub
commit 9c82dd9157
4 changed files with 24 additions and 14 deletions

View File

@ -20,7 +20,13 @@ frappe.ui.form.on("Item Group", {
frm.trigger("set_root_readonly");
frm.add_custom_button(__("Item Group Tree"), function() {
frappe.set_route("Tree", "Item Group");
}, "icon-sitemap");
});
if(!frm.is_new()) {
frm.add_custom_button(__("Items"), function() {
frappe.set_route("List", "Item", {"item_group": frm.doc.name});
});
}
},
set_root_readonly: function(frm) {

View File

@ -60,13 +60,15 @@ class ItemGroup(NestedSet, WebsiteGenerator):
def get_context(self, context):
context.show_search=True
context.page_length = 6
context.search_link = '/product_search'
start = int(frappe.form_dict.start or 0)
if start < 0:
start = 0
context.update({
"items": get_product_list_for_group(product_group = self.name, start=start, limit=24, search=frappe.form_dict.get("search")),
"items": get_product_list_for_group(product_group = self.name, start=start,
limit=context.page_length, search=frappe.form_dict.get("search")),
"parent_groups": get_parent_item_groups(self.name),
"title": self.name,
"products_as_list": cint(frappe.db.get_single_value('Website Settings', 'products_as_list'))

View File

@ -455,16 +455,18 @@ class Item(WebsiteGenerator):
def cant_change(self):
if not self.get("__islocal"):
vals = frappe.db.get_value("Item", self.name, ["has_serial_no", "is_stock_item",
"valuation_method", "has_batch_no", "is_fixed_asset"], as_dict=True)
to_check = ("has_serial_no", "is_stock_item",
"valuation_method", "has_batch_no", "is_fixed_asset")
if vals and ((self.is_stock_item != vals.is_stock_item) or
vals.has_serial_no != self.has_serial_no or
vals.has_batch_no != self.has_batch_no or
cstr(vals.valuation_method) != cstr(self.valuation_method)):
if self.check_if_linked_document_exists():
frappe.throw(_("As there are existing transactions for this item, \
you can not change the values of 'Has Serial No', 'Has Batch No', 'Is Stock Item' and 'Valuation Method'"))
vals = frappe.db.get_value("Item", self.name, to_check, as_dict=True)
if vals:
for key in to_check:
if self.get(key) != vals.get(key):
if not self.check_if_linked_document_exists():
break # no linked document, allowed
else:
frappe.throw(_("As there are existing transactions for this item, you can not change the value of {0}").format(frappe.bold(self.meta.get_label(key))))
if vals and not self.is_fixed_asset and self.is_fixed_asset != vals.is_fixed_asset:
asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)

View File

@ -31,10 +31,10 @@
</div>
<div class="text-center item-group-nav-buttons">
{% if frappe.form_dict.start|int > 0 %}
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int - 24 }}">Prev</a>
<a class="btn btn-default" href="/{{ pathname }}?start={{ frappe.form_dict.start|int - page_length }}">Prev</a>
{% endif %}
{% if items|length == 24 %}
<a class="btn btn-default" href="{{ pathname }}?start={{ frappe.form_dict.start|int + 24 }}">Next</a>
{% if items|length == page_length %}
<a class="btn btn-default" href="/{{ pathname }}?start={{ frappe.form_dict.start|int + page_length }}">Next</a>
{% endif %}
</div>
{% else %}