From 06e31e5d7dd4d453f65b728743a62d782b4a133b Mon Sep 17 00:00:00 2001 From: casesolved-co-uk Date: Sat, 10 Apr 2021 00:31:16 +0000 Subject: [PATCH] fix: Test data for empty db --- .../report/tax_detail/test_tax_detail.json | 116 ++++++++++++++++-- .../report/tax_detail/test_tax_detail.py | 50 ++++---- 2 files changed, 132 insertions(+), 34 deletions(-) diff --git a/erpnext/accounts/report/tax_detail/test_tax_detail.json b/erpnext/accounts/report/tax_detail/test_tax_detail.json index 17248d0320..977920a231 100644 --- a/erpnext/accounts/report/tax_detail/test_tax_detail.json +++ b/erpnext/accounts/report/tax_detail/test_tax_detail.json @@ -6,6 +6,98 @@ "default_currency": "GBP", "doctype": "Company", "name": "_T" + },{ + "account_manager": null, + "accounts": [], + "companies": [], + "credit_limits": [], + "customer_details": null, + "customer_group": "All Customer Groups", + "customer_name": "_Test Customer", + "customer_pos_id": null, + "customer_primary_address": null, + "customer_primary_contact": null, + "customer_type": "Company", + "default_bank_account": null, + "default_commission_rate": 0.0, + "default_currency": null, + "default_price_list": null, + "default_sales_partner": null, + "disabled": 0, + "dn_required": 0, + "docstatus": 0, + "doctype": "Customer", + "email_id": null, + "gender": null, + "image": null, + "industry": null, + "is_frozen": 0, + "is_internal_customer": 0, + "language": "en", + "lead_name": null, + "loyalty_program": null, + "loyalty_program_tier": null, + "market_segment": null, + "mobile_no": null, + "modified": "2021-02-15 05:18:03.624724", + "name": "_Test Customer", + "naming_series": "CUST-.YYYY.-", + "pan": null, + "parent": null, + "parentfield": null, + "parenttype": null, + "payment_terms": null, + "primary_address": null, + "represents_company": "", + "sales_team": [], + "salutation": null, + "so_required": 0, + "tax_category": null, + "tax_id": null, + "tax_withholding_category": null, + "territory": "All Territories", + "website": null + },{ + "accounts": [], + "allow_purchase_invoice_creation_without_purchase_order": 0, + "allow_purchase_invoice_creation_without_purchase_receipt": 0, + "companies": [], + "country": "United Kingdom", + "default_bank_account": null, + "default_currency": null, + "default_price_list": null, + "disabled": 0, + "docstatus": 0, + "doctype": "Supplier", + "hold_type": "", + "image": null, + "is_frozen": 0, + "is_internal_supplier": 0, + "is_transporter": 0, + "language": "en", + "modified": "2021-03-31 16:47:10.109316", + "name": "_Test Supplier", + "naming_series": "SUP-.YYYY.-", + "on_hold": 0, + "pan": null, + "parent": null, + "parentfield": null, + "parenttype": null, + "payment_terms": null, + "prevent_pos": 0, + "prevent_rfqs": 0, + "release_date": null, + "represents_company": null, + "supplier_details": null, + "supplier_group": "Raw Material", + "supplier_name": "_Test Supplier", + "supplier_type": "Company", + "tax_category": null, + "tax_id": null, + "tax_withholding_category": null, + "warn_pos": 0, + "warn_rfqs": 0, + "website": null },{ "account_currency": "GBP", "account_name": "Debtors", @@ -251,7 +343,7 @@ "item_name": "Widget Fluid 1Litre", "item_tax_amount": 0.0, "item_tax_rate": "{\"VAT on Purchases - _T\": 20.0}", - "item_tax_template": "Purchase - Standard VAT", + "item_tax_template": null, "landed_cost_voucher_amount": 0.0, "manufacturer": null, "manufacturer_part_no": null, @@ -336,11 +428,11 @@ "shipping_rule": null, "status": "Unpaid", "supplied_items": [], - "supplier": "Raw Materials Inc", + "supplier": "_Test Supplier", "supplier_address": null, - "supplier_name": "Raw Materials Inc", + "supplier_name": "_Test Supplier", "supplier_warehouse": "Stores - _T", - "tax_category": "Other Supplier", + "tax_category": null, "tax_id": null, "tax_withholding_category": null, "taxes": [ @@ -371,7 +463,7 @@ "taxes_and_charges_deducted": 0.0, "tc_name": null, "terms": null, - "title": "Raw Materials Inc", + "title": "_Purchase Invoice", "to_date": null, "total": 426.4, "total_advance": 0.0, @@ -421,10 +513,10 @@ "conversion_rate": 1.0, "cost_center": null, "currency": "GBP", - "customer": "ABC Tyres", + "customer": "_Test Customer", "customer_address": null, "customer_group": "All Customer Groups", - "customer_name": "ABC Tyres", + "customer_name": "_Test Customer", "debit_to": "Debtors - _T", "discount_amount": 0.0, "docstatus": 0, @@ -481,7 +573,7 @@ "item_group": null, "item_name": "Dunlop tyres", "item_tax_rate": "{\"VAT on Sales - _T\": 20.0}", - "item_tax_template": "Sale - Standard VAT", + "item_tax_template": null, "margin_rate_or_amount": 0.0, "margin_type": "", "net_amount": 200.0, @@ -552,7 +644,7 @@ "item_group": null, "item_name": "Continental tyres", "item_tax_rate": "{\"VAT on Sales - _T\": 5.0}", - "item_tax_template": "Sale - Reduced VAT", + "item_tax_template": null, "margin_rate_or_amount": 0.0, "margin_type": "", "net_amount": 65.0, @@ -623,7 +715,7 @@ "item_group": null, "item_name": "Toyo tyres", "item_tax_rate": "{\"VAT on Sales - _T\": 0.0}", - "item_tax_template": "Sale - Zero VAT", + "item_tax_template": null, "margin_rate_or_amount": 0.0, "margin_type": "", "net_amount": 560.0, @@ -735,7 +827,7 @@ "terms": null, "territory": "All Territories", "timesheets": [], - "title": "ABC Tyres", + "title": "_Sales Invoice", "to_date": null, "total": 825.0, "total_advance": 0.0, @@ -752,4 +844,4 @@ "write_off_cost_center": null, "write_off_outstanding_amount_automatically": 0 } -] \ No newline at end of file +] diff --git a/erpnext/accounts/report/tax_detail/test_tax_detail.py b/erpnext/accounts/report/tax_detail/test_tax_detail.py index 614ef8d234..21732b9dfd 100644 --- a/erpnext/accounts/report/tax_detail/test_tax_detail.py +++ b/erpnext/accounts/report/tax_detail/test_tax_detail.py @@ -5,34 +5,27 @@ 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, get_year_start, get_year_ending from .tax_detail import filter_match, save_custom_report class TestTaxDetail(unittest.TestCase): def load_testdocs(self): datapath, _ = os.path.splitext(os.path.realpath(__file__)) with open(datapath + '.json', 'r') as fp: - self.docs = json.load(fp) + docs = json.load(fp) - def load_defcols(self): - custom_report = frappe.get_doc('Report', 'Tax Detail') - self.default_columns, _ = custom_report.run_query_report( - filters={ - 'from_date': '2021-03-01', - 'to_date': '2021-03-31', - 'company': '_T', - 'mode': 'run', - 'report_name': 'Tax Detail' - }, user=frappe.session.user) - - def setUp(self): - "Add Transactions in 01-03-2021 - 31-03-2021" - self.load_testdocs() now = getdate() self.from_date = get_first_day(now) self.to_date = get_last_day(now) - for doc in self.docs: + docs = [{ + "doctype": "Fiscal Year", + "year": "_Test Fiscal", + "year_end_date": get_year_ending(now), + "year_start_date": get_year_start(now) + }] + docs + + for doc in docs: try: db_doc = frappe.get_doc(doc) if 'Invoice' in db_doc.doctype: @@ -45,15 +38,28 @@ class TestTaxDetail(unittest.TestCase): except frappe.exceptions.DuplicateEntryError: pass + def load_defcols(self): + self.company = frappe.get_doc('Company', '_T') + custom_report = frappe.get_doc('Report', 'Tax Detail') + self.default_columns, _ = custom_report.run_query_report( + filters={ + 'from_date': '2021-03-01', + 'to_date': '2021-03-31', + 'company': self.company.name, + 'mode': 'run', + 'report_name': 'Tax Detail' + }, user=frappe.session.user) + + def setUp(self): + self.load_testdocs() self.load_defcols() def tearDown(self): "Remove the Company and all data" from erpnext.setup.doctype.company.delete_company_transactions import delete_company_transactions - for co in filter(lambda doc: doc['doctype'] == 'Company', self.docs): - delete_company_transactions(co['name']) - db_co = frappe.get_doc('Company', co['name']) - db_co.delete() + delete_company_transactions(self.company.name) + self.company.delete() + def test_report(self): report_name = save_custom_report( @@ -78,7 +84,7 @@ class TestTaxDetail(unittest.TestCase): filters={ 'from_date': self.from_date, 'to_date': self.to_date, - 'company': '_T', + 'company': self.company.name, 'mode': 'run', 'report_name': report_name }, user=frappe.session.user)