Пример #1
0
def get_events(start, end, filters=None):
	"""Returns events for Gantt / Calendar view rendering.

	:param start: Start date-time.
	:param end: End date-time.
	:param filters: Filters like workstation, project etc.
	"""
	from frappe.desk.calendar import get_event_conditions
	conditions = get_event_conditions("Time Log", filters)

	if (cint(get_defaults("fs_simplified_time_log"))):
		date_cond = "date_worked between %(start)s and %(end)s"
	else:
		date_cond = "( from_time between %(start)s and %(end)s or to_time between %(start)s and %(end)s )"
	
	data = frappe.db.sql("""select name, from_time, to_time,
		activity_type, task, project, production_order, workstation, date_worked, employee, hours from `tabTime Log`
		where docstatus < 2 and {date_cond}
		{conditions}""".format(conditions=conditions,date_cond=date_cond), {
			"start": start,
			"end": end
			}, as_dict=True, update={"allDay": 0})
	#aligns the assorted time logs so they are layed out sequentially
	if(cint(get_defaults("fs_simplified_time_log"))):
		slist = {}
		for idx,da in enumerate(data):
			if (da.employee not in slist):
				slist[da.employee]={}
			if (da.date_worked not in slist[da.employee]):
				slist[da.employee][da.date_worked]=[]
			slist[da.employee][da.date_worked].append([idx,da.from_time,da.to_time,da.hours])	
		for e in slist:
			for d in slist[e]:
				temp = slist[e][d][0]
				temp[1]= datetime.combine(d,get_time("8:00:00"))
				temp[2]= temp[1] + timedelta(hours=temp[3])
				for idx,l in enumerate(slist[e][d][1:]):
					data[l[0]]["from_time"]= l[1] = slist[e][d][idx][2]
					data[l[0]]["to_time"] = l[2] = l[1]+ timedelta(hours=l[3])
				l= slist[e][d][0]
				data[temp[0]]["from_time"]= slist[e][d][0][1]
				data[temp[0]]["to_time"] =  slist[e][d][0][2]

	for d in data:
		d.title = d.name + ": " + (d.activity_type or d.production_order or "")
		if d.task:
			d.title += " for Task: " + d.task
		if d.project:
			d.title += " for Project: " + d.project

	return data
Пример #2
0
def money_in_words(number, main_currency=None, fraction_currency=None):
    """
	Returns string in words with currency and fraction currency.
	"""
    from frappe.utils import get_defaults

    d = get_defaults()
    if not main_currency:
        main_currency = d.get('currency', 'INR')
    if not fraction_currency:
        fraction_currency = frappe.db.get_value("Currency", main_currency,
                                                "fraction") or "Cent"

    n = "%.2f" % flt(number)
    main, fraction = n.split('.')
    if len(fraction) == 1: fraction += '0'


    number_format = frappe.db.get_value("Currency", main_currency, "number_format") or \
     frappe.db.get_default("number_format") or "#,###.##"

    in_million = True
    if number_format == "#,##,###.##": in_million = False

    out = main_currency + ' ' + in_words(main, in_million).title()
    if cint(fraction):
        out = out + ' and ' + in_words(
            fraction, in_million).title() + ' ' + fraction_currency

    return out + ' only.'
Пример #3
0
def money_in_words(number, main_currency = None, fraction_currency=None):
	"""
	Returns string in words with currency and fraction currency.
	"""
	from frappe.utils import get_defaults

	if not number or flt(number) < 0:
		return ""

	d = get_defaults()
	if not main_currency:
		main_currency = d.get('currency', 'INR')
	if not fraction_currency:
		fraction_currency = frappe.db.get_value("Currency", main_currency, "fraction") or "Cent"

	n = "%.2f" % flt(number)
	main, fraction = n.split('.')
	if len(fraction)==1: fraction += '0'


	number_format = frappe.db.get_value("Currency", main_currency, "number_format") or \
		frappe.db.get_default("number_format") or "#,###.##"

	in_million = True
	if number_format == "#,##,###.##": in_million = False

	out = main_currency + ' ' + in_words(main, in_million).title()
	if cint(fraction):
		out = out + ' and ' + in_words(fraction, in_million).title() + ' ' + fraction_currency

	return out + ' only.'
Пример #4
0
def money_in_words(number, main_currency=None, fraction_currency=None):
    """
	Returns string in words with currency and fraction currency.
	"""
    from frappe.utils import get_defaults
    _ = frappe._

    if not number or flt(number) < 0:
        return ""

    d = get_defaults()
    if not main_currency:
        main_currency = d.get('currency', 'INR')
    if not fraction_currency:
        fraction_currency = frappe.db.get_value("Currency", main_currency,
                                                "fraction") or _("Cent")

    n = "%.2f" % flt(number)
    main, fraction = n.split('.')
    if len(fraction) == 1: fraction += '0'


    number_format = frappe.db.get_value("Currency", main_currency, "number_format", cache=True) or \
     frappe.db.get_default("number_format") or "#,###.##"

    in_million = True
    if number_format == "#,##,###.##": in_million = False

    out = in_words(main, in_million).title()
    if cint(fraction):
        out = out + ' ' + _('and') + ' ' + fraction + '/100'
    else:
        out = out + ' ' + _('and') + ' 00/100'

    return out + ' soles'
Пример #5
0
def money_in_words_zh(number, main_currency = None, fraction_currency=None):
    """
    Returns string in words with currency and fraction currency.
    """
    from frappe.utils import get_defaults
    _ = frappe._

    try:
        # note: `flt` returns 0 for invalid input and we don't want that
        number = float(number)
    except ValueError:
        return ""

    number = flt(number)
    if number < 0:
        return ""

    d = get_defaults()
    if not main_currency:
        main_currency = d.get('currency', 'INR')
    if not fraction_currency:
        fraction_currency = frappe.db.get_value("Currency", main_currency, "fraction", cache=True) or _("Cent")

    number_format = frappe.db.get_value("Currency", main_currency, "number_format", cache=True) or \
        frappe.db.get_default("number_format") or "#,###.##"

    fraction_length = get_number_format_info(number_format)[2]

    n = "%.{0}f".format(fraction_length) % number

    numbers = n.split('.')

    main, fraction =  numbers if len(numbers) > 1 else [n, '00']

    if len(fraction) < fraction_length:
        zeros = '0' * (fraction_length - len(fraction))
        fraction += zeros

    in_million = True
    if number_format == "#,##,###.##": in_million = False

    # 如果是中文,调用中文的金额转大写
    if (frappe.local.lang == 'zh'):
        return cncurrency(n, prefix=True)

    # 0.00
    if main == '0' and fraction in ['00', '000']:
        out = "{0} {1}".format(main_currency, _('Zero'))
    # 0.XX
    elif main == '0':
        out = _(in_words(fraction, in_million).title()) + ' ' + fraction_currency
    else:
        out = main_currency + ' ' + _(in_words(main, in_million).title())
        if cint(fraction):
            out = out + ' ' + _('and') + ' ' + _(in_words(fraction, in_million).title()) + ' ' + fraction_currency

    return out + ' ' + _('only.')
Пример #6
0
def money_in_words(number, main_currency=None, fraction_currency=None):
    """
	Returns string in words with currency and fraction currency.
	"""
    from frappe.utils import get_defaults, cint
    from frappe.utils.data import get_number_format_info, in_words
    _ = frappe._

    try:
        # note: `flt` returns 0 for invalid input and we don't want that
        number = float(number)
    except ValueError:
        return ""

    number = flt(number)
    if number < 0:
        return ""

    d = get_defaults()
    if not main_currency:
        main_currency = d.get('currency', 'INR')
    if not fraction_currency:
        fraction_currency = frappe.db.get_value(
            "Currency", main_currency, "fraction", cache=True) or _("Cent")

    number_format = frappe.db.get_value("Currency", main_currency, "number_format", cache=True) or \
     frappe.db.get_default("number_format") or "#,###.##"

    fraction_length = get_number_format_info(number_format)[2]

    n = "%.{0}f".format(fraction_length) % number

    numbers = n.split('.')
    main, fraction = numbers if len(numbers) > 1 else [n, '00']

    if len(fraction) < fraction_length:
        zeros = '0' * (fraction_length - len(fraction))
        fraction += zeros

    in_million = True
    if number_format == "#,##,###.##": in_million = False

    # 0.00
    if main == '0' and fraction in ['00', '000']:
        out = "{0} {1}".format(main_currency, _('Zero'))
    # 0.XX
    elif main == '0':
        out = _(in_words(fraction, in_million).title())
    else:
        out = main_currency + ' ' + _(in_words(main, in_million).title())
        if cint(fraction):
            out = out + ' ' + _('and') + ' ' + _(
                in_words(fraction, in_million).title())
    # out = re.sub(r'(?<=Thousand).*', '', out)
    out = out[0:139]  #140 characters is max
    return out + '.'
Пример #7
0
def money_in_words(number, main_currency = None, fraction_currency=None):
	"""
	Returns string in words with currency and fraction currency.
	"""
	from frappe.utils import get_defaults
	_ = frappe._

	try:
		# note: `flt` returns 0 for invalid input and we don't want that
		number = float(number)
	except ValueError:
		return ""

	number = flt(number)
	if number < 0:
		return ""

	d = get_defaults()
	if not main_currency:
		main_currency = d.get('currency', 'INR')
	if not fraction_currency:
		fraction_currency = frappe.db.get_value("Currency", main_currency, "fraction") or _("Cent")

	number_format = frappe.db.get_value("Currency", main_currency, "number_format", cache=True) or \
		frappe.db.get_default("number_format") or "#,###.##"

	fraction_length = get_number_format_info(number_format)[2]

	n = "%.{0}f".format(fraction_length) % number

	numbers = n.split('.')
	main, fraction =  numbers if len(numbers) > 1 else [n, '00']

	if len(fraction) < fraction_length:
		zeros = '0' * (fraction_length - len(fraction))
		fraction += zeros

	in_million = True
	if number_format == "#,##,###.##": in_million = False

	# 0.00
	if main == '0' and fraction in ['00', '000']:
		out = "{0} {1}".format(main_currency, _('Zero'))
	# 0.XX
	elif main == '0':
		out = _(in_words(fraction, in_million).title()) + ' ' + fraction_currency
	else:
		out = main_currency + ' ' + _(in_words(main, in_million).title())
		if cint(fraction):
			out = out + ' ' + _('and') + ' ' + _(in_words(fraction, in_million).title()) + ' ' + fraction_currency

	return out + ' ' + _('only.')
Пример #8
0
	def validate(self):
		self.set_status()
		self.set_title()
		if not(cint(get_defaults("fs_simplified_time_log"))):
			self.validate_overlap()
		self.validate_timings()
		self.calculate_total_hours()
		self.validate_time_log_for()
		self.check_workstation_timings()
		self.validate_production_order()
		self.validate_manufacturing()
		self.set_project_if_missing()
		self.update_cost()
Пример #9
0
def validate_vat(doc):
	from frappe.utils import get_defaults
	if isinstance(doc, basestring):
		doc = json.loads(doc)

	nif = doc.get('vat_or_nif')
	if nif:
		nif = nif.strip(' \t\n\r')
		company = get_defaults().get("company")
		ret = validation.button_check_vat(nif, company)
		_logger.info("whitelist nif {0}".format(nif))
		check_duplo_vat(doc, nif)
	else:
		ret = {"msg":_('You need to provide a VAT number first.'), "status": "ERROR"}

	return ret
Пример #10
0
def validate_vat(doc):
	"""
		doc must have at least the following fields
		vat_or_nif (String), customer_name (String) and vies_vat_check (Boolean).
	"""
	from frappe.utils import get_defaults
	if isinstance(doc, basestring):
		doc = json.loads(doc)

	nif = doc.get('vat_or_nif')
	if nif:
		nif = nif.strip(' \t\n\r')
		company = get_defaults().get("company")
		ret = validation.button_check_vat(nif, doc.get("vies_vat_check"), company)
		_logger.info("whitelist nif {0}".format(nif))
		check_duplo_vat(doc, nif)
	else:
		ret = {"msg":_('You need to provide a VAT number first.'), "status": "ERROR"}

	return ret
Пример #11
0
def money_in_words(number, main_currency=None, fraction_currency=None):
    """
	Returns string in words with currency and fraction currency.
	"""
    from frappe.utils import get_defaults

    _ = frappe._

    if not number or flt(number) < 0:
        return ""

    d = get_defaults()
    if not main_currency:
        main_currency = d.get("currency", "INR")
    if not fraction_currency:
        fraction_currency = frappe.db.get_value("Currency", main_currency, "fraction") or _("Cent")

    n = "%.2f" % flt(number)
    main, fraction = n.split(".")
    if len(fraction) == 1:
        fraction += "0"

    number_format = (
        frappe.db.get_value("Currency", main_currency, "number_format", cache=True)
        or frappe.db.get_default("number_format")
        or "#,###.##"
    )

    in_million = True
    if number_format == "#,##,###.##":
        in_million = False

    out = main_currency + " " + in_words(main, in_million).title()
    if cint(fraction):
        out = out + " " + _("and") + " " + in_words(fraction, in_million).title() + " " + fraction_currency

    return out + " " + _("only.")