Skip to content

Commit

Permalink
fix: checking ifnull values
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed May 24, 2024
1 parent 358296e commit 3804b6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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}

Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)
)
Expand All @@ -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)
)
Expand Down

0 comments on commit 3804b6e

Please sign in to comment.