fix: date validation

This commit is contained in:
pateljannat 2021-01-20 18:12:48 +05:30
parent 3c55463b4b
commit f110759897

View File

@ -29,9 +29,19 @@ class LowerDeductionCertificate(Document):
frappe.throw(_("Valid Upto date not in Fiscal Year {0}").format(frappe.bold(self.fiscal_year)))
def validate_supplier_against_section_code(self):
duplicate_certificate = frappe.db.get_value('Lower Deduction Certificate', {'supplier': self.supplier, 'section_code': self.section_code}, ['name'])
if duplicate_certificate:
certificate_link = get_link_to_form('Lower Deduction Certificate', duplicate_certificate)
frappe.throw(_("There is already a Lower Deduction Certificate {0} for Supplier {1} against Section Code {2}")
duplicate_certificate = frappe.db.get_value('Lower Deduction Certificate', {'supplier': self.supplier, 'section_code': self.section_code}, ['name', 'valid_from', 'valid_upto'], as_dict=True)
if duplicate_certificate and self.are_dates_overlapping(duplicate_certificate):
certificate_link = get_link_to_form('Lower Deduction Certificate', duplicate_certificate.name)
frappe.throw(_("There is already a valid Lower Deduction Certificate {0} for Supplier {1} against Section Code {2} for this time period.")
.format(certificate_link, frappe.bold(self.supplier), frappe.bold(self.section_code)))
def are_dates_overlapping(self,duplicate_certificate):
valid_from = duplicate_certificate.valid_from
valid_upto = duplicate_certificate.valid_upto
if valid_from <= getdate(self.valid_from) and getdate(self.valid_from) <= valid_upto:
return True
elif valid_from <= getdate(self.valid_upto) and getdate(self.valid_upto) <= valid_upto:
return True
elif getdate(self.valid_from) <= valid_from and valid_upto <= getdate(self.valid_upto):
return True
return False