# Copyright (c) 2019, InfluxFramework LLC and contributors
# For license information, please see license.txt


import influxframework
from influxframework import _
from influxframework.model.document import Document


class SanctionedLoanAmount(Document):
	def validate(self):
		sanctioned_doc = influxframework.db.exists(
			"Sanctioned Loan Amount", {"applicant": self.applicant, "company": self.company}
		)

		if sanctioned_doc and sanctioned_doc != self.name:
			influxframework.throw(
				_("Sanctioned Loan Amount already exists for {0} against company {1}").format(
					influxframework.bold(self.applicant), influxframework.bold(self.company)
				)
			)
