fix: Test data for empty db

This commit is contained in:
casesolved-co-uk 2021-04-10 00:31:16 +00:00
parent 391dc45964
commit 06e31e5d7d
2 changed files with 132 additions and 34 deletions

View File

@ -6,6 +6,98 @@
"default_currency": "GBP", "default_currency": "GBP",
"doctype": "Company", "doctype": "Company",
"name": "_T" "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_currency": "GBP",
"account_name": "Debtors", "account_name": "Debtors",
@ -251,7 +343,7 @@
"item_name": "Widget Fluid 1Litre", "item_name": "Widget Fluid 1Litre",
"item_tax_amount": 0.0, "item_tax_amount": 0.0,
"item_tax_rate": "{\"VAT on Purchases - _T\": 20.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, "landed_cost_voucher_amount": 0.0,
"manufacturer": null, "manufacturer": null,
"manufacturer_part_no": null, "manufacturer_part_no": null,
@ -336,11 +428,11 @@
"shipping_rule": null, "shipping_rule": null,
"status": "Unpaid", "status": "Unpaid",
"supplied_items": [], "supplied_items": [],
"supplier": "Raw Materials Inc", "supplier": "_Test Supplier",
"supplier_address": null, "supplier_address": null,
"supplier_name": "Raw Materials Inc", "supplier_name": "_Test Supplier",
"supplier_warehouse": "Stores - _T", "supplier_warehouse": "Stores - _T",
"tax_category": "Other Supplier", "tax_category": null,
"tax_id": null, "tax_id": null,
"tax_withholding_category": null, "tax_withholding_category": null,
"taxes": [ "taxes": [
@ -371,7 +463,7 @@
"taxes_and_charges_deducted": 0.0, "taxes_and_charges_deducted": 0.0,
"tc_name": null, "tc_name": null,
"terms": null, "terms": null,
"title": "Raw Materials Inc", "title": "_Purchase Invoice",
"to_date": null, "to_date": null,
"total": 426.4, "total": 426.4,
"total_advance": 0.0, "total_advance": 0.0,
@ -421,10 +513,10 @@
"conversion_rate": 1.0, "conversion_rate": 1.0,
"cost_center": null, "cost_center": null,
"currency": "GBP", "currency": "GBP",
"customer": "ABC Tyres", "customer": "_Test Customer",
"customer_address": null, "customer_address": null,
"customer_group": "All Customer Groups", "customer_group": "All Customer Groups",
"customer_name": "ABC Tyres", "customer_name": "_Test Customer",
"debit_to": "Debtors - _T", "debit_to": "Debtors - _T",
"discount_amount": 0.0, "discount_amount": 0.0,
"docstatus": 0, "docstatus": 0,
@ -481,7 +573,7 @@
"item_group": null, "item_group": null,
"item_name": "Dunlop tyres", "item_name": "Dunlop tyres",
"item_tax_rate": "{\"VAT on Sales - _T\": 20.0}", "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_rate_or_amount": 0.0,
"margin_type": "", "margin_type": "",
"net_amount": 200.0, "net_amount": 200.0,
@ -552,7 +644,7 @@
"item_group": null, "item_group": null,
"item_name": "Continental tyres", "item_name": "Continental tyres",
"item_tax_rate": "{\"VAT on Sales - _T\": 5.0}", "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_rate_or_amount": 0.0,
"margin_type": "", "margin_type": "",
"net_amount": 65.0, "net_amount": 65.0,
@ -623,7 +715,7 @@
"item_group": null, "item_group": null,
"item_name": "Toyo tyres", "item_name": "Toyo tyres",
"item_tax_rate": "{\"VAT on Sales - _T\": 0.0}", "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_rate_or_amount": 0.0,
"margin_type": "", "margin_type": "",
"net_amount": 560.0, "net_amount": 560.0,
@ -735,7 +827,7 @@
"terms": null, "terms": null,
"territory": "All Territories", "territory": "All Territories",
"timesheets": [], "timesheets": [],
"title": "ABC Tyres", "title": "_Sales Invoice",
"to_date": null, "to_date": null,
"total": 825.0, "total": 825.0,
"total_advance": 0.0, "total_advance": 0.0,

View File

@ -5,34 +5,27 @@ import unittest
import datetime import datetime
import json import json
import os 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 from .tax_detail import filter_match, save_custom_report
class TestTaxDetail(unittest.TestCase): class TestTaxDetail(unittest.TestCase):
def load_testdocs(self): def load_testdocs(self):
datapath, _ = os.path.splitext(os.path.realpath(__file__)) datapath, _ = os.path.splitext(os.path.realpath(__file__))
with open(datapath + '.json', 'r') as fp: 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() now = getdate()
self.from_date = get_first_day(now) self.from_date = get_first_day(now)
self.to_date = get_last_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: try:
db_doc = frappe.get_doc(doc) db_doc = frappe.get_doc(doc)
if 'Invoice' in db_doc.doctype: if 'Invoice' in db_doc.doctype:
@ -45,15 +38,28 @@ class TestTaxDetail(unittest.TestCase):
except frappe.exceptions.DuplicateEntryError: except frappe.exceptions.DuplicateEntryError:
pass 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() self.load_defcols()
def tearDown(self): def tearDown(self):
"Remove the Company and all data" "Remove the Company and all data"
from erpnext.setup.doctype.company.delete_company_transactions import delete_company_transactions 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(self.company.name)
delete_company_transactions(co['name']) self.company.delete()
db_co = frappe.get_doc('Company', co['name'])
db_co.delete()
def test_report(self): def test_report(self):
report_name = save_custom_report( report_name = save_custom_report(
@ -78,7 +84,7 @@ class TestTaxDetail(unittest.TestCase):
filters={ filters={
'from_date': self.from_date, 'from_date': self.from_date,
'to_date': self.to_date, 'to_date': self.to_date,
'company': '_T', 'company': self.company.name,
'mode': 'run', 'mode': 'run',
'report_name': report_name 'report_name': report_name
}, user=frappe.session.user) }, user=frappe.session.user)