blob: debfffdcbb3e2f02db7eacdb07c3ca077c0f1d29 [file] [log] [blame]
ruthra kumar3b580552023-07-28 21:02:21 +05301import frappe
ruthra kumaraf52f212023-08-21 14:54:03 +05302from frappe import qb
ruthra kumar3b580552023-07-28 21:02:21 +05303
4from erpnext.stock.doctype.item.test_item import create_item
5
6
7class AccountsTestMixin:
ruthra kumare64b0042023-08-08 20:27:12 +05308 def create_customer(self, customer_name="_Test Customer", currency=None):
ruthra kumar3b580552023-07-28 21:02:21 +05309 if not frappe.db.exists("Customer", customer_name):
10 customer = frappe.new_doc("Customer")
11 customer.customer_name = customer_name
12 customer.type = "Individual"
13
14 if currency:
15 customer.default_currency = currency
16 customer.save()
17 self.customer = customer.name
18 else:
19 self.customer = customer_name
20
ruthra kumare64b0042023-08-08 20:27:12 +053021 def create_supplier(self, supplier_name="_Test Supplier", currency=None):
ruthra kumar3b580552023-07-28 21:02:21 +053022 if not frappe.db.exists("Supplier", supplier_name):
23 supplier = frappe.new_doc("Supplier")
24 supplier.supplier_name = supplier_name
25 supplier.supplier_type = "Individual"
26 supplier.supplier_group = "Local"
27
28 if currency:
29 supplier.default_currency = currency
30 supplier.save()
31 self.supplier = supplier.name
32 else:
33 self.supplier = supplier_name
34
ruthra kumare64b0042023-08-08 20:27:12 +053035 def create_item(self, item_name="_Test Item", is_stock=0, warehouse=None, company=None):
ruthra kumar3b580552023-07-28 21:02:21 +053036 item = create_item(item_name, is_stock_item=is_stock, warehouse=warehouse, company=company)
37 self.item = item.name
38
39 def create_company(self, company_name="_Test Company", abbr="_TC"):
40 self.company_abbr = abbr
41 if frappe.db.exists("Company", company_name):
42 company = frappe.get_doc("Company", company_name)
43 else:
44 company = frappe.get_doc(
45 {
46 "doctype": "Company",
47 "company_name": company_name,
48 "country": "India",
49 "default_currency": "INR",
50 "create_chart_of_accounts_based_on": "Standard Template",
51 "chart_of_accounts": "Standard",
52 }
53 )
54 company = company.save()
55
56 self.company = company.name
57 self.cost_center = company.cost_center
58 self.warehouse = "Stores - " + abbr
59 self.finished_warehouse = "Finished Goods - " + abbr
60 self.income_account = "Sales - " + abbr
61 self.expense_account = "Cost of Goods Sold - " + abbr
62 self.debit_to = "Debtors - " + abbr
63 self.debit_usd = "Debtors USD - " + abbr
64 self.cash = "Cash - " + abbr
65 self.creditors = "Creditors - " + abbr
ruthra kumare64b0042023-08-08 20:27:12 +053066 self.retained_earnings = "Retained Earnings - " + abbr
ruthra kumar3b580552023-07-28 21:02:21 +053067
ruthra kumare64b0042023-08-08 20:27:12 +053068 # Deferred revenue, expense and bank accounts
69 other_accounts = [
70 frappe._dict(
ruthra kumar3b580552023-07-28 21:02:21 +053071 {
ruthra kumare64b0042023-08-08 20:27:12 +053072 "attribute_name": "deferred_revenue",
73 "account_name": "Deferred Revenue",
74 "parent_account": "Current Liabilities - " + abbr,
75 }
76 ),
77 frappe._dict(
78 {
79 "attribute_name": "deferred_expense",
80 "account_name": "Deferred Expense",
81 "parent_account": "Current Assets - " + abbr,
82 }
83 ),
84 frappe._dict(
85 {
86 "attribute_name": "bank",
ruthra kumar3b580552023-07-28 21:02:21 +053087 "account_name": "HDFC",
88 "parent_account": "Bank Accounts - " + abbr,
ruthra kumar3b580552023-07-28 21:02:21 +053089 }
ruthra kumare64b0042023-08-08 20:27:12 +053090 ),
91 ]
92 for acc in other_accounts:
93 acc_name = acc.account_name + " - " + abbr
94 if frappe.db.exists("Account", acc_name):
95 setattr(self, acc.attribute_name, acc_name)
96 else:
97 new_acc = frappe.get_doc(
98 {
99 "doctype": "Account",
100 "account_name": acc.account_name,
101 "parent_account": acc.parent_account,
102 "company": self.company,
103 }
104 )
105 new_acc.save()
106 setattr(self, acc.attribute_name, new_acc.name)
ruthra kumaraf52f212023-08-21 14:54:03 +0530107
108 def clear_old_entries(self):
109 doctype_list = [
110 "GL Entry",
111 "Payment Ledger Entry",
112 "Sales Invoice",
113 "Purchase Invoice",
114 "Payment Entry",
115 "Journal Entry",
116 ]
117 for doctype in doctype_list:
118 qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()