# Copyright (c) 2018, Xhive LLC
# See license.txt

import unittest

import xhiveframework

import xhiveerp

test_dependencies = ["Employee", "Leave Type", "Leave Policy"]


class TestLeavePeriod(unittest.TestCase):
	pass


def create_leave_period(from_date, to_date, company=None):
	leave_period = xhiveframework.db.get_value(
		"Leave Period",
		dict(
			company=company or xhiveerp.get_default_company(),
			from_date=from_date,
			to_date=to_date,
			is_active=1,
		),
		"name",
	)
	if leave_period:
		return xhiveframework.get_doc("Leave Period", leave_period)

	leave_period = xhiveframework.get_doc(
		{
			"doctype": "Leave Period",
			"company": company or xhiveerp.get_default_company(),
			"from_date": from_date,
			"to_date": to_date,
			"is_active": 1,
		}
	).insert()
	return leave_period
