From 3804b6e610475ff1ac07ef2742d64c8636a80e63 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 24 May 2024 11:19:22 +0530 Subject: [PATCH] fix: checking ifnull values --- .../doctype/gstr_3b_report/gstr_3b_report.py | 18 +++++++----------- .../report/gstr_3b_details/gstr_3b_details.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py index ba32ffa650..d9a02f2eae 100644 --- a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py +++ b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py @@ -9,7 +9,7 @@ from frappe import _ from frappe.model.document import Document from frappe.query_builder import DatePart -from frappe.query_builder.functions import Extract, Sum +from frappe.query_builder.functions import Extract, IfNull, Sum from frappe.utils import cstr, flt, get_date_str, get_first_day, get_last_day from india_compliance.gst_india.constants import INVOICE_DOCTYPES @@ -196,7 +196,7 @@ def get_itc_details(self): FROM `tabPurchase Invoice` WHERE docstatus = 1 and is_opening = 'No' - and company_gstin != supplier_gstin + and company_gstin != IFNULL(supplier_gstin, "") and month(posting_date) = %s and year(posting_date) = %s and company = %s and company_gstin = %s GROUP BY itc_classification @@ -257,7 +257,7 @@ def get_inward_nil_exempt(self, state): FROM `tabPurchase Invoice` p , `tabPurchase Invoice Item` i WHERE p.docstatus = 1 and p.name = i.parent and p.is_opening = 'No' - and p.supplier_gstin != p.company_gstin + and p.company_gstin != IFNULL(p.supplier_gstin, "") and (i.gst_treatment != 'Taxable' or p.gst_category = 'Registered Composition') and month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s @@ -395,9 +395,11 @@ def get_outward_tax_invoices(self, doctype, reverse_charge=None): invoice = frappe.qb.DocType(doctype) fields = [invoice.name, invoice.gst_category, invoice.place_of_supply] + gstin = invoice.supplier_gstin if doctype == "Sales Invoice": fields.append(invoice.is_export_with_gst) + gstin = invoice.billing_address_gstin query = ( frappe.qb.from_(invoice) @@ -408,18 +410,12 @@ def get_outward_tax_invoices(self, doctype, reverse_charge=None): .where(invoice.company == self.company) .where(invoice.company_gstin == self.gst_details.get("gstin")) .where(invoice.is_opening == "No") + .where(invoice.company_gstin != IfNull(gstin, "")) ) if reverse_charge: query = query.where(invoice.is_reverse_charge == 1) - condition = ( - (invoice.billing_address_gstin != invoice.company_gstin) - if doctype == "Sales Invoice" - else (invoice.supplier_gstin != invoice.company_gstin) - ) - query = query.where(condition) - invoice_details = query.orderby(invoice.name).run(as_dict=True) self.invoice_map = {d.name: d for d in invoice_details} @@ -613,7 +609,7 @@ def get_missing_field_invoices(self): WHERE docstatus = 1 and is_opening = 'No' and month(posting_date) = %s and year(posting_date) = %s and company = %s and place_of_supply IS NULL - and {billing_gstin} != company_gstin + and company_gstin != IFNULL({billing_gstin},"") and gst_category != 'Overseas' """, (self.month_no, self.year, self.company), diff --git a/india_compliance/gst_india/report/gstr_3b_details/gstr_3b_details.py b/india_compliance/gst_india/report/gstr_3b_details/gstr_3b_details.py index b275779c0f..22827f6f4f 100644 --- a/india_compliance/gst_india/report/gstr_3b_details/gstr_3b_details.py +++ b/india_compliance/gst_india/report/gstr_3b_details/gstr_3b_details.py @@ -155,7 +155,10 @@ def get_itc_from_purchase(self): & (purchase_invoice.posting_date[self.from_date : self.to_date]) & (purchase_invoice.company == self.company) & (purchase_invoice.company_gstin == self.company_gstin) - & (purchase_invoice.company_gstin != purchase_invoice.supplier_gstin) + & ( + purchase_invoice.company_gstin + != IfNull(purchase_invoice.supplier_gstin, "") + ) & (Ifnull(purchase_invoice.itc_classification, "") != "") ) .groupby(purchase_invoice.name) @@ -406,7 +409,10 @@ def get_inward_nil_exempt(self): & (purchase_invoice.posting_date[self.from_date : self.to_date]) & (purchase_invoice.company == self.company) & (purchase_invoice.company_gstin == self.company_gstin) - & (purchase_invoice.company_gstin != purchase_invoice.supplier_gstin) + & ( + purchase_invoice.company_gstin + != IfNull(purchase_invoice.supplier_gstin, "") + ) ) .groupby(purchase_invoice.name) ) @@ -442,7 +448,7 @@ def get_for_purchase_invoice(self, group_by="name"): ) .where(IfNull(pi.ineligibility_reason, "") != "") .where(pi.name.isin(ineligible_transactions)) - .where(pi.company_gstin != pi.supplier_gstin) + .where(pi.company_gstin != IfNull(pi.supplier_gstin, "")) .groupby(pi[group_by]) .run(as_dict=1) ) @@ -461,7 +467,7 @@ def get_for_purchase_invoice(self, group_by="name"): ) .where(IfNull(pi.ineligibility_reason, "") != "") .where(pi.name.isin(ineligible_transactions)) - .where(pi.company_gstin != pi.supplier_gstin) + .where(pi.company_gstin != IfNull(pi.supplier_gstin, "")) .groupby(pi[group_by]) .run(as_dict=1) )