Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion india_compliance/gst_india/overrides/ineligible_itc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import frappe
from frappe import _
from frappe.utils import flt, get_link_to_form
from erpnext.assets.doctype.asset.asset import (
from assets.assets.doctype.asset.asset import (
get_asset_account,
is_cwip_accounting_enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def delete_tax_id_custom_field():
def set_correct_state_number():
# set correct state number for all states with single digit state number
frappe.db.sql(
"""UPDATE tabAddress SET gst_state_number=concat("0", gst_state_number)
"""UPDATE "tabAddress" SET gst_state_number=concat('0', gst_state_number)
WHERE length(gst_state_number) = 1"""
)

Expand Down
8 changes: 4 additions & 4 deletions india_compliance/patches/post_install/update_company_gstin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def verify_gstin_update(gst_accounts=None):
voucher_types = get_pending_voucher_types(gst_accounts)

if voucher_types:
toggle_allow_on_submit(True, voucher_types)
toggle_allow_on_submit(1, voucher_types)
return voucher_types

toggle_allow_on_submit(False)
toggle_allow_on_submit(0)


def update_gstin_for_je(company, gst_accounts):
Expand Down Expand Up @@ -174,11 +174,11 @@ def get_pending_voucher_types(gst_accounts):
)


def toggle_allow_on_submit(allow=True, voucher_types=None):
def toggle_allow_on_submit(allow=1, voucher_types=None):
custom_field = frappe.qb.DocType("Custom Field")
query = (
frappe.qb.update(custom_field)
.set(custom_field.allow_on_submit, bool(allow))
.set(custom_field.allow_on_submit, allow)
.where(custom_field.fieldname == "company_gstin")
)

Expand Down
3 changes: 1 addition & 2 deletions india_compliance/patches/post_install/update_gst_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def execute():
"company",
"cgst_account",
"sgst_account",
"igst_account",
"is_reverse_charge_account",
"igst_account"
),
ignore_ddl=True,
)
Expand Down
109 changes: 74 additions & 35 deletions india_compliance/patches/post_install/update_reconciliation_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,80 @@


def execute():
PI = frappe.qb.DocType("Purchase Invoice")
PI_ITEM = frappe.qb.DocType("Purchase Invoice Item")
BOE = frappe.qb.DocType("Bill of Entry")

(
frappe.qb.update(PI)
.set(PI.reconciliation_status, "Not Applicable")
.join(PI_ITEM)
.on(PI.name == PI_ITEM.parent)
.where(PI.docstatus == 1)
.where(
(IfNull(PI.supplier_gstin, "") == "")
| (
IfNull(PI.gst_category, "").isin(
["Registered Composition", "Unregistered", "Overseas"]
if frappe.db.db_type == "postgres":
# Update Purchase Invoice reconciliation status to "Not Applicable"
frappe.db.sql(
"""
UPDATE "tabPurchase Invoice" AS pi
SET reconciliation_status = 'Not Applicable'
FROM "tabPurchase Invoice Item" AS pii
WHERE pi.name = pii.parent
AND pi.docstatus = 1
AND (
COALESCE(pi.supplier_gstin, '') = ''
OR COALESCE(pi.gst_category, '') IN ('Registered Composition', 'Unregistered', 'Overseas')
OR COALESCE(pi.supplier_gstin, '') = pi.company_gstin
OR COALESCE(pi.is_opening, '') = 'Yes'
OR pii.gst_treatment = 'Non-GST'
)
"""
)

# Update Purchase Invoice reconciliation status to "Unreconciled"
frappe.db.sql(
"""
UPDATE "tabPurchase Invoice"
SET reconciliation_status = 'Unreconciled'
WHERE docstatus = 1
AND COALESCE(reconciliation_status, '') = ''
"""
)

# Update Bill of Entry reconciliation status to "Unreconciled"
frappe.db.sql(
"""
UPDATE "tabBill of Entry"
SET reconciliation_status = 'Unreconciled'
WHERE docstatus = 1
"""
)

else:
PI = frappe.qb.DocType("Purchase Invoice")
PI_ITEM = frappe.qb.DocType("Purchase Invoice Item")
BOE = frappe.qb.DocType("Bill of Entry")

(
frappe.qb.update(PI)
.set(PI.reconciliation_status, "Not Applicable")
.join(PI_ITEM)
.on(PI.name == PI_ITEM.parent)
.where(PI.docstatus == 1)
.where(
(IfNull(PI.supplier_gstin, "") == "")
| (
IfNull(PI.gst_category, "").isin(
["Registered Composition", "Unregistered", "Overseas"]
)
)
| (IfNull(PI.supplier_gstin, "") == PI.company_gstin)
| (IfNull(PI.is_opening, "") == "Yes")
| (PI_ITEM.gst_treatment == "Non-GST")
)
| (IfNull(PI.supplier_gstin, "") == PI.company_gstin)
| (IfNull(PI.is_opening, "") == "Yes")
| (PI_ITEM.gst_treatment == "Non-GST")
.run()
)

(
frappe.qb.update(PI)
.set(PI.reconciliation_status, "Unreconciled")
.where(PI.docstatus == 1)
.where(IfNull(PI.reconciliation_status, "") == "")
.run()
)

(
frappe.qb.update(BOE)
.set(BOE.reconciliation_status, "Unreconciled")
.where(BOE.docstatus == 1)
.run()
)
.run()
)

(
frappe.qb.update(PI)
.set(PI.reconciliation_status, "Unreconciled")
.where(PI.docstatus == 1)
.where(IfNull(PI.reconciliation_status, "") == "")
.run()
)

(
frappe.qb.update(BOE)
.set(BOE.reconciliation_status, "Unreconciled")
.where(BOE.docstatus == 1)
.run()
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,37 @@ def execute():
- gj06-ab-1234
- Gj06 abc 1234
"""
REGEX_PATTERN = r"^[a-zA-Z]{2}[-\s]?[0-9]{2}[-\s]?[a-zA-Z]{1,3}[-\s]?[0-9]{4}$"
pr = frappe.qb.DocType("Purchase Receipt")
if frappe.db.db_type == "postgres":
REGEX_PATTERN = r"^[a-zA-Z]{2}[-\s]?[0-9]{2}[-\s]?[a-zA-Z]{1,3}[-\s]?[0-9]{4}$"

(
frappe.qb.update(pr)
.set(pr.vehicle_no, pr.lr_no)
.where(pr.lr_no.regexp(REGEX_PATTERN))
.run()
)
# Update vehicle_no field where lr_no matches the regex pattern
frappe.db.sql(
"""
UPDATE "tabPurchase Receipt"
SET "vehicle_no" = "lr_no"
WHERE "lr_no" ~ %s
""",
(REGEX_PATTERN,)
)

(frappe.qb.update(pr).set(pr.lr_no, "").where(pr.lr_no.regexp(REGEX_PATTERN)).run())
# Clear lr_no field for entries that matched the regex pattern
frappe.db.sql(
"""
UPDATE "tabPurchase Receipt"
SET "lr_no" = ''
WHERE "lr_no" ~ %s
""",
(REGEX_PATTERN,)
)
else:
REGEX_PATTERN = r"^[a-zA-Z]{2}[-\s]?[0-9]{2}[-\s]?[a-zA-Z]{1,3}[-\s]?[0-9]{4}$"
pr = frappe.qb.DocType("Purchase Receipt")

(
frappe.qb.update(pr)
.set(pr.vehicle_no, pr.lr_no)
.where(pr.lr_no.regexp(REGEX_PATTERN))
.run()
)

(frappe.qb.update(pr).set(pr.lr_no, "").where(pr.lr_no.regexp(REGEX_PATTERN)).run())