chore: fix sider

This commit is contained in:
casesolved-co-uk 2021-04-09 00:23:08 +00:00
parent 7555f5f613
commit 391dc45964
2 changed files with 45 additions and 26 deletions

View File

@ -3,7 +3,8 @@
# Contributed by Case Solved and sponsored by Nulight Studios # Contributed by Case Solved and sponsored by Nulight Studios
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe, json import frappe
import json
from frappe import _ from frappe import _
# NOTE: Payroll is implemented using Journal Entries which are included as GL Entries # 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: except KeyError:
frappe.throw(_("A report component can only refer to an earlier section: ") + section_name) frappe.throw(_("A report component can only refer to an earlier section: ") + section_name)
if show_detail: new_data += report[section_name]['rows'] if show_detail:
new_data += report[section_name]['rows']
new_data += [{'voucher_no': section_name, 'amount': report[section_name]['subtotal']}] new_data += [{'voucher_no': section_name, 'amount': report[section_name]['subtotal']}]
summary += [{'label': section_name, 'datatype': 'Currency', 'value': 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 += [{}]
return new_data or data, summary or None return new_data or data, summary or None
def filter_match(value, string): def filter_match(value, string):
"Approximation to datatable filters" "Approximation to datatable filters"
import datetime import datetime
if string == '': return True if string == '':
if value is None: value = -999999999999999 return True
elif isinstance(value, datetime.date): return True if value is None:
value = -999999999999999
elif isinstance(value, datetime.date):
return True
if isinstance(value, str): if isinstance(value, str):
value = value.lower() value = value.lower()
string = string.lower() string = string.lower()
if string[0] == '<': return True if string[1:].strip() else False if string[0] == '<':
elif string[0] == '>': return False if string[1:].strip() else True return True if string[1:].strip() else False
elif string[0] == '=': return string[1:] in value if string[1:] else False elif string[0] == '>':
elif string[0:2] == '!=': return string[2:] not in value 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: elif len(string.split(':')) == 2:
pre, post = string.split(':') pre, post = string.split(':')
return (True if not pre.strip() and post.strip() in value else False) return (True if not pre.strip() and post.strip() in value else False)
@ -114,7 +124,8 @@ def filter_match(value, string):
else: else:
if string[0] in ['<', '>', '=']: if string[0] in ['<', '>', '=']:
operator = string[0] operator = string[0]
if operator == '=': operator = '==' if operator == '=':
operator = '=='
string = string[1:].strip() string = string[1:].strip()
elif string[0:2] == '!=': elif string[0:2] == '!=':
operator = '!=' operator = '!='
@ -132,12 +143,16 @@ def filter_match(value, string):
num = float(string) if string.strip() else 0 num = float(string) if string.strip() else 0
return eval(f'{value} {operator} {num}') return eval(f'{value} {operator} {num}')
except ValueError: except ValueError:
if operator == '<': return True if operator == '<':
return True
return False return False
abbrev = lambda dt: ''.join(l[0].lower() for l in dt.split(' ')) + '.' def abbrev(dt):
doclist = lambda dt, dfs: [abbrev(dt) + f for f in dfs] 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): def as_split(fields):
for field in fields: for field in fields:
@ -165,7 +180,8 @@ def get_columns(fieldlist):
for doctypes, docfields in fieldlist.items(): for doctypes, docfields in fieldlist.items():
fieldmap = {name: new_name for name, new_name in as_split(docfields)} fieldmap = {name: new_name for name, new_name in as_split(docfields)}
for doctype in doctypes: for doctype in doctypes:
if isinstance(doctype, int): break if isinstance(doctype, int):
break
meta = frappe.get_meta(doctype) meta = frappe.get_meta(doctype)
# get column field metadata from the db # get column field metadata from the db
fieldmeta = {} fieldmeta = {}
@ -203,8 +219,10 @@ def modify_report_data(data):
import json import json
new_data = [] new_data = []
for line in data: for line in data:
if line.debit: line.amount = -line.debit if line.debit:
else: line.amount = line.credit line.amount = -line.debit
else:
line.amount = line.credit
# Remove Invoice GL Tax Entries and generate Tax entries from the invoice lines # Remove Invoice GL Tax Entries and generate Tax entries from the invoice lines
if "Invoice" in line.voucher_type: if "Invoice" in line.voucher_type:
if line.account_type != "Tax": if line.account_type != "Tax":
@ -226,7 +244,8 @@ def modify_report_data(data):
new_data += [line] new_data += [line]
return new_data return new_data
####### JS client utilities
# JS client utilities
custom_report_dict = { custom_report_dict = {
'ref_doctype': 'GL Entry', 'ref_doctype': 'GL Entry',

View File

@ -1,6 +1,10 @@
from __future__ import unicode_literals 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 frappe.utils import getdate, add_to_date, get_first_day, get_last_day
from .tax_detail import filter_match, save_custom_report from .tax_detail import filter_match, save_custom_report
@ -38,12 +42,8 @@ class TestTaxDetail(unittest.TestCase):
db_doc.submit() db_doc.submit()
else: else:
db_doc.insert() db_doc.insert()
except frappe.exceptions.DuplicateEntryError as e: except frappe.exceptions.DuplicateEntryError:
pass pass
#print(f'Duplicate Entry: {e}')
except:
print(f'\nError importing {doc["doctype"]}: {doc["name"]}')
raise
self.load_defcols() self.load_defcols()