From 61fb496be6cfbfde428a0a481ffaab06ece24629 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 16 Dec 2016 12:19:56 +0530 Subject: [PATCH 1/4] [Fix] Test case --- erpnext/hr/doctype/salary_slip/test_salary_slip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py index fafc2273c9..c3fa4edc18 100644 --- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py @@ -72,7 +72,7 @@ class TestSalarySlip(unittest.TestCase): # set joinng date in the same month self.make_employee("test_employee@salary.com") - if getdate(nowdate()).day > 15: + if getdate(nowdate()).day >= 15: date_of_joining = getdate(add_days(nowdate(),-10)) relieving_date = getdate(add_days(nowdate(),-10)) elif getdate(nowdate()).day < 15 and getdate(nowdate()).day > 5: From 6500ef404daca020b3eebdb16f31ef1e3c7c7153 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 15 Dec 2016 18:24:32 +0530 Subject: [PATCH 2/4] [Fix] Timeout error in item attribute validation --- erpnext/controllers/item_variant.py | 43 +++++++++++-------- .../doctype/item_attribute/item_attribute.py | 15 +++++-- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index ba1d2426cb..66b3dd0a94 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -41,30 +41,37 @@ def validate_item_variant_attributes(item, args=None): if attribute.lower() in numeric_values: numeric_attribute = numeric_values[attribute.lower()] + validate_is_incremental(numeric_attribute, attribute, value, item.name) - from_range = numeric_attribute.from_range - to_range = numeric_attribute.to_range - increment = numeric_attribute.increment + else: + attributes_list = attribute_values.get(attribute.lower(), []) + validate_item_attribute_value(attributes_list, attribute, value, item.name) - if increment == 0: - # defensive validation to prevent ZeroDivisionError - frappe.throw(_("Increment for Attribute {0} cannot be 0").format(attribute)) +def validate_is_incremental(numeric_attribute, attribute, value, item): + from_range = numeric_attribute.from_range + to_range = numeric_attribute.to_range + increment = numeric_attribute.increment - is_in_range = from_range <= flt(value) <= to_range - precision = max(len(cstr(v).split(".")[-1].rstrip("0")) for v in (value, increment)) - #avoid precision error by rounding the remainder - remainder = flt((flt(value) - from_range) % increment, precision) + if increment == 0: + # defensive validation to prevent ZeroDivisionError + frappe.throw(_("Increment for Attribute {0} cannot be 0").format(attribute)) - is_incremental = remainder==0 or remainder==increment + is_in_range = from_range <= flt(value) <= to_range + precision = max(len(cstr(v).split(".")[-1].rstrip("0")) for v in (value, increment)) + #avoid precision error by rounding the remainder + remainder = flt((flt(value) - from_range) % increment, precision) - if not (is_in_range and is_incremental): - frappe.throw(_("Value for Attribute {0} must be within the range of {1} to {2} in the increments of {3} for Item {4}")\ - .format(attribute, from_range, to_range, increment, item.name), - InvalidItemAttributeValueError, title=_('Invalid Attribute')) + is_incremental = remainder==0 or remainder==increment - elif value not in attribute_values.get(attribute.lower(), []): - frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values for Item {2}").format( - value, attribute, item.name), InvalidItemAttributeValueError, title=_('Invalid Attribute')) + if not (is_in_range and is_incremental): + frappe.throw(_("Value for Attribute {0} must be within the range of {1} to {2} in the increments of {3} for Item {4}")\ + .format(attribute, from_range, to_range, increment, item), + InvalidItemAttributeValueError, title=_('Invalid Attribute')) + +def validate_item_attribute_value(attributes_list, attribute, attribute_value, item): + if attribute_value not in attributes_list: + frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values for Item {2}").format( + attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Invalid Attribute')) def get_attribute_values(): if not frappe.flags.attribute_values: diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.py b/erpnext/stock/doctype/item_attribute/item_attribute.py index 3220bc5ba2..71b998fb95 100644 --- a/erpnext/stock/doctype/item_attribute/item_attribute.py +++ b/erpnext/stock/doctype/item_attribute/item_attribute.py @@ -6,7 +6,8 @@ import frappe from frappe.model.document import Document from frappe import _ -from erpnext.controllers.item_variant import validate_item_variant_attributes, InvalidItemAttributeValueError +from erpnext.controllers.item_variant import (validate_is_incremental, + validate_item_attribute_value, InvalidItemAttributeValueError) class ItemAttributeIncrementError(frappe.ValidationError): pass @@ -25,9 +26,15 @@ class ItemAttribute(Document): def validate_exising_items(self): '''Validate that if there are existing items with attributes, they are valid''' - for item in frappe.db.sql('''select distinct i.name from `tabItem Variant Attribute` iva, `tabItem` i - where iva.attribute = %s and iva.parent = i.name and i.has_variants = 0''', self.name): - validate_item_variant_attributes(item[0]) + attributes_list = [d.attribute_value for d in self.item_attribute_values] + + for item in frappe.db.sql('''select i.name, iva.attribute_value as value + from `tabItem Variant Attribute` iva, `tabItem` i where iva.attribute = %s + and iva.parent = i.name and i.has_variants = 0''', self.name, as_dict=1): + if self.numeric_values: + validate_is_incremental(self, self.name, item.value, item.name) + else: + validate_item_attribute_value(attributes_list, self.name, item.value, item.name) def validate_numeric(self): if self.numeric_values: From 4c210527b271f362b702c957538d4fe53bd09445 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 19 Dec 2016 16:22:34 +0530 Subject: [PATCH 3/4] [fix] https for SMS gateway, now using requests fixes #5404 --- .../doctype/sms_settings/sms_settings.py | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/erpnext/setup/doctype/sms_settings/sms_settings.py b/erpnext/setup/doctype/sms_settings/sms_settings.py index d0f4065642..681237f679 100644 --- a/erpnext/setup/doctype/sms_settings/sms_settings.py +++ b/erpnext/setup/doctype/sms_settings/sms_settings.py @@ -69,7 +69,7 @@ def send_sms(receiver_list, msg, sender_name = ''): def send_via_gateway(arg): ss = frappe.get_doc('SMS Settings', 'SMS Settings') - args = {ss.message_parameter : arg.get('message')} + args = {ss.message_parameter: arg.get('message')} for d in ss.get("parameters"): args[d.parameter] = d.value @@ -77,7 +77,7 @@ def send_via_gateway(arg): for d in arg.get('receiver_list'): args[ss.receiver_parameter] = d status = send_request(ss.sms_gateway_url, args) - if status == 200: + if status > 200 and status < 300: success_list.append(d) if len(success_list) > 0: @@ -85,27 +85,12 @@ def send_via_gateway(arg): create_sms_log(args, success_list) frappe.msgprint(_("SMS sent to following numbers: {0}").format("\n" + "\n".join(success_list))) -# Send Request -# ========================================================= -def send_request(gateway_url, args): - import httplib, urllib - server, api_url = scrub_gateway_url(gateway_url) - conn = httplib.HTTPConnection(server) # open connection - headers = {} - headers['Accept'] = "text/plain, text/html, */*" - conn.request('GET', api_url + urllib.urlencode(args), headers = headers) # send request - resp = conn.getresponse() # get response - return resp.status -# Split gateway url to server and api url -# ========================================================= -def scrub_gateway_url(url): - url = url.replace('http://', '').strip().split('/') - server = url.pop(0) - api_url = '/' + '/'.join(url) - if not api_url.endswith('?'): - api_url += '?' - return server, api_url +def send_request(gateway_url, params): + import requests + response = requests.get(gateway_url, params = params, headers={'Accept': "text/plain, text/html, */*"}) + response.raise_for_status() + return response.status_code # Create SMS Log From 1cc2d7403b74c4364bbf30f8d34ecc28bb6bc3ec Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 20 Dec 2016 12:09:46 +0600 Subject: [PATCH 4/4] bumped to version 7.1.27 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index debf4bfb53..84660b6069 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe -__version__ = '7.1.26' +__version__ = '7.1.27' def get_default_company(user=None): '''Get default company for user'''