feat: default Location tree and Asset Categories
Location fixture: "All Locations" group with Head Office, Branch Office and Warehouse. Fixture import re-inserts tree nodes with fresh lft/rgt, which strands locations users add beneath them, so after_migrate rebuilds the Location tree. Asset Category fixture: Land (non-depreciable), Buildings (20 years), Plant and Machinery, Vehicles, Furniture and Fixtures, Office Equipment, Computers and Electronics, Software (5 years) and Intangible Assets (10 years), per Royal Decree 145 rates; monthly straight-line, daily pro-rata. The accounts table is company-specific and therefore not shipped: an Asset Category before_import hook links every Thai company (same contract as the WHT categories), reusing the Standard chart's fixed asset accounts and creating Land, Vehicles and Intangible Assets under Fixed Assets. Company.on_update links new companies. Depreciation accounts are left to the Company defaults. get_or_create_account now takes account_type and parent_groups.
This commit is contained in:
@@ -43,7 +43,9 @@ def thai_companies():
|
||||
return frappe.get_all("Company", filters={"country": "Thailand"}, pluck="name")
|
||||
|
||||
|
||||
def get_or_create_account(company, account_name, root_type):
|
||||
def get_or_create_account(company, account_name, root_type, account_type="Tax", parent_groups=None):
|
||||
"""Leaf account `account_name` for `company`, created under the first existing
|
||||
group in `parent_groups` (default: PARENT_GROUPS[root_type]), else the root."""
|
||||
name = frappe.db.get_value(
|
||||
"Account", {"company": company, "account_name": account_name, "is_group": 0, "root_type": root_type}
|
||||
)
|
||||
@@ -55,17 +57,19 @@ def get_or_create_account(company, account_name, root_type):
|
||||
"doctype": "Account",
|
||||
"company": company,
|
||||
"account_name": account_name,
|
||||
"parent_account": find_parent_group(company, root_type),
|
||||
"parent_account": find_parent_group(
|
||||
company, root_type, parent_groups or PARENT_GROUPS[root_type]
|
||||
),
|
||||
"root_type": root_type,
|
||||
"account_type": "Tax",
|
||||
"account_type": account_type,
|
||||
"is_group": 0,
|
||||
}
|
||||
).insert(ignore_permissions=True)
|
||||
return account.name
|
||||
|
||||
|
||||
def find_parent_group(company, root_type):
|
||||
for account_name in PARENT_GROUPS[root_type]:
|
||||
def find_parent_group(company, root_type, group_names):
|
||||
for account_name in group_names:
|
||||
parent = frappe.db.get_value(
|
||||
"Account",
|
||||
{"company": company, "account_name": account_name, "is_group": 1, "root_type": root_type},
|
||||
|
||||
Reference in New Issue
Block a user