ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 1 | import frappe |
| 2 | |
| 3 | from erpnext.stock.doctype.item.test_item import create_item |
| 4 | |
| 5 | |
| 6 | class AccountsTestMixin: |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 7 | def create_customer(self, customer_name="_Test Customer", currency=None): |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 8 | if not frappe.db.exists("Customer", customer_name): |
| 9 | customer = frappe.new_doc("Customer") |
| 10 | customer.customer_name = customer_name |
| 11 | customer.type = "Individual" |
| 12 | |
| 13 | if currency: |
| 14 | customer.default_currency = currency |
| 15 | customer.save() |
| 16 | self.customer = customer.name |
| 17 | else: |
| 18 | self.customer = customer_name |
| 19 | |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 20 | def create_supplier(self, supplier_name="_Test Supplier", currency=None): |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 21 | if not frappe.db.exists("Supplier", supplier_name): |
| 22 | supplier = frappe.new_doc("Supplier") |
| 23 | supplier.supplier_name = supplier_name |
| 24 | supplier.supplier_type = "Individual" |
| 25 | supplier.supplier_group = "Local" |
| 26 | |
| 27 | if currency: |
| 28 | supplier.default_currency = currency |
| 29 | supplier.save() |
| 30 | self.supplier = supplier.name |
| 31 | else: |
| 32 | self.supplier = supplier_name |
| 33 | |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 34 | def create_item(self, item_name="_Test Item", is_stock=0, warehouse=None, company=None): |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 35 | item = create_item(item_name, is_stock_item=is_stock, warehouse=warehouse, company=company) |
| 36 | self.item = item.name |
| 37 | |
| 38 | def create_company(self, company_name="_Test Company", abbr="_TC"): |
| 39 | self.company_abbr = abbr |
| 40 | if frappe.db.exists("Company", company_name): |
| 41 | company = frappe.get_doc("Company", company_name) |
| 42 | else: |
| 43 | company = frappe.get_doc( |
| 44 | { |
| 45 | "doctype": "Company", |
| 46 | "company_name": company_name, |
| 47 | "country": "India", |
| 48 | "default_currency": "INR", |
| 49 | "create_chart_of_accounts_based_on": "Standard Template", |
| 50 | "chart_of_accounts": "Standard", |
| 51 | } |
| 52 | ) |
| 53 | company = company.save() |
| 54 | |
| 55 | self.company = company.name |
| 56 | self.cost_center = company.cost_center |
| 57 | self.warehouse = "Stores - " + abbr |
| 58 | self.finished_warehouse = "Finished Goods - " + abbr |
| 59 | self.income_account = "Sales - " + abbr |
| 60 | self.expense_account = "Cost of Goods Sold - " + abbr |
| 61 | self.debit_to = "Debtors - " + abbr |
| 62 | self.debit_usd = "Debtors USD - " + abbr |
| 63 | self.cash = "Cash - " + abbr |
| 64 | self.creditors = "Creditors - " + abbr |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 65 | self.retained_earnings = "Retained Earnings - " + abbr |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 66 | |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 67 | # Deferred revenue, expense and bank accounts |
| 68 | other_accounts = [ |
| 69 | frappe._dict( |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 70 | { |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 71 | "attribute_name": "deferred_revenue", |
| 72 | "account_name": "Deferred Revenue", |
| 73 | "parent_account": "Current Liabilities - " + abbr, |
| 74 | } |
| 75 | ), |
| 76 | frappe._dict( |
| 77 | { |
| 78 | "attribute_name": "deferred_expense", |
| 79 | "account_name": "Deferred Expense", |
| 80 | "parent_account": "Current Assets - " + abbr, |
| 81 | } |
| 82 | ), |
| 83 | frappe._dict( |
| 84 | { |
| 85 | "attribute_name": "bank", |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 86 | "account_name": "HDFC", |
| 87 | "parent_account": "Bank Accounts - " + abbr, |
ruthra kumar | 3b58055 | 2023-07-28 21:02:21 +0530 | [diff] [blame] | 88 | } |
ruthra kumar | e64b004 | 2023-08-08 20:27:12 +0530 | [diff] [blame^] | 89 | ), |
| 90 | ] |
| 91 | for acc in other_accounts: |
| 92 | acc_name = acc.account_name + " - " + abbr |
| 93 | if frappe.db.exists("Account", acc_name): |
| 94 | setattr(self, acc.attribute_name, acc_name) |
| 95 | else: |
| 96 | new_acc = frappe.get_doc( |
| 97 | { |
| 98 | "doctype": "Account", |
| 99 | "account_name": acc.account_name, |
| 100 | "parent_account": acc.parent_account, |
| 101 | "company": self.company, |
| 102 | } |
| 103 | ) |
| 104 | new_acc.save() |
| 105 | setattr(self, acc.attribute_name, new_acc.name) |