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


import xhiveframework
from xhiveframework import _
from xhiveframework.model.document import Document


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

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