From 487b4ec1e7aff2c472d8040de08ff27d725d0ae3 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Tue, 19 Nov 2024 22:39:08 +0530 Subject: [PATCH] fix: credit note --- .../gst_india/utils/ve_credit_note.py | 77 +++++++++++++++++++ .../gst_india/utils/ve_sales_import.py | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 india_compliance/gst_india/utils/ve_credit_note.py diff --git a/india_compliance/gst_india/utils/ve_credit_note.py b/india_compliance/gst_india/utils/ve_credit_note.py new file mode 100644 index 000000000..5a6d8d2e9 --- /dev/null +++ b/india_compliance/gst_india/utils/ve_credit_note.py @@ -0,0 +1,77 @@ +import frappe +from erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer import ( + generate_data_from_excel, + get_file, +) +from frappe.utils.data import ( + add_days, + add_months, + add_to_date, + cint, + date_diff, + flt, + get_date_str, + getdate, + nowdate, +) + + +CREDIT_NOTE_ACCOUNT = "Credit Note By Company - VE" + + +def import_invoices(): + file_name = "/private/files/Ledger_Report_19Nov2024_638676311193017942.xlsx" + file_doc, extension = get_file(file_name) + + data = generate_data_from_excel(file_doc, extension, as_dict=True) + + for row in data: + row = frappe._dict(row) + print(row) + print(row.credit, "row.credit") + if row.particulars != "PROCESSING CREDIT NOTE": + continue + + if frappe.db.get_value("Journal Entry", {"bill_no": row.document_no}): + continue + + + date =getdate(row.document_date) + + jv = frappe.new_doc("Journal Entry") + jv.posting_date = date + jv.voucher_type = "Credit Note" + jv.bill_no = row.document_no + jv.bill_date = date + jv.user_remark = row.particulars + + jv.append( + "accounts", + { + "account":"Debtors - VE", + "party_type": "Customer", + "party": row.account_code, + "credit": row.credit, + "debit": 0, + "credit_in_account_currency": row.credit, + "debit_in_account_currency": 0, + }, + ) + + jv.append( + "accounts", + { + "account": CREDIT_NOTE_ACCOUNT, + "debit_in_account_currency": row.credit, + "credit_in_account_currency": 0, + "debit": row.credit, + "credit": 0, + }, + ) + + jv.set_missing_values() + + print(jv.as_dict()) + + jv.insert() + jv.save() diff --git a/india_compliance/gst_india/utils/ve_sales_import.py b/india_compliance/gst_india/utils/ve_sales_import.py index 42ea269cb..76d7ad8bd 100644 --- a/india_compliance/gst_india/utils/ve_sales_import.py +++ b/india_compliance/gst_india/utils/ve_sales_import.py @@ -10,7 +10,7 @@ def import_invoices(): - file_name = "/private/files/Data_20129252_O_20241105023010_7325_E_05Nov2024_638663943037325347.xlsx" + file_name = "/private/files/Data_20129252_CO1_20241119094156_5236_E_19Nov2024_638676297076402496.xlsx" file_doc, extension = get_file(file_name) data = generate_data_from_excel(file_doc, extension, as_dict=True)