Skip to content

Commit

Permalink
Merge pull request #39 from 8848digital/cleatax_group_id
Browse files Browse the repository at this point in the history
generate group id
  • Loading branch information
Satya8848 authored Feb 20, 2024
2 parents 396d07c + e2e1f43 commit 6cdcc66
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
9 changes: 6 additions & 3 deletions gst_india/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@
},
"Purchase Invoice": {
"validate": "gst_india.gst_india.overrides.purchase_invoice.validate",
"before_submit": "gst_india.public.py.purchase_invoice_doctype.purchase_invoice_submit",
"before_submit": ["gst_india.public.py.purchase_invoice_doctype.group_id",
"gst_india.public.py.purchase_invoice_doctype.purchase_invoice_submit"],
"before_cancel": "gst_india.public.py.purchase_invoice_doctype.purchase_invoice_cancel",
"before_save": "gst_india.public.py.purchase_invoice_doctype.purchase_invoice_save"
"before_save": "gst_india.public.py.purchase_invoice_doctype.purchase_invoice_save",
"on_submit":"gst_india.public.py.purchase_invoice_doctype.group_id"
},
"Purchase Order": {
"validate": (
Expand All @@ -111,8 +113,9 @@
},
"Sales Invoice": {
"onload": "gst_india.gst_india.overrides.sales_invoice.onload",
"validate": "gst_india.gst_india.overrides.sales_invoice.validate",
"validate": ["gst_india.gst_india.overrides.sales_invoice.validate","gst_india.public.py.sales_invoice_doctype.group_id"],
"on_submit": ["gst_india.gst_india.overrides.sales_invoice.on_submit",
"gst_india.public.py.sales_invoice_doctype.sales_invoice_submit",
"gst_india.public.py.sales_invoice_doctype.sales_invoice_submit"],
"before_cancel": "gst_india.public.py.sales_invoice_doctype.sales_invoice_cancel",
"before_save": "gst_india.public.py.sales_invoice_doctype.sales_invoice_save"
Expand Down
26 changes: 25 additions & 1 deletion gst_india/public/py/purchase_invoice_doctype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import frappe
from gst_india.cleartax_integration.API.gst import create_gst_invoice

import secrets
import string

def purchase_invoice_submit(doc, method=None):
if frappe.db.get_single_value('Cleartax Settings','automate'):
Expand All @@ -27,6 +28,29 @@ def purchase_invoice_save(doc,method=None):
if doc.taxes_and_charges_added <= 0:
doc.custom_non_gst = 1

def generate_random_id(length=12):
characters = string.ascii_letters + string.digits
random_id = ''.join(secrets.choice(characters) for _ in range(length))
return random_id

def group_id(doc,method=None):
# pan_no=frappe.db.get_value("Customer",doc.customer,'pan')

random_id = generate_random_id()
exist=frappe.db.exists("Generate Group ID", {"pan": doc.supplier_pan})
if exist:
doc.custom_group_id=frappe.db.get_value("Generate Group ID",exist,"random_id")
else:
new_doc=frappe.new_doc("Generate Group ID")
new_doc.pan=doc.supplier_pan
new_doc.pan_no=doc.supplier_pan
new_doc.random_id = random_id
new_doc.document_no=doc.name
new_doc.dacument_type='Purchase Invoice'
new_doc.save()
doc.custom_group_id = random_id





27 changes: 26 additions & 1 deletion gst_india/public/py/sales_invoice_doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from gst_india.cleartax_integration.API.gst import create_gst_invoice
import frappe
from frappe.utils import flt

import secrets
import string
def sales_invoice_submit(doc, method=None):
if frappe.db.get_single_value('Cleartax Settings','automate'):
if e_invoicing_enabled(company=doc.company):
Expand Down Expand Up @@ -32,3 +33,27 @@ def sales_invoice_save(doc,method=None):
doc.custom_non_gst = 1


def generate_random_id(length=12):
characters = string.ascii_letters + string.digits
random_id = ''.join(secrets.choice(characters) for _ in range(length))
return random_id


def group_id(doc,method=None):
print("----------------------")
pan_no=frappe.db.get_value("Customer",doc.customer,'pan')

random_id = generate_random_id()
exist=frappe.db.exists("Generate Group ID", {"pan": pan_no})
if exist:
frappe.msgprint('Alredy exist the Pan')
else:
new_doc=frappe.new_doc("Generate Group ID")
new_doc.pan=pan_no
new_doc.pan_no=pan_no
new_doc.random_id = random_id
new_doc.document_no=doc.name
new_doc.dacument_type='Sales Invoice'
new_doc.save()
doc.group_id = random_id

0 comments on commit 6cdcc66

Please sign in to comment.