From 391dc45964913d79c3baec434a6692a370d570d3 Mon Sep 17 00:00:00 2001 From: casesolved-co-uk Date: Fri, 9 Apr 2021 00:23:08 +0000 Subject: [PATCH] chore: fix sider --- .../accounts/report/tax_detail/tax_detail.py | 59 ++++++++++++------- .../report/tax_detail/test_tax_detail.py | 12 ++-- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/report/tax_detail/tax_detail.py b/erpnext/accounts/report/tax_detail/tax_detail.py index fb7791f7e1..aafcf1297e 100644 --- a/erpnext/accounts/report/tax_detail/tax_detail.py +++ b/erpnext/accounts/report/tax_detail/tax_detail.py @@ -3,7 +3,8 @@ # Contributed by Case Solved and sponsored by Nulight Studios from __future__ import unicode_literals -import frappe, json +import frappe +import json from frappe import _ # NOTE: Payroll is implemented using Journal Entries which are included as GL Entries @@ -86,26 +87,35 @@ def run_report(report_name, data): except KeyError: frappe.throw(_("A report component can only refer to an earlier section: ") + section_name) - if show_detail: new_data += report[section_name]['rows'] - new_data += [ {'voucher_no': section_name, 'amount': report[section_name]['subtotal']} ] - summary += [ {'label': section_name, 'datatype': 'Currency', 'value': report[section_name]['subtotal']} ] - if show_detail: new_data += [ {} ] + if show_detail: + new_data += report[section_name]['rows'] + new_data += [{'voucher_no': section_name, 'amount': report[section_name]['subtotal']}] + summary += [{'label': section_name, 'datatype': 'Currency', 'value': report[section_name]['subtotal']}] + if show_detail: + new_data += [{}] return new_data or data, summary or None def filter_match(value, string): "Approximation to datatable filters" import datetime - if string == '': return True - if value is None: value = -999999999999999 - elif isinstance(value, datetime.date): return True + if string == '': + return True + if value is None: + value = -999999999999999 + elif isinstance(value, datetime.date): + return True if isinstance(value, str): value = value.lower() string = string.lower() - if string[0] == '<': return True if string[1:].strip() else False - elif string[0] == '>': return False if string[1:].strip() else True - elif string[0] == '=': return string[1:] in value if string[1:] else False - elif string[0:2] == '!=': return string[2:] not in value + if string[0] == '<': + return True if string[1:].strip() else False + elif string[0] == '>': + return False if string[1:].strip() else True + elif string[0] == '=': + return string[1:] in value if string[1:] else False + elif string[0:2] == '!=': + return string[2:] not in value elif len(string.split(':')) == 2: pre, post = string.split(':') return (True if not pre.strip() and post.strip() in value else False) @@ -114,7 +124,8 @@ def filter_match(value, string): else: if string[0] in ['<', '>', '=']: operator = string[0] - if operator == '=': operator = '==' + if operator == '=': + operator = '==' string = string[1:].strip() elif string[0:2] == '!=': operator = '!=' @@ -132,12 +143,16 @@ def filter_match(value, string): num = float(string) if string.strip() else 0 return eval(f'{value} {operator} {num}') except ValueError: - if operator == '<': return True + if operator == '<': + return True return False -abbrev = lambda dt: ''.join(l[0].lower() for l in dt.split(' ')) + '.' -doclist = lambda dt, dfs: [abbrev(dt) + f for f in dfs] +def abbrev(dt): + return ''.join(l[0].lower() for l in dt.split(' ')) + '.' + +def doclist(dt, dfs): + return [abbrev(dt) + f for f in dfs] def as_split(fields): for field in fields: @@ -165,7 +180,8 @@ def get_columns(fieldlist): for doctypes, docfields in fieldlist.items(): fieldmap = {name: new_name for name, new_name in as_split(docfields)} for doctype in doctypes: - if isinstance(doctype, int): break + if isinstance(doctype, int): + break meta = frappe.get_meta(doctype) # get column field metadata from the db fieldmeta = {} @@ -203,8 +219,10 @@ def modify_report_data(data): import json new_data = [] for line in data: - if line.debit: line.amount = -line.debit - else: line.amount = line.credit + if line.debit: + line.amount = -line.debit + else: + line.amount = line.credit # Remove Invoice GL Tax Entries and generate Tax entries from the invoice lines if "Invoice" in line.voucher_type: if line.account_type != "Tax": @@ -226,7 +244,8 @@ def modify_report_data(data): new_data += [line] return new_data -####### JS client utilities + +# JS client utilities custom_report_dict = { 'ref_doctype': 'GL Entry', diff --git a/erpnext/accounts/report/tax_detail/test_tax_detail.py b/erpnext/accounts/report/tax_detail/test_tax_detail.py index c9b8e209e4..614ef8d234 100644 --- a/erpnext/accounts/report/tax_detail/test_tax_detail.py +++ b/erpnext/accounts/report/tax_detail/test_tax_detail.py @@ -1,6 +1,10 @@ from __future__ import unicode_literals -import frappe, unittest, datetime, json, os +import frappe +import unittest +import datetime +import json +import os from frappe.utils import getdate, add_to_date, get_first_day, get_last_day from .tax_detail import filter_match, save_custom_report @@ -38,12 +42,8 @@ class TestTaxDetail(unittest.TestCase): db_doc.submit() else: db_doc.insert() - except frappe.exceptions.DuplicateEntryError as e: + except frappe.exceptions.DuplicateEntryError: pass - #print(f'Duplicate Entry: {e}') - except: - print(f'\nError importing {doc["doctype"]}: {doc["name"]}') - raise self.load_defcols()