Beispiel #1
0
def hourly_reminder():
    fields = ["from_time", "to_time"]
    projects = get_projects_for_collect_progress("Hourly", fields)

    for project in projects:
        if (get_time(nowtime()) >= get_time(project.from_time)
                or get_time(nowtime()) <= get_time(project.to_time)):
            send_project_update_email_to_users(project.name)
Beispiel #2
0
def get_stock_qty(item_code, warehouse):
	return get_previous_sle({
		"item_code": item_code,
		"warehouse": warehouse,
		"posting_date": nowdate(),
		"posting_time": nowtime()
	}).get("qty_after_transaction") or 0
Beispiel #3
0
def create_delivery_note(**args):
	dn = dataent.new_doc("Delivery Note")
	args = dataent._dict(args)
	dn.posting_date = args.posting_date or nowdate()
	dn.posting_time = args.posting_time or nowtime()
	dn.set_posting_time = 1

	dn.company = args.company or "_Test Company"
	dn.customer = args.customer or "_Test Customer"
	dn.currency = args.currency or "INR"
	dn.is_return = args.is_return
	dn.return_against = args.return_against

	dn.append("items", {
		"item_code": args.item or args.item_code or "_Test Item",
		"warehouse": args.warehouse or "_Test Warehouse - _TC",
		"qty": args.qty or 1,
		"rate": args.rate or 100,
		"conversion_factor": 1.0,
		"expense_account": "Cost of Goods Sold - _TC",
		"cost_center": args.cost_center or "_Test Cost Center - _TC",
		"serial_no": args.serial_no,
		"target_warehouse": args.target_warehouse
	})

	if not args.do_not_save:
		dn.insert()
		if not args.do_not_submit:
			dn.submit()
	return dn
Beispiel #4
0
def send_project_update_email_to_users(project):
    doc = dataent.get_doc('Project', project)

    if is_holiday_today(doc.holiday_list) or not doc.users: return

    project_update = dataent.get_doc({
        "doctype":
        "Project Update",
        "project":
        project,
        "sent":
        0,
        "date":
        today(),
        "time":
        nowtime(),
        "naming_series":
        "UPDATE-.project.-.YY.MM.DD.-",
    }).insert()

    subject = "For project %s, update your status" % (project)

    incoming_email_account = dataent.db.get_value(
        'Email Account', dict(enable_incoming=1, default_incoming=1),
        'email_id')

    dataent.sendmail(recipients=get_users_email(doc),
                     message=doc.message,
                     subject=_(subject),
                     reference_doctype=project_update.doctype,
                     reference_name=project_update.name,
                     reply_to=incoming_email_account)
Beispiel #5
0
    def test_repack_no_change_in_valuation(self):
        company = dataent.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                       'company')
        set_perpetual_inventory(0, company)

        make_stock_entry(item_code="_Test Item",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)
        make_stock_entry(item_code="_Test Item Home Desktop 100",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)

        repack = dataent.copy_doc(test_records[3])
        repack.posting_date = nowdate()
        repack.posting_time = nowtime()
        repack.insert()
        repack.submit()

        self.check_stock_ledger_entries(
            "Stock Entry", repack.name,
            [["_Test Item", "_Test Warehouse - _TC", -50.0],
             ["_Test Item Home Desktop 100", "_Test Warehouse - _TC", 1]])

        gl_entries = dataent.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Stock Entry' and voucher_no=%s
			order by account desc""",
                                    repack.name,
                                    as_dict=1)
        self.assertFalse(gl_entries)

        set_perpetual_inventory(0, repack.company)
Beispiel #6
0
def allow_to_make_project_update(project, time, frequency):
    data = dataent.db.sql(
        """ SELECT name from `tabProject Update`
		WHERE project = %s and date = %s """, (project, today()))

    # len(data) > 1 condition is checked for twicely frequency
    if data and (frequency in ['Daily', 'Weekly'] or len(data) > 1):
        return False

    if get_time(nowtime()) >= get_time(time):
        return True
Beispiel #7
0
def get_qty_after_transaction(**args):
    args = dataent._dict(args)

    last_sle = get_previous_sle({
        "item_code": args.item_code or "_Test Item",
        "warehouse": args.warehouse or "_Test Warehouse - _TC",
        "posting_date": args.posting_date or nowdate(),
        "posting_time": args.posting_time or nowtime()
    })

    return flt(last_sle.get("qty_after_transaction"))
Beispiel #8
0
    def test_repack_with_additional_costs(self):
        company = dataent.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                       'company')
        set_perpetual_inventory(1, company)

        make_stock_entry(item_code="_Test Item",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)
        repack = dataent.copy_doc(test_records[3])
        repack.posting_date = nowdate()
        repack.posting_time = nowtime()

        repack.set("additional_costs", [
            {
                "description": "Actual Oerating Cost",
                "amount": 1000
            },
            {
                "description": "additional operating costs",
                "amount": 200
            },
        ])
        repack.insert()
        repack.submit()

        stock_in_hand_account = get_inventory_account(
            repack.company,
            repack.get("items")[1].t_warehouse)
        rm_stock_value_diff = abs(
            dataent.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Stock Entry",
                    "voucher_no": repack.name,
                    "item_code": "_Test Item"
                }, "stock_value_difference"))

        fg_stock_value_diff = abs(
            dataent.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Stock Entry",
                    "voucher_no": repack.name,
                    "item_code": "_Test Item Home Desktop 100"
                }, "stock_value_difference"))

        stock_value_diff = flt(fg_stock_value_diff - rm_stock_value_diff, 2)

        self.assertEqual(stock_value_diff, 1200)

        self.check_gl_entries(
            "Stock Entry", repack.name,
            sorted([[stock_in_hand_account, 1200, 0.0],
                    ["Expenses Included In Valuation - _TC", 0.0, 1200.0]]))
        set_perpetual_inventory(0, repack.company)
    def test_get_items(self):
        create_warehouse("_Test Warehouse Group 1", {"is_group": 1})
        create_warehouse("_Test Warehouse Ledger 1", {
            "is_group": 0,
            "parent_warehouse": "_Test Warehouse Group 1 - _TC"
        })

        create_item("_Test Stock Reco Item",
                    is_stock_item=1,
                    valuation_rate=100,
                    warehouse="_Test Warehouse Ledger 1 - _TC",
                    opening_stock=100)

        items = get_items("_Test Warehouse Group 1 - _TC", nowdate(),
                          nowtime(), "_Test Company")

        self.assertEqual(
            ["_Test Stock Reco Item", "_Test Warehouse Ledger 1 - _TC", 100],
            [items[0]["item_code"], items[0]["warehouse"], items[0]["qty"]])
Beispiel #10
0
	def test_delivery_note_no_gl_entry(self):
		company = dataent.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company')
		set_perpetual_inventory(0, company)
		make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

		stock_queue = json.loads(get_previous_sle({
			"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC",
			"posting_date": nowdate(),
			"posting_time": nowtime()
		}).stock_queue or "[]")

		dn = create_delivery_note()

		sle = dataent.get_doc("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name})

		self.assertEqual(sle.stock_value_difference, -1*stock_queue[0][1])

		self.assertFalse(get_gl_entries("Delivery Note", dn.name))
Beispiel #11
0
def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None, with_valuation_rate=False):
	"""Returns stock balance quantity at given warehouse on given posting date or current date.

	If `with_valuation_rate` is True, will return tuple (qty, rate)"""

	from epaas.stock.stock_ledger import get_previous_sle

	if not posting_date: posting_date = nowdate()
	if not posting_time: posting_time = nowtime()

	last_entry = get_previous_sle({
		"item_code": item_code,
		"warehouse":warehouse,
		"posting_date": posting_date,
		"posting_time": posting_time })

	if with_valuation_rate:
		return (last_entry.qty_after_transaction, last_entry.valuation_rate) if last_entry else (0.0, 0.0)
	else:
		return last_entry.qty_after_transaction if last_entry else 0.0
def create_stock_reconciliation(**args):
    args = dataent._dict(args)
    sr = dataent.new_doc("Stock Reconciliation")
    sr.posting_date = args.posting_date or nowdate()
    sr.posting_time = args.posting_time or nowtime()
    sr.set_posting_time = 1
    sr.company = args.company or "_Test Company"
    sr.expense_account = args.expense_account or \
     ("Stock Adjustment - _TC" if dataent.get_all("Stock Ledger Entry") else "Temporary Opening - _TC")
    sr.cost_center = args.cost_center or "_Test Cost Center - _TC"
    sr.append(
        "items", {
            "item_code": args.item_code or "_Test Item",
            "warehouse": args.warehouse or "_Test Warehouse - _TC",
            "qty": args.qty,
            "valuation_rate": args.rate
        })

    try:
        sr.submit()
    except EmptyStockReconciliationItemsError:
        pass
    return sr
Beispiel #13
0
def set_stock_balance_as_per_serial_no(item_code=None,
                                       posting_date=None,
                                       posting_time=None,
                                       fiscal_year=None):
    if not posting_date: posting_date = nowdate()
    if not posting_time: posting_time = nowtime()

    condition = " and item.name='%s'" % item_code.replace(
        "'", "\'") if item_code else ""

    bin = dataent.db.sql(
        """select bin.item_code, bin.warehouse, bin.actual_qty, item.stock_uom
		from `tabBin` bin, tabItem item
		where bin.item_code = item.name and item.has_serial_no = 1 %s""" % condition)

    for d in bin:
        serial_nos = dataent.db.sql(
            """select count(name) from `tabSerial No`
			where item_code=%s and warehouse=%s and docstatus < 2""", (d[0], d[1]))

        if serial_nos and flt(serial_nos[0][0]) != flt(d[2]):
            print(d[0], d[1], d[2], serial_nos[0][0])

        sle = dataent.db.sql(
            """select valuation_rate, company from `tabStock Ledger Entry`
			where item_code = %s and warehouse = %s and ifnull(is_cancelled, 'No') = 'No'
			order by posting_date desc limit 1""", (d[0], d[1]))

        sle_dict = {
            'doctype':
            'Stock Ledger Entry',
            'item_code':
            d[0],
            'warehouse':
            d[1],
            'transaction_date':
            nowdate(),
            'posting_date':
            posting_date,
            'posting_time':
            posting_time,
            'voucher_type':
            'Stock Reconciliation (Manual)',
            'voucher_no':
            '',
            'voucher_detail_no':
            '',
            'actual_qty':
            flt(serial_nos[0][0]) - flt(d[2]),
            'stock_uom':
            d[3],
            'incoming_rate':
            sle and flt(serial_nos[0][0]) > flt(d[2]) and flt(sle[0][0]) or 0,
            'company':
            sle and cstr(sle[0][1]) or 0,
            'is_cancelled':
            'No',
            'batch_no':
            '',
            'serial_no':
            ''
        }

        sle_doc = dataent.get_doc(sle_dict)
        sle_doc.flags.ignore_validate = True
        sle_doc.flags.ignore_links = True
        sle_doc.insert()

        args = sle_dict.copy()
        args.update({"sle_id": sle_doc.name, "is_amended": 'No'})

        update_bin(args)
        update_entries_after({
            "item_code": d[0],
            "warehouse": d[1],
            "posting_date": posting_date,
            "posting_time": posting_time
        })