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

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


class PartySpecificItem(Document):
	def validate(self):
		exists = xhiveframework.db.exists(
			{
				"doctype": "Party Specific Item",
				"party_type": self.party_type,
				"party": self.party,
				"restrict_based_on": self.restrict_based_on,
				"based_on": self.based_on_value,
			}
		)
		if exists:
			xhiveframework.throw(_("This item filter has already been applied for the {0}").format(self.party_type))
