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


import xhiveframework
from dateutil.relativedelta import relativedelta
from xhiveframework.model.document import Document
from xhiveframework.utils import cint


class ManufacturingSettings(Document):
	pass


def get_mins_between_operations():
	return relativedelta(
		minutes=cint(xhiveframework.db.get_single_value("Manufacturing Settings", "mins_between_operations"))
		or 10
	)


@xhiveframework.whitelist()
def is_material_consumption_enabled():
	if not hasattr(xhiveframework.local, "material_consumption"):
		xhiveframework.local.material_consumption = cint(
			xhiveframework.db.get_single_value("Manufacturing Settings", "material_consumption")
		)

	return xhiveframework.local.material_consumption
