fix(product-listing): fix variant selection in website

This commit is contained in:
Rushabh Mehta 2018-08-16 09:22:33 +05:30
parent 7e36aa4162
commit 8705371ef0
12 changed files with 734 additions and 675 deletions

View File

@ -178,7 +178,7 @@ def create_variant(item, args):
@frappe.whitelist()
def enqueue_multiple_variant_creation(item, args):
# There can be innumerable attribute combinations, enqueue
if isinstance(args, basestring):
if isinstance(args, frappe.string_types):
variants = json.loads(args)
total_variants = 1
for key in variants:
@ -186,10 +186,15 @@ def enqueue_multiple_variant_creation(item, args):
if total_variants >= 600:
frappe.msgprint("Please do not create more than 500 items at a time", raise_exception=1)
return
frappe.enqueue("erpnext.controllers.item_variant.create_multiple_variants",
item=item, args=args, now=frappe.flags.in_test);
if total_variants < 10:
return create_multiple_variants(item, args)
else:
frappe.enqueue("erpnext.controllers.item_variant.create_multiple_variants",
item=item, args=args, now=frappe.flags.in_test);
return 'queued'
def create_multiple_variants(item, args):
count = 0
if isinstance(args, string_types):
args = json.loads(args)
@ -199,6 +204,9 @@ def create_multiple_variants(item, args):
if not get_variant(item, args=attribute_values):
variant = create_variant(item, attribute_values)
variant.save()
count +=1
return count
def generate_keyed_value_combinations(args):
"""

View File

@ -148,7 +148,7 @@ def get_loan_application(loan_application):
def make_repayment_entry(payment_rows, loan, company, loan_account, applicant_type, applicant, \
payment_account=None, interest_income_account=None):
if isinstance(payment_rows, basestring):
if isinstance(payment_rows, frappe.string_types):
payment_rows_list = json.loads(payment_rows)
else:
frappe.throw(_("No repayments available for Journal Entry"))

View File

@ -73,7 +73,7 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
if (me.after_insert) {
me.after_insert(me.dialog.doc);
} else {
me.open_from_if_not_list();
me.open_form_if_not_list();
}
}
},

View File

@ -303,8 +303,6 @@
}
.product-text {
border-top: 1px solid @light-border-color;
padding: 15px;
word-wrap: break-word;
height: 75px;
display: block; /* Fallback for non-webkit */

View File

@ -147,6 +147,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "image",
"fieldtype": "Attach Image",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Image",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
@ -545,13 +577,14 @@
"hide_toolbar": 0,
"icon": "fa fa-sitemap",
"idx": 1,
"image_field": "image",
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 3,
"modified": "2018-07-11 16:07:56.050363",
"modified": "2018-08-16 05:41:46.788896",
"modified_by": "Administrator",
"module": "Setup",
"name": "Item Group",

View File

@ -80,6 +80,12 @@ class ItemGroup(NestedSet, WebsiteGenerator):
@frappe.whitelist(allow_guest=True)
def get_product_list_for_group(product_group=None, start=0, limit=10, search=None):
if product_group:
item_group = frappe.get_cached_doc('Item Group', product_group)
if item_group.is_group:
# return child item groups if the type is of "Is Group"
return get_child_groups_for_list_in_html(item_group, start, limit, search)
child_groups = ", ".join(['"' + frappe.db.escape(i[0]) + '"' for i in get_child_groups(product_group)])
# base query
@ -113,6 +119,23 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
return [get_item_for_list_in_html(r) for r in data]
def get_child_groups_for_list_in_html(item_group, start, limit, search):
search_filters = None
if search_filters:
search_filters = [
dict(name = ('like', '%{}%'.format(search))),
dict(description = ('like', '%{}%'.format(search)))
]
data = frappe.db.get_all('Item Group',
fields = ['name', 'route', 'description', 'image'],
filters = dict(
show_in_website = 1,
lft = ('>', item_group.lft),
rgt = ('<', item_group.rgt),
),
or_filters = search_filters)
return [get_item_for_list_in_html(r) for r in data]
def adjust_qty_for_expired_items(data):
adjusted_data = []
@ -128,7 +151,6 @@ def adjust_qty_for_expired_items(data):
return adjusted_data
def get_child_groups(item_group_name):
item_group = frappe.get_doc("Item Group", item_group_name)
return frappe.db.sql("""select name
@ -160,12 +182,13 @@ def get_parent_item_groups(item_group_name):
if not item_group_name:
return [{"name": frappe._("Home"), "route":"/"}]
item_group = frappe.get_doc("Item Group", item_group_name)
return [{"name": frappe._("Home"), "route":"/"}]+\
frappe.db.sql("""select name, route from `tabItem Group`
parent_groups = frappe.db.sql("""select name, route from `tabItem Group`
where lft <= %s and rgt >= %s
and show_in_website=1
order by lft asc""", (item_group.lft, item_group.rgt), as_dict=True)
return [{"name": frappe._("Home"), "route":"/"}] + parent_groups
def invalidate_cache_for(doc, item_group=None):
if not item_group:
item_group = doc.name

View File

@ -441,11 +441,18 @@ $.extend(erpnext.item, {
"item": frm.doc.name,
"args": selected_attributes
},
callback: function() {
frappe.show_alert({
message: __("Variant creation has been queued."),
indicator: 'orange'
});
callback: function(r) {
if (r.message==='queued') {
frappe.show_alert({
message: __("Variant creation has been queued."),
indicator: 'orange'
});
} else {
frappe.show_alert({
message: __("{0} variants created.", [r.message]),
indicator: 'green'
});
}
}
});
});

View File

@ -309,8 +309,8 @@ class Item(WebsiteGenerator):
# load variants
# also used in set_attribute_context
context.variants = frappe.get_all("Item",
filters={"variant_of": self.name, "show_variant_in_website": 1},
order_by="name asc")
filters={"variant_of": self.name, "show_variant_in_website": 1},
order_by="name asc")
variant = frappe.form_dict.variant
if not variant and context.variants:
@ -344,7 +344,8 @@ class Item(WebsiteGenerator):
# load attributes
for v in context.variants:
v.attributes = frappe.get_all("Item Variant Attribute",
fields=["attribute", "attribute_value"], filters={"parent": v.name})
fields=["attribute", "attribute_value"],
filters={"parent": v.name})
for attr in v.attributes:
values = attribute_values_available.setdefault(attr.attribute, [])
@ -365,7 +366,8 @@ class Item(WebsiteGenerator):
else:
# get list of values defined (for sequence)
for attr_value in frappe.db.get_all("Item Attribute Value",
fields=["attribute_value"], filters={"parent": attr.attribute}, order_by="idx asc"):
fields=["attribute_value"],
filters={"parent": attr.attribute}, order_by="idx asc"):
if attr_value.attribute_value in attribute_values_available.get(attr.attribute, []):
values.append(attr_value.attribute_value)
@ -441,7 +443,7 @@ class Item(WebsiteGenerator):
for d in template.get("reorder_levels"):
n = {}
for k in ("warehouse", "warehouse_reorder_level",
"warehouse_reorder_qty", "material_request_type"):
"warehouse_reorder_qty", "material_request_type"):
n[k] = d.get(k)
self.append("reorder_levels", n)

View File

@ -43,8 +43,6 @@
<br>
<div class="item-attribute-selectors">
{% if has_variants and attributes %}
{{ attributes }}
{#
{% for d in attributes %}
{% if attribute_values[d.attribute] -%}
@ -69,7 +67,6 @@
{%- endif %}
{% endfor %}
#}
{% endif %}
</div>
<br>

View File

@ -1,16 +1,6 @@
{% extends "templates/web.html" %}
{% block header %}<h1>{{ _("Products") }}</h1>{% endblock %}
{% block breadcrumbs %}
<div class="page-breadcrumbs" data-html-block="breadcrumbs">
<ul class="breadcrumb">
<li>
<span class="fa fa-angle-left"></span>
<a href="/me">{{ _("My Account") }}</a>
</li>
</ul>
</div>
{% endblock %}
{% block header %}<h1>{{ name }}</h1>{% endblock %}
{% block page_content %}
<div class="item-group-content" itemscope itemtype="http://schema.org/Product">

View File

@ -3,14 +3,14 @@
<a class="product-link product-list-link" href="{{ route|abs_url }}">
<div class='row'>
<div class='col-xs-3 col-sm-2 product-image-wrapper'>
{{ product_image_square(thumbnail or website_image) }}
{{ product_image_square(thumbnail or website_image or image) }}
</div>
<div class='col-xs-9 col-sm-10 text-left'>
<div class="product-text strong">{{ item_name }}</div>
<div class="product-text strong">{{ item_name or name }}</div>
{% set website_description = website_description or description %}
{% if website_description != item_name %}
<div class="text-muted">{{ website_description or description }}</div>
{% elif item_code != item_name %}
{% elif item_code and item_code != item_name %}
<div class="text-muted">{{ _('Item Code') }}: {{ item_code }}</div>
{% endif %}
</div>

View File

@ -24,8 +24,9 @@ def get_product_list(search=None, start=0, limit=12):
I.has_batch_no
from `tabItem` I
left join tabBin S on I.item_code = S.item_code and I.website_warehouse = S.warehouse
where (I.show_in_website = 1 or I.show_variant_in_website = 1)
where (I.show_in_website = 1)
and I.disabled = 0
and (I.variant_of is null or I.variant_of='')
and (I.end_of_life is null or I.end_of_life='0000-00-00' or I.end_of_life > %(today)s)"""
# search term condition