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: |
| 7 | def create_customer(self, customer_name, currency=None): |
| 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 | |
| 20 | def create_supplier(self, supplier_name, currency=None): |
| 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 | |
| 34 | def create_item(self, item_name, is_stock=0, warehouse=None, company=None): |
| 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 |
| 65 | |
| 66 | # create bank account |
| 67 | bank_account = "HDFC - " + abbr |
| 68 | if frappe.db.exists("Account", bank_account): |
| 69 | self.bank = bank_account |
| 70 | else: |
| 71 | bank_acc = frappe.get_doc( |
| 72 | { |
| 73 | "doctype": "Account", |
| 74 | "account_name": "HDFC", |
| 75 | "parent_account": "Bank Accounts - " + abbr, |
| 76 | "company": self.company, |
| 77 | } |
| 78 | ) |
| 79 | bank_acc.save() |
| 80 | self.bank = bank_acc.name |