Python 3 fixes [merge asap] (#12884)
* Python 3 fixes
* fixed compare
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 5e67e44..9a28946 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -11,6 +11,8 @@
from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
from erpnext.hr.doctype.employee_loan.employee_loan import update_disbursement_status
+from six import string_types
+
class JournalEntry(AccountsController):
def __init__(self, *args, **kwargs):
super(JournalEntry, self).__init__(*args, **kwargs)
@@ -763,7 +765,7 @@
if not frappe.has_permission("Account"):
frappe.msgprint(_("No Permission"), raise_exception=1)
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
company_currency = erpnext.get_company_currency(args.get("company"))
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index c32acc1..913aa6e 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -14,6 +14,7 @@
from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
from erpnext.controllers.accounts_controller import AccountsController
+from six import string_types
class InvalidPaymentEntry(ValidationError):
pass
@@ -500,7 +501,7 @@
@frappe.whitelist()
def get_outstanding_reference_documents(args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
party_account_currency = get_account_currency(args.get("party_account"))
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 83045ea..c26cb92 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -11,6 +11,7 @@
from frappe.utils import flt, cint
from frappe.model.document import Document
+from six import string_types
class MultiplePricingRuleConflict(frappe.ValidationError): pass
@@ -96,7 +97,7 @@
"ignore_pricing_rule": "something"
}
"""
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
args = frappe._dict(args)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 5237a71..55d2c21 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -17,6 +17,7 @@
from erpnext.accounts.utils import get_fiscal_year
from erpnext import get_default_currency, get_company_currency
+from six import iteritems
class DuplicatePartyAccountError(frappe.ValidationError): pass
@@ -412,7 +413,7 @@
timeline_items = dict(data)
- for date, count in timeline_items.iteritems():
+ for date, count in iteritems(timeline_items):
timestamp = get_timestamp(date)
out.update({ timestamp: count })
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index 9eee6cc..5470446 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -7,6 +7,8 @@
from frappe.utils import cstr, flt
import json, copy
+from six import string_types
+
class ItemVariantExistsError(frappe.ValidationError): pass
class InvalidItemAttributeValueError(frappe.ValidationError): pass
class ItemTemplateCannotHaveStock(frappe.ValidationError): pass
@@ -26,7 +28,7 @@
return make_variant_based_on_manufacturer(item_template, manufacturer,
manufacturer_part_no)
else:
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
if not args:
@@ -150,7 +152,7 @@
@frappe.whitelist()
def create_variant(item, args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
template = frappe.get_doc("Item", item)
@@ -177,7 +179,7 @@
item=item, args=args, now=frappe.flags.in_test);
def create_multiple_variants(item, args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
args_set = generate_keyed_value_combinations(args)
diff --git a/erpnext/controllers/tests/test_item_variant.py b/erpnext/controllers/tests/test_item_variant.py
index 34d6360..dfd9f9d 100644
--- a/erpnext/controllers/tests/test_item_variant.py
+++ b/erpnext/controllers/tests/test_item_variant.py
@@ -7,19 +7,10 @@
from erpnext.stock.doctype.item.test_item import set_item_variant_settings
from erpnext.controllers.item_variant import copy_attributes_to_variant, make_variant_item_code
-# python 3 compatibility stuff
-try:
- unicode = unicode
-except NameError:
- # Python 3
- basestring = (str, bytes)
-else:
- # Python 2
- basestring = basestring
-
+from six import string_types
def create_variant_with_tables(item, args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
template = frappe.get_doc("Item", item)
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 2e69475..58fe442 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -9,6 +9,8 @@
from frappe.website.website_generator import WebsiteGenerator
from erpnext.stock.get_item_details import get_conversion_factor
+from six import string_types
+
from operator import itemgetter
form_grid_templates = {
@@ -109,7 +111,7 @@
if not args:
args = frappe.form_dict.get('args')
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
import json
args = json.loads(args)
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 7560e8a..4915c78 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -14,6 +14,8 @@
from erpnext.stock.utils import get_bin
import json
+from six import string_types
+
class IncorrectValuationRateError(frappe.ValidationError): pass
class DuplicateEntryForProductionOrderError(frappe.ValidationError): pass
class OperationsNotCompleteError(frappe.ValidationError): pass
@@ -978,7 +980,7 @@
@frappe.whitelist()
def get_warehouse_details(args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
args = frappe._dict(args)
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 01f5206..3b5b4d3 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -11,6 +11,7 @@
from frappe.model.meta import get_field_precision
from erpnext.stock.doctype.batch.batch import get_batch_no
+from six import string_types
@frappe.whitelist()
def get_item_details(args):
@@ -100,7 +101,7 @@
return out
def process_args(args):
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
args = frappe._dict(args)
@@ -640,7 +641,7 @@
@frappe.whitelist()
def get_serial_no(args, serial_nos=None):
serial_no = None
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
args = frappe._dict(args)
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index 49d0ec6..6f8b2c9 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -7,6 +7,8 @@
import json
from frappe.utils import flt, cstr, nowdate, nowtime
+from six import string_types
+
class InvalidWarehouseCompany(frappe.ValidationError): pass
def get_stock_value_on(warehouse=None, posting_date=None, item_code=None):
@@ -126,7 +128,7 @@
def get_incoming_rate(args, raise_error_if_no_rate=True):
"""Get Incoming Rate based on valuation method"""
from erpnext.stock.stock_ledger import get_previous_sle, get_valuation_rate
- if isinstance(args, basestring):
+ if isinstance(args, string_types):
args = json.loads(args)
in_rate = 0