fix: Sider and Tests

This commit is contained in:
marination 2021-04-08 15:25:43 +05:30
parent c842305be0
commit 3d5f029e51
12 changed files with 59 additions and 51 deletions

View File

@ -3,7 +3,8 @@
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.utils import cint
from frappe import _, msgprint
from frappe.model.document import Document
from frappe.utils import cint
from frappe.utils import get_datetime, get_datetime_str, now_datetime
@ -29,7 +30,8 @@ class ECommerceSettings(Document):
frappe.clear_document_cache("E Commerce Settings", "E Commerce Settings")
def validate_field_filters(self):
if not (self.enable_field_filters and self.filter_fields): return
if not (self.enable_field_filters and self.filter_fields):
return
item_meta = frappe.get_meta("Item")
valid_fields = [df.fieldname for df in item_meta.fields if df.fieldtype in ["Link", "Table MultiSelect"]]
@ -39,7 +41,8 @@ class ECommerceSettings(Document):
frappe.throw(_("Filter Fields Row #{0}: Fieldname <b>{1}</b> must be of type 'Link' or 'Table MultiSelect'").format(f.idx, f.fieldname))
def validate_attribute_filters(self):
if not (self.enable_attribute_filters and self.filter_attributes): return
if not (self.enable_attribute_filters and self.filter_attributes):
return
# if attribute filters are enabled, hide_variants should be disabled
self.hide_variants = 0

View File

@ -4,9 +4,6 @@
from __future__ import unicode_literals
from datetime import datetime
from six import string_types
import json
import frappe
from frappe.model.document import Document
from frappe.contacts.doctype.contact.contact import get_contact_name

View File

@ -48,6 +48,7 @@ class WebsiteItem(WebsiteGenerator):
self.update_template_item()
def on_trash(self):
super(WebsiteItem, self).on_trash()
self.publish_unpublish_desk_item(publish=False)
def validate_duplicate_website_item(self):
@ -169,8 +170,8 @@ class WebsiteItem(WebsiteGenerator):
context.parents = get_parent_item_groups(self.item_group, from_item=True)
self.attributes = frappe.get_all("Item Variant Attribute",
fields=["attribute", "attribute_value"],
filters={"parent": self.item_code})
fields=["attribute", "attribute_value"],
filters={"parent": self.item_code})
self.set_variant_context(context)
self.set_attribute_context(context)
self.set_disabled_attributes(context)
@ -181,7 +182,7 @@ class WebsiteItem(WebsiteGenerator):
context.wished = False
if frappe.db.exists("Wishlist Items", {"item_code": self.item_code, "parent": frappe.session.user}):
context.wished = True
context.wished = True
return context
@ -192,8 +193,8 @@ class WebsiteItem(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:
@ -227,8 +228,8 @@ class WebsiteItem(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})
# make a map for easier access in templates
v.attribute_map = frappe._dict({})
for attr in v.attributes:
@ -379,7 +380,8 @@ def invalidate_cache_for_web_item(doc):
@frappe.whitelist()
def make_website_item(doc, save=True):
if not doc: return
if not doc:
return
if isinstance(doc, string_types):
doc = json.loads(doc)

View File

@ -53,7 +53,7 @@ def remove_from_wishlist(item_code):
delete
from `tabWishlist Items`
where item_code=%(item_code)s
"""%{"item_code": frappe.db.escape(item_code)})
""" % {"item_code": frappe.db.escape(item_code)})
frappe.db.commit()

View File

@ -14,7 +14,8 @@ class ProductFiltersBuilder:
self.item_group = item_group
def get_field_filters(self):
if not self.item_group and not self.doc.enable_field_filters: return
if not self.item_group and not self.doc.enable_field_filters:
return
filter_fields = [row.fieldname for row in self.doc.filter_fields]
@ -48,7 +49,8 @@ class ProductFiltersBuilder:
values = [d.name for d in frappe.get_all(doctype, filters)]
# Remove None
if None in values: values.remove(None)
if None in values:
values.remove(None)
if values:
filter_data.append([df, values])
@ -56,7 +58,8 @@ class ProductFiltersBuilder:
return filter_data
def get_attribute_filters(self):
if not self.item_group and not self.doc.enable_attribute_filters: return
if not self.item_group and not self.doc.enable_attribute_filters:
return
attributes = [row.attribute for row in self.doc.filter_attributes]

View File

@ -106,7 +106,7 @@ class TestProductConfigurator(unittest.TestCase):
def publish_items_on_website(self):
if frappe.db.exists("Item", "_Test Item") and not frappe.db.exists("Website Item", {"item_code": "_Test Item"}):
make_website_item(frappe.get_cached_doc("Item", "_Test Item"))
make_website_item(frappe.get_cached_doc("Item", "_Test Item"))
if frappe.db.exists("Item", "_Test Variant Item") and not frappe.db.exists("Website Item", {"item_code": "_Test Variant Item"}):
make_website_item(frappe.get_cached_doc("Item", "_Test Variant Item"))

View File

@ -12,7 +12,8 @@ def get_item_codes_by_attributes(attribute_filters, template_item_code=None):
if not isinstance(attribute_values, list):
attribute_values = [attribute_values]
if not attribute_values: continue
if not attribute_values:
continue
wheres = []
query_values = []

View File

@ -10,11 +10,11 @@ class ProductQuery:
"""Query engine for product listing
Attributes:
fields (list): Fields to fetch in query
conditions (string): Conditions for query building
or_conditions (string): Search conditions
page_length (Int): Length of page for the query
settings (Document): E Commerce Settings DocType
fields (list): Fields to fetch in query
conditions (string): Conditions for query building
or_conditions (string): Search conditions
page_length (Int): Length of page for the query
settings (Document): E Commerce Settings DocType
"""
def __init__(self):
@ -31,16 +31,18 @@ class ProductQuery:
"""Summary
Args:
attributes (dict, optional): Item Attribute filters
fields (dict, optional): Field level filters
search_term (str, optional): Search term to lookup
start (int, optional): Page start
attributes (dict, optional): Item Attribute filters
fields (dict, optional): Field level filters
search_term (str, optional): Search term to lookup
start (int, optional): Page start
Returns:
list: List of results with set fields
list: List of results with set fields
"""
if fields: self.build_fields_filters(fields)
if search_term: self.build_search_filters(search_term)
if fields:
self.build_fields_filters(fields)
if search_term:
self.build_search_filters(search_term)
if self.settings.hide_variants:
self.conditions += " and wi.variant_of is null"
@ -72,13 +74,13 @@ class ProductQuery:
if self.settings.show_stock_availability:
if item.get("website_warehouse"):
stock_qty = frappe.utils.flt(
frappe.db.get_value("Bin",
{
"item_code": item.item_code,
"warehouse": item.get("website_warehouse")
},
"actual_qty")
)
frappe.db.get_value("Bin",
{
"item_code": item.item_code,
"warehouse": item.get("website_warehouse")
},
"actual_qty")
)
item.in_stock = "green" if stock_qty else "red"
elif not frappe.db.get_value("Item", item.item_code, "is_stock_item"):
item.in_stock = "green" # non-stock item will always be available
@ -117,7 +119,8 @@ class ProductQuery:
self.conditions += " and iva.parent = wi.item_code"
for attribute, values in attributes.items():
if not isinstance(values, list): values = [values]
if not isinstance(values, list):
values = [values]
conditions_copy = self.conditions
substitutions_copy = self.substitutions.copy()
@ -140,7 +143,7 @@ class ProductQuery:
"""Build filters for field values
Args:
filters (dict): Filters
filters (dict): Filters
"""
for field, values in filters.items():
if not values:
@ -167,7 +170,7 @@ class ProductQuery:
"""Query search term in specified fields
Args:
search_term (str): Search candidate
search_term (str): Search candidate
"""
# Default fields to search from
default_fields = {'name', 'item_name', 'description', 'item_group'}

View File

@ -6,7 +6,8 @@ def execute():
for row in homepage.products:
web_item = frappe.db.get_value("Website Item", {"item_code": row.item_code}, "name")
if not web_item: continue
if not web_item:
continue
row.item_code = web_item

View File

@ -380,7 +380,6 @@ class Item(Document):
)
def on_trash(self):
super(Item, self).on_trash()
frappe.db.sql("""delete from tabBin where item_code=%s""", self.name)
frappe.db.sql("delete from `tabItem Price` where item_code=%s", self.name)
for variant_of in frappe.get_all("Item", filters={"variant_of": self.name}):

View File

@ -26,7 +26,6 @@ $(() => {
{fieldname: "comment", fieldtype: "Small Text", label: "Your Review"}
],
primary_action: function() {
let me = this;
let data = d.get_values();
frappe.call({
method: "erpnext.e_commerce.doctype.item_review.item_review.add_item_review",
@ -39,7 +38,7 @@ $(() => {
freeze: true,
freeze_message: __("Submitting Review ..."),
callback: (r) => {
if(!r.exc) {
if (!r.exc) {
frappe.msgprint({
message: __("Thank you for submitting your review"),
title: __("Review Submitted"),
@ -74,7 +73,7 @@ $(() => {
end: me.page_length
},
callback: (result) => {
if(result.message) {
if (result.message) {
let res = result.message;
me.get_user_review_html(res.reviews);
@ -85,7 +84,7 @@ $(() => {
}
}
})
});
});
}
@ -121,7 +120,7 @@ $(() => {
get_review_stars(rating) {
let stars = ``;
for(let i = 1; i < 6; i++) {
for (let i = 1; i < 6; i++) {
let fill_class = i <= rating ? 'star-click' : '';
stars += `<svg class="icon icon-md ${fill_class}">
<use href="#icon-star"></use>

View File

@ -19,7 +19,7 @@ def get_context(context):
"warehouse": item.get("warehouse")
},
"actual_qty")
)
)
item.available = True if stock_qty else False
context.items = items
@ -34,5 +34,5 @@ def get_wishlist_items():
from
`tabWishlist Items`
where
parent=%(user)s"""%{"user": frappe.db.escape(frappe.session.user)}, as_dict=1)
parent=%(user)s""" % {"user": frappe.db.escape(frappe.session.user)}, as_dict=1)
return