From 333f2a565bd357809f154d40c19d9fd565b5afc8 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 1 Aug 2023 10:10:50 +0530 Subject: [PATCH] fix: Add journal entry in demo --- erpnext/hooks.py | 2 +- erpnext/setup/demo.py | 27 ++++++++++++++-------- erpnext/setup/demo_data/journal_entry.json | 25 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 erpnext/setup/demo_data/journal_entry.json diff --git a/erpnext/hooks.py b/erpnext/hooks.py index e5d9318603..a9eef94457 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -78,7 +78,7 @@ demo_master_doctypes = [ "customer", "supplier", ] -demo_transaction_doctypes = ["purchase_invoice", "sales_invoice", "payment_entry"] +demo_transaction_doctypes = ["purchase_invoice", "sales_invoice", "payment_entry", "journal_entry"] jinja = { "methods": [ diff --git a/erpnext/setup/demo.py b/erpnext/setup/demo.py index a6d90eda96..50bc43d325 100644 --- a/erpnext/setup/demo.py +++ b/erpnext/setup/demo.py @@ -83,7 +83,9 @@ def create_transaction(doctype, company, start_date): posting_date = ( start_date if doctype.get("doctype") == "Purchase Invoice" else get_random_date(start_date) ) - bank_account = frappe.db.get_value("Company", company, "default_bank_account") + bank_account, default_receivable_account = frappe.db.get_value( + "Company", company, ["default_bank_account", "default_receivable_account"] + ) bank_field = "paid_to" if doctype.get("party_type") == "Customer" else "paid_from" doctype.update( @@ -101,20 +103,27 @@ def create_transaction(doctype, company, start_date): "Company", company, ["default_income_account", "default_expense_account"] ) - for item in doctype.get("items") or []: - item.update( - { - "cost_center": erpnext.get_default_cost_center(company), - "income_account": income_account, - "expense_account": expense_account, - } - ) + if doctype in ("Purchase Invoice", "Sales Invoice"): + for item in doctype.get("items") or []: + item.update( + { + "cost_center": erpnext.get_default_cost_center(company), + "income_account": income_account, + "expense_account": expense_account, + } + ) + elif doctype == "Journal Entry": + pass + # update_accounts(doctype, bank_account, default_receivable_account) doc = frappe.get_doc(doctype) doc.save(ignore_permissions=True) doc.submit() +# def update_accounts(doctype, company, bank_account): + + def get_random_date(start_date): return add_days(start_date, randint(1, 365)) diff --git a/erpnext/setup/demo_data/journal_entry.json b/erpnext/setup/demo_data/journal_entry.json new file mode 100644 index 0000000000..b751c7cf24 --- /dev/null +++ b/erpnext/setup/demo_data/journal_entry.json @@ -0,0 +1,25 @@ +[ + { + "cheque_date": "2023-03-14", + "cheque_no": "33", + "doctype": "Journal Entry", + "accounts": [ + { + "party_type": "Customer", + "party": "ABC Enterprises", + "credit_in_account_currency": 40000.0, + "debit_in_account_currency": 0.0, + "doctype": "Journal Entry Account", + "parentfield": "accounts", + }, + { + "credit_in_account_currency": 0.0, + "debit_in_account_currency": 40000.0, + "doctype": "Journal Entry Account", + "parentfield": "accounts", + } + ], + "user_remark": "test", + "voucher_type": "Bank Entry" + } +] \ No newline at end of file