feat: maintain tally voucher numbers

feat: create seperate customer and supplier entries for same party if
case exists

(cherry picked from commit af612ddb6d)
This commit is contained in:
Gavin D'souza
2020-05-01 14:39:11 +05:30
committed by mergify-bot
parent d50cceaafa
commit 8ea9b0a415

View File

@@ -145,14 +145,18 @@ class TallyMigration(Document):
def remove_parties(parents, children, group_set): def remove_parties(parents, children, group_set):
customers, suppliers = set(), set() customers, suppliers = set(), set()
for account in parents: for account in parents:
found = False
if self.tally_creditors_account in parents[account]: if self.tally_creditors_account in parents[account]:
children.pop(account, None) found = True
if account not in group_set: if account not in group_set:
suppliers.add(account) suppliers.add(account)
elif self.tally_debtors_account in parents[account]: if self.tally_debtors_account in parents[account]:
children.pop(account, None) found = True
if account not in group_set: if account not in group_set:
customers.add(account) customers.add(account)
if found:
children.pop(account, None)
return children, customers, suppliers return children, customers, suppliers
def traverse(tree, children, accounts, roots, group_set): def traverse(tree, children, accounts, roots, group_set):
@@ -170,6 +174,7 @@ class TallyMigration(Document):
parties, addresses = [], [] parties, addresses = [], []
for account in collection.find_all("LEDGER"): for account in collection.find_all("LEDGER"):
party_type = None party_type = None
links = []
if account.NAME.string.strip() in customers: if account.NAME.string.strip() in customers:
party_type = "Customer" party_type = "Customer"
parties.append({ parties.append({
@@ -180,7 +185,9 @@ class TallyMigration(Document):
"territory": "All Territories", "territory": "All Territories",
"customer_type": "Individual", "customer_type": "Individual",
}) })
elif account.NAME.string.strip() in suppliers: links.append({"link_doctype": party_type, "link_name": account["NAME"]})
if account.NAME.string.strip() in suppliers:
party_type = "Supplier" party_type = "Supplier"
parties.append({ parties.append({
"doctype": party_type, "doctype": party_type,
@@ -189,6 +196,8 @@ class TallyMigration(Document):
"supplier_group": "All Supplier Groups", "supplier_group": "All Supplier Groups",
"supplier_type": "Individual", "supplier_type": "Individual",
}) })
links.append({"link_doctype": party_type, "link_name": account["NAME"]})
if party_type: if party_type:
address = "\n".join([a.string.strip() for a in account.find_all("ADDRESS")]) address = "\n".join([a.string.strip() for a in account.find_all("ADDRESS")])
addresses.append({ addresses.append({
@@ -202,7 +211,7 @@ class TallyMigration(Document):
"mobile": account.LEDGERPHONE.string.strip() if account.LEDGERPHONE else None, "mobile": account.LEDGERPHONE.string.strip() if account.LEDGERPHONE else None,
"phone": account.LEDGERPHONE.string.strip() if account.LEDGERPHONE else None, "phone": account.LEDGERPHONE.string.strip() if account.LEDGERPHONE else None,
"gstin": account.PARTYGSTIN.string.strip() if account.PARTYGSTIN else None, "gstin": account.PARTYGSTIN.string.strip() if account.PARTYGSTIN else None,
"links": [{"link_doctype": party_type, "link_name": account["NAME"]}], "links": links
}) })
return parties, addresses return parties, addresses
@@ -378,6 +387,7 @@ class TallyMigration(Document):
journal_entry = { journal_entry = {
"doctype": "Journal Entry", "doctype": "Journal Entry",
"tally_guid": voucher.GUID.string.strip(), "tally_guid": voucher.GUID.string.strip(),
"tally_voucher_no": voucher.VOUCHERNUMBER.string.strip() if voucher.VOUCHERNUMBER else "",
"posting_date": voucher.DATE.string.strip(), "posting_date": voucher.DATE.string.strip(),
"company": self.erpnext_company, "company": self.erpnext_company,
"accounts": accounts, "accounts": accounts,
@@ -406,6 +416,7 @@ class TallyMigration(Document):
"doctype": doctype, "doctype": doctype,
party_field: voucher.PARTYNAME.string.strip(), party_field: voucher.PARTYNAME.string.strip(),
"tally_guid": voucher.GUID.string.strip(), "tally_guid": voucher.GUID.string.strip(),
"tally_voucher_no": voucher.VOUCHERNUMBER.string.strip() if voucher.VOUCHERNUMBER else "",
"posting_date": voucher.DATE.string.strip(), "posting_date": voucher.DATE.string.strip(),
"due_date": voucher.DATE.string.strip(), "due_date": voucher.DATE.string.strip(),
"items": get_voucher_items(voucher, doctype), "items": get_voucher_items(voucher, doctype),
@@ -497,14 +508,21 @@ class TallyMigration(Document):
oldest_year = new_year oldest_year = new_year
def create_custom_fields(doctypes): def create_custom_fields(doctypes):
df = { tally_guid_df = {
"fieldtype": "Data", "fieldtype": "Data",
"fieldname": "tally_guid", "fieldname": "tally_guid",
"read_only": 1, "read_only": 1,
"label": "Tally GUID" "label": "Tally GUID"
} }
for doctype in doctypes: tally_voucher_no_df = {
create_custom_field(doctype, df) "fieldtype": "Data",
"fieldname": "tally_voucher_no",
"read_only": 1,
"label": "Tally Voucher Number"
}
for df in [tally_guid_df, tally_voucher_no_df]:
for doctype in doctypes:
create_custom_field(doctype, df)
def create_price_list(): def create_price_list():
frappe.get_doc({ frappe.get_doc({