fix: Create transactions

This commit is contained in:
Deepesh Garg 2023-06-16 13:43:55 +05:30
parent 8ef257abbc
commit 77a29574a6
13 changed files with 320 additions and 405 deletions

View File

@ -669,6 +669,7 @@ def get_payment_terms_template(party_name, party_type, company=None):
if party_type not in ("Customer", "Supplier"):
return
template = None
print(party_type, party_name)
if party_type == "Customer":
customer = frappe.get_cached_value(
"Customer", party_name, fieldname=["payment_terms", "customer_group"], as_dict=1

View File

@ -70,7 +70,15 @@ treeviews = [
"Department",
]
demo_doctypes = ["items"]
demo_master_doctypes = [
"item_group",
"item",
"customer_group",
"supplier_group",
"customer",
"supplier",
]
demo_transaction_doctypes = ["purchase_invoice", "sales_invoice"]
jinja = {
"methods": [

View File

@ -6,12 +6,20 @@ import os
import frappe
import erpnext
@frappe.whitelist()
def setup_demo_data():
create_demo_company()
process_demo_data()
make_transactions()
company = create_demo_company()
process_masters()
make_transactions(company)
@frappe.whitelist()
def clear_demo_data():
company = frappe.db.get_single_value("Global Defaults", "demo_company")
create_transaction_deletion_record(company)
def create_demo_company():
@ -29,9 +37,12 @@ def create_demo_company():
new_company.chart_of_accounts = company_doc.chart_of_accounts
new_company.insert()
frappe.db.set_single_value("Global Defaults", "demo_company", new_company.name)
return new_company.name
def process_demo_data():
demo_doctypes = frappe.get_hooks("demo_doctypes") or []
def process_masters():
demo_doctypes = frappe.get_hooks("demo_master_doctypes") or []
path = os.path.join(os.path.dirname(__file__), "demo_data")
for doctype in demo_doctypes:
with open(os.path.join(path, doctype + ".json"), "r") as f:
@ -45,5 +56,40 @@ def create_demo_record(doctype):
frappe.get_doc(doctype).insert(ignore_permissions=True)
def make_transactions():
pass
def make_transactions(company):
transaction_doctypes = frappe.get_hooks("demo_transaction_doctypes") or []
path = os.path.join(os.path.dirname(__file__), "demo_data")
for transaction in transaction_doctypes:
with open(os.path.join(path, transaction + ".json"), "r") as f:
data = f.read()
if data:
for item in json.loads(data):
create_transaction(item, company)
def create_transaction(doctype, company):
doctype.update({"company": company})
income_account, expense_account = frappe.db.get_value(
"Company", company, ["default_income_account", "default_expense_account"]
)
for item in doctype.get("items"):
item.update(
{
"cost_center": erpnext.get_default_cost_center(company),
"income_account": income_account,
"expense_account": expense_account,
}
)
doc = frappe.get_doc(doctype)
doc.save(ignore_permissions=True)
doc.submit()
def create_transaction_deletion_record(company):
transaction_deletion_record = frappe.new_doc("Transaction Deletion Record")
transaction_deletion_record.company = company
transaction_deletion_record.save(ignore_permissions=True)
transaction_deletion_record.submit()

View File

@ -0,0 +1,17 @@
[
{
"doctype": "Customer",
"customer_group": "Demo Customer Group",
"customer_name": "ABC Enterprises"
},
{
"doctype": "Customer",
"customer_group": "Demo Customer Group",
"customer_name": "XYZ Corporation"
},
{
"doctype": "Customer",
"customer_group": "Demo Customer Group",
"customer_name": "KJPR Pvt Ltd"
}
]

View File

@ -0,0 +1,6 @@
[
{
"doctype": "Customer Group",
"customer_group_name": "Demo Customer Group"
}
]

View File

@ -0,0 +1,71 @@
[
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU001",
"item_name": "T-shirt",
"image": "https://media.istockphoto.com/id/1281631373/vector/mockup-template-men-black-t-shirt-short-sleeve.jpg?s=612x612&w=0&k=20&c=SfYrtFXQS2wJ1-R9ozvxhUabJz3cnmH5HXv2sXW_mZk="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU002",
"item_name": "Laptop",
"image": "https://media.istockphoto.com/id/1297051332/vector/levitation-laptop-mockup.jpg?s=612x612&w=0&k=20&c=E9rp9HY7CaPjjsnZlg8NYBTFOGy7gfBSL7oK6wv5VnY="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU003",
"item_name": "Book",
"image": "https://media.istockphoto.com/id/950152244/vector/vector-mock-up-of-standing-book.jpg?s=612x612&w=0&k=20&c=oDF2LeFoAcPAwJZFEVjWRvT53sMmCQwkVj-3qYy1duw="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU004",
"item_name": "Smartphone",
"image": "https://media.istockphoto.com/id/1308145590/vector/realistic-mobile-phone-mockup-template-isolated-stock-vector.jpg?s=612x612&w=0&k=20&c=63UyujU3S9kAkUh3MXdJcr10xelDjgVyQzRx5Sh5018="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU005",
"item_name": "Sneakers",
"image": "https://media.istockphoto.com/id/1303978937/photo/white-sneaker-on-a-blue-gradient-background-mens-fashion-sport-shoe-sneakers-lifestyle.jpg?s=612x612&w=0&k=20&c=L725fuzFTnm6qEaqE7Urc5q6IR80EgYQEjBn_qtBIQg="
},
{
"doctype": "Item",
"item_code": "SKU006",
"item_name": "Coffee Mug",
"image": "https://media.istockphoto.com/id/821282266/photo/white-mug-isolated.jpg?s=612x612&w=0&k=20&c=LJCMPk0D83OKmJHahkiLzAB3OsKr83nMbL7KxSgfpfM="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU007",
"item_name": "Television",
"image": "https://media.istockphoto.com/id/1002728980/vector/wide-tv-monitor-mockup.jpg?s=612x612&w=0&k=20&c=1gDEH7ppC9ap8UBuIQmO1gM_Z8VeEaEUDDo-Aw_k8qs="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU008",
"item_name": "Backpack",
"image": "https://media.istockphoto.com/id/1141208525/photo/yellow-open-backpack.jpg?s=612x612&w=0&k=20&c=k0NOqN9FnIGdkaUNx6-fMIBG2IfWwLT_AbDVefqJT_0="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU009",
"item_name": "Headphones",
"image": "https://media.istockphoto.com/id/860853774/photo/blue-headphones-isolated-on-a-white-background.jpg?s=612x612&w=0&k=20&c=KqMSLWuM_Prrq5XHTe79bnFRU_leFDaXTuKqup5uvrE="
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU010",
"item_name": "Camera",
"image": "https://media.istockphoto.com/id/185278433/photo/black-digital-slr-camera-in-a-white-background.jpg?s=612x612&w=0&k=20&c=OOCbhvOF0W-eVhhrm-TxbgLfbKhFfs4Lprjd7hiQBNU="
}
]

View File

@ -0,0 +1,7 @@
[
{
"doctype": "Item Group",
"item_group_name": "Demo Item Group",
"parent_item_group": "All Item Groups"
}
]

View File

@ -1,62 +0,0 @@
[
{
"doctype": "Item",
"item_code": "SKU001",
"item_name": "T-shirt",
"image": "https://www.shutterstock.com/image-photo/close-man-blank-tshirt-140861086"
},
{
"doctype": "Item",
"item_code": "SKU002",
"item_name": "Laptop",
"image": "https://www.shutterstock.com/image-photo/laptop-computer-blank-screen-isolated-on-1721445466"
},
{
"doctype": "Item",
"item_code": "SKU003",
"item_name": "Book",
"image": "https://www.shutterstock.com/image-vector/blank-vertical-book-cover-template-pages-172777709"
},
{
"doctype": "Item",
"item_code": "SKU004",
"item_name": "Smartphone",
"image": "https://www.shutterstock.com/image-vector/realistic-smartphone-mockup-front-back-1450789832"
},
{
"doctype": "Item",
"item_code": "SKU005",
"item_name": "Sneakers",
"image": "https://www.shutterstock.com/image-photo/white-sneaker-sport-shoe-on-purple-2155395817"
},
{
"doctype": "Item",
"item_code": "SKU006",
"item_name": "Coffee Mug",
"image": "https://www.shutterstock.com/image-vector/realistic-white-cup-isolated-on-transparent-585104080"
},
{
"doctype": "Item",
"item_code": "SKU007",
"item_name": "Television",
"image": "https://www.shutterstock.com/image-photo/tv-flat-screen-lcd-plasma-realistic-314401364"
},
{
"doctype": "Item",
"item_code": "SKU008",
"item_name": "Backpack",
"image": "https://www.shutterstock.com/image-photo/school-backpack-on-white-background-1440715766"
},
{
"doctype": "Item",
"item_code": "SKU009",
"item_name": "Headphones",
"image": "https://www.shutterstock.com/image-illustration/3d-rendering-yellow-headphones-isolated-on-1833307018"
},
{
"doctype": "Item",
"item_code": "SKU010",
"item_name": "Camera",
"image": "https://www.shutterstock.com/image-photo/camera-610909205"
}
]

View File

@ -0,0 +1,17 @@
[
{
"conversion_rate": 1.0,
"supplier": "DQ Industries",
"doctype": "Purchase Invoice",
"items": [
{
"doctype": "Purchase Invoice Item",
"item_code": "SKU004",
"parentfield": "items",
"qty": 20.0,
"rate": 400.0,
"conversion_factor": 1
}
]
}
]

View File

@ -0,0 +1,17 @@
[
{
"conversion_rate": 1.0,
"customer": "ABC Enterprises",
"doctype": "Sales Invoice",
"items": [
{
"doctype": "Sales Invoice Item",
"item_code": "SKU004",
"parentfield": "items",
"qty": 20.0,
"rate": 500.0,
"conversion_factor": 1
}
]
}
]

View File

@ -0,0 +1,17 @@
[
{
"doctype": "Supplier",
"supplier_group": "Demo Supplier Group",
"supplier_name": "DQ Industries"
},
{
"doctype": "Supplier",
"supplier_group": "Demo Supplier Group",
"supplier_name": "MA Inc."
},
{
"doctype": "Supplier",
"supplier_group": "Demo Supplier Group",
"supplier_name": "KC Corp."
}
]

View File

@ -0,0 +1,6 @@
[
{
"doctype": "Supplier Group",
"supplier_group_name": "Demo Supplier Group"
}
]

View File

@ -1,352 +1,116 @@
{
"allow_copy": 1,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2013-05-02 17:53:24",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"editable_grid": 0,
"actions": [],
"allow_copy": 1,
"creation": "2013-05-02 17:53:24",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"default_company",
"current_fiscal_year",
"country",
"default_distance_unit",
"column_break_8",
"default_currency",
"hide_currency_symbol",
"disable_rounded_total",
"disable_in_words",
"demo_company"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "default_company",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Default Company",
"length": 0,
"no_copy": 0,
"options": "Company",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "default_company",
"fieldtype": "Link",
"ignore_user_permissions": 1,
"label": "Default Company",
"options": "Company"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "current_fiscal_year",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Current Fiscal Year",
"length": 0,
"no_copy": 0,
"options": "Fiscal Year",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "current_fiscal_year",
"fieldtype": "Link",
"label": "Current Fiscal Year",
"options": "Fiscal Year",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "country",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Country",
"length": 0,
"no_copy": 0,
"options": "Country",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "country",
"fieldtype": "Link",
"label": "Country",
"options": "Country"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "",
"fieldname": "default_distance_unit",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Default Distance Unit",
"length": 0,
"no_copy": 0,
"options": "UOM",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "default_distance_unit",
"fieldtype": "Link",
"label": "Default Distance Unit",
"options": "UOM"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_8",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fieldname": "column_break_8",
"fieldtype": "Column Break"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "INR",
"fieldname": "default_currency",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Default Currency",
"length": 0,
"no_copy": 0,
"options": "Currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"default": "INR",
"fieldname": "default_currency",
"fieldtype": "Link",
"ignore_user_permissions": 1,
"in_list_view": 1,
"label": "Default Currency",
"options": "Currency",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "Do not show any symbol like $ etc next to currencies.",
"fieldname": "hide_currency_symbol",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Hide Currency Symbol",
"length": 0,
"no_copy": 0,
"options": "\nNo\nYes",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"description": "Do not show any symbol like $ etc next to currencies.",
"fieldname": "hide_currency_symbol",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Hide Currency Symbol",
"options": "\nNo\nYes"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "If disable, 'Rounded Total' field will not be visible in any transaction",
"fieldname": "disable_rounded_total",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Disable Rounded Total",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"default": "0",
"description": "If disable, 'Rounded Total' field will not be visible in any transaction",
"fieldname": "disable_rounded_total",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Disable Rounded Total"
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "If disable, 'In Words' field will not be visible in any transaction",
"fieldname": "disable_in_words",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Disable In Words",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
"default": "0",
"description": "If disable, 'In Words' field will not be visible in any transaction",
"fieldname": "disable_in_words",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Disable In Words"
},
{
"fieldname": "demo_company",
"fieldtype": "Link",
"hidden": 1,
"label": "Demo Company",
"options": "Company",
"read_only": 1
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "fa fa-cog",
"idx": 1,
"image_view": 0,
"in_create": 1,
"is_submittable": 0,
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2018-10-15 03:08:19.886212",
"modified_by": "Administrator",
"module": "Setup",
"name": "Global Defaults",
"owner": "Administrator",
],
"icon": "fa fa-cog",
"idx": 1,
"in_create": 1,
"issingle": 1,
"links": [],
"modified": "2023-06-16 13:03:45.016191",
"modified_by": "Administrator",
"module": "Setup",
"name": "Global Defaults",
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"cancel": 0,
"create": 1,
"delete": 0,
"email": 0,
"export": 0,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 0,
"read": 1,
"report": 0,
"role": "System Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"create": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 0,
"read_only": 1,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0,
"track_views": 0
],
"read_only": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}