From 897e90ac55e61bfab6291fd3ba87f3e2bec02c9d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 4 Nov 2021 18:49:06 +0530 Subject: [PATCH] chore: remove past module dependencies --- erpnext/accounts/doctype/tax_rule/tax_rule.py | 5 ++++- erpnext/accounts/report/financial_statements.py | 5 ++--- erpnext/setup/doctype/company/company.py | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py index e1d630d0d7..b0d6983e6e 100644 --- a/erpnext/accounts/doctype/tax_rule/tax_rule.py +++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py @@ -10,7 +10,6 @@ from frappe.contacts.doctype.address.address import get_default_address from frappe.model.document import Document from frappe.utils import cint, cstr from frappe.utils.nestedset import get_root_of -from past.builtins import cmp from six import iteritems from erpnext.setup.doctype.customer_group.customer_group import get_parent_customer_groups @@ -170,6 +169,10 @@ def get_tax_template(posting_date, args): for key in args: if rule.get(key): rule.no_of_keys_matched += 1 + def cmp(a, b): + # refernce: https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons + return int(a > b) - int(a < b) + rule = sorted(tax_rule, key = functools.cmp_to_key(lambda b, a: cmp(a.no_of_keys_matched, b.no_of_keys_matched) or diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 27294335b1..37ff103e72 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -10,7 +10,6 @@ import re import frappe from frappe import _ from frappe.utils import add_days, add_months, cint, cstr, flt, formatdate, get_first_day, getdate -from past.builtins import cmp from six import itervalues from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( @@ -343,7 +342,7 @@ def sort_accounts(accounts, is_root=False, key="name"): def compare_accounts(a, b): if re.split(r'\W+', a[key])[0].isdigit(): # if chart of accounts is numbered, then sort by number - return cmp(a[key], b[key]) + return int(a[key] > b[key]) - int(a[key] < b[key]) elif is_root: if a.report_type != b.report_type and a.report_type == "Balance Sheet": return -1 @@ -355,7 +354,7 @@ def sort_accounts(accounts, is_root=False, key="name"): return -1 else: # sort by key (number) or name - return cmp(a[key], b[key]) + return int(a[key] > b[key]) - int(a[key] < b[key]) return 1 accounts.sort(key = functools.cmp_to_key(compare_accounts)) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index d40ed912f6..5ebfa04942 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -2,7 +2,6 @@ # License: GNU General Public License v3. See license.txt -import functools import json import os @@ -13,7 +12,6 @@ from frappe.cache_manager import clear_defaults_cache from frappe.contacts.address_and_contact import load_address_and_contact from frappe.utils import cint, formatdate, get_timestamp, today from frappe.utils.nestedset import NestedSet -from past.builtins import cmp from erpnext.accounts.doctype.account.account import get_account_currency from erpnext.setup.setup_wizard.operations.taxes_setup import setup_taxes_and_charges @@ -583,7 +581,7 @@ def get_default_company_address(name, sort_key='is_primary_address', existing_ad return existing_address if out: - return sorted(out, key = functools.cmp_to_key(lambda x,y: cmp(y[1], x[1])))[0][0] + return min(out, key=lambda x: x[1])[0] # find min by sort_key else: return None