# 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 LoanType(Document):
	def validate(self):
		self.validate_accounts()

	def validate_accounts(self):
		for fieldname in [
			"payment_account",
			"loan_account",
			"interest_income_account",
			"penalty_income_account",
		]:
			company = xhiveframework.get_value("Account", self.get(fieldname), "company")

			if company and company != self.company:
				xhiveframework.throw(
					_("Account {0} does not belong to company {1}").format(
						xhiveframework.bold(self.get(fieldname)), xhiveframework.bold(self.company)
					)
				)

		if self.get("loan_account") == self.get("payment_account"):
			xhiveframework.throw(_("Loan Account and Payment Account cannot be same"))
