Ejemplo n.º 1
0
def on_login_post_session(login_manager):
	"""
		called after login
		update login_from and delete parallel sessions
	"""
	# Clear previous sessions i.e. logout previous log-in attempts
	allow_multiple_sessions = ['*****@*****.**', 'Administrator', 'Guest']
	if webnotes.session['user'] not in allow_multiple_sessions:
		from webnotes.sessions import clear_sessions
		clear_sessions(webnotes.session.user, keep_current=True)

		# check if account is expired
		check_if_expired()

	if webnotes.session['user'] not in ('Guest', '*****@*****.**'):
		# create feed
		from webnotes.utils import nowtime
		from webnotes.profile import get_user_fullname
		webnotes.conn.begin()
		home.make_feed('Login', 'Profile', login_manager.user, login_manager.user,
			'%s logged in at %s' % (get_user_fullname(login_manager.user), nowtime()), 
			login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')
		webnotes.conn.commit()
		
	if webnotes.conn.get_value("Profile", webnotes.session.user, "user_type") == "Website User":
		from website.helpers.cart import set_cart_count
		set_cart_count()
Ejemplo n.º 2
0
def on_login_post_session(login_manager):
    """
		called after login
		update login_from and delete parallel sessions
	"""
    # Clear previous sessions i.e. logout previous log-in attempts
    exception_list = ['*****@*****.**', 'Administrator', 'Guest']
    if webnotes.session['user'] not in exception_list:
        sid_list = webnotes.conn.sql("""
			DELETE FROM `tabSessions`
			WHERE
				user=%s AND
				sid!=%s""", \
         (webnotes.session['user'], webnotes.session['sid']), as_list=1)

        # check if account is expired
        check_if_expired()

    if webnotes.session['user'] not in ('Guest', '*****@*****.**'):
        # create feed
        from webnotes.utils import nowtime
        from webnotes.profile import get_user_fullname
        home.make_feed(
            'Login', 'Profile', login_manager.user, login_manager.user,
            '%s logged in at %s' %
            (get_user_fullname(login_manager.user), nowtime()),
            login_manager.user == 'Administrator' and '#8CA2B3' or '#1B750D')
Ejemplo n.º 3
0
def on_login_post_session(login_manager):
    """
		called after login
		update login_from and delete parallel sessions
	"""
    # Clear previous sessions i.e. logout previous log-in attempts
    allow_multiple_sessions = ["*****@*****.**", "Administrator", "Guest"]
    if webnotes.session["user"] not in allow_multiple_sessions:
        from webnotes.sessions import clear_sessions

        clear_sessions(webnotes.session.user, keep_current=True)

        # check if account is expired
        check_if_expired()

    if webnotes.session["user"] not in ("Guest", "*****@*****.**"):
        # create feed
        from webnotes.utils import nowtime
        from webnotes.profile import get_user_fullname

        home.make_feed(
            "Login",
            "Profile",
            login_manager.user,
            login_manager.user,
            "%s logged in at %s" % (get_user_fullname(login_manager.user), nowtime()),
            login_manager.user == "Administrator" and "#8CA2B3" or "#1B750D",
        )
Ejemplo n.º 4
0
def on_login_post_session(login_manager):
	"""
		called after login
		update login_from and delete parallel sessions
	"""
	# Clear previous sessions i.e. logout previous log-in attempts
	exception_list = ['*****@*****.**', 'Administrator', 'Guest']
	if webnotes.session['user'] not in exception_list:
		sid_list = webnotes.conn.sql("""
			DELETE FROM `tabSessions`
			WHERE
				user=%s AND
				sid!=%s""", \
			(webnotes.session['user'], webnotes.session['sid']), as_list=1)

		# check if account is expired
		check_if_expired()

	if webnotes.session['user'] not in ('Guest', '*****@*****.**'):
		# create feed
		from webnotes.utils import nowtime
		from webnotes.profile import get_user_fullname
		home.make_feed('Login', 'Profile', login_manager.user, login_manager.user,
			'%s logged in at %s' % (get_user_fullname(login_manager.user), nowtime()), 
			login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')		
Ejemplo n.º 5
0
def on_login_post_session(login_manager):
    """
		called after login
		update login_from and delete parallel sessions
	"""
    # Clear previous sessions i.e. logout previous log-in attempts
    allow_multiple_sessions = ['*****@*****.**', 'Administrator', 'Guest']
    if webnotes.session['user'] not in allow_multiple_sessions:
        from webnotes.sessions import clear_sessions
        clear_sessions(webnotes.session.user, keep_current=True)

        # check if account is expired
        check_if_expired()

    if webnotes.session['user'] not in ('Guest', '*****@*****.**'):
        # create feed
        from webnotes.utils import nowtime
        from webnotes.profile import get_user_fullname
        webnotes.conn.begin()
        home.make_feed(
            'Login', 'Profile', login_manager.user, login_manager.user,
            '%s logged in at %s' %
            (get_user_fullname(login_manager.user), nowtime()),
            login_manager.user == 'Administrator' and '#8CA2B3' or '#1B750D')
        webnotes.conn.commit()

    if webnotes.conn.get_value("Profile", webnotes.session.user,
                               "user_type") == "Website User":
        from website.helpers.cart import set_cart_count
        set_cart_count()
Ejemplo n.º 6
0
def execute():
	item_map = {}
	for item in webnotes.conn.sql("""select * from tabItem""", as_dict=1):
		item_map.setdefault(item.name, item)
	
	warehouse_map = get_warehosue_map()
	naming_series = "STE/13/"
	
	for company in webnotes.conn.sql("select name from tabCompany"):
		stock_entry = [{
			"doctype": "Stock Entry",
			"naming_series": naming_series,
			"posting_date": nowdate(),
			"posting_time": nowtime(),
			"purpose": "Material Transfer",
			"company": company[0],
			"remarks": "Material Transfer to activate perpetual inventory",
			"fiscal_year": get_fiscal_year(nowdate())[0]
		}]
		expense_account = "Cost of Goods Sold - NISL"
		cost_center = "Default CC Ledger - NISL"
		
		for bin in webnotes.conn.sql("""select * from tabBin bin where ifnull(item_code, '')!='' 
				and ifnull(warehouse, '') in (%s) and ifnull(actual_qty, 0) != 0
				and (select company from tabWarehouse where name=bin.warehouse)=%s""" %
				(', '.join(['%s']*len(warehouse_map)), '%s'), 
				(warehouse_map.keys() + [company[0]]), as_dict=1):
			item_details = item_map[bin.item_code]
			new_warehouse = warehouse_map[bin.warehouse].get("fixed_asset_warehouse") \
				if cstr(item_details.is_asset_item) == "Yes" \
				else warehouse_map[bin.warehouse].get("current_asset_warehouse")
				
			if item_details.has_serial_no == "Yes":
				serial_no = "\n".join([d[0] for d in webnotes.conn.sql("""select name 
					from `tabSerial No` where item_code = %s and warehouse = %s 
					and status in ('Available', 'Sales Returned')""", 
					(bin.item_code, bin.warehouse))])
			else:
				serial_no = None
			
			stock_entry.append({
				"doctype": "Stock Entry Detail",
				"parentfield": "mtn_details",
				"s_warehouse": bin.warehouse,
				"t_warehouse": new_warehouse,
				"item_code": bin.item_code,
				"description": item_details.description,
				"qty": bin.actual_qty,
				"transfer_qty": bin.actual_qty,
				"uom": item_details.stock_uom,
				"stock_uom": item_details.stock_uom,
				"conversion_factor": 1,
				"expense_account": expense_account,
				"cost_center": cost_center,
				"serial_no": serial_no
			})
		
		webnotes.bean(stock_entry).insert()
Ejemplo n.º 7
0
def create_profile(usr, name):
	d = Document("Profile")
	d.owner = "Administrator"
	d.email = usr
	d.first_name = name
	d.enabled = 1
	d.creation = nowdate() + ' ' + nowtime()
	d.user_type = "System User"
	d.save(1)
Ejemplo n.º 8
0
def get_new_doc(doctype, parent_doc = None, parentfield = None):
	doc = webnotes.doc({
		"doctype": doctype,
		"__islocal": 1,
		"owner": webnotes.session.user,
		"docstatus": 0
	})
	
	meta = webnotes.get_doctype(doctype)
	
	restrictions = webnotes.defaults.get_restrictions()
	
	if parent_doc:
		doc.parent = parent_doc.name
		doc.parenttype = parent_doc.doctype
	
	if parentfield:
		doc.parentfield = parentfield
	
	for d in meta.get({"doctype":"DocField", "parent": doctype}):
		default = webnotes.defaults.get_user_default(d.fieldname)
		
		if (d.fieldtype=="Link") and d.ignore_restrictions != 1 and (d.options in restrictions)\
			and len(restrictions[d.options])==1:
			doc.fields[d.fieldname] = restrictions[d.options][0]
		elif default:
			doc.fields[d.fieldname] = default
		elif d.fields.get("default"):
			if d.default == "__user":
				doc.fields[d.fieldname] = webnotes.session.user
			elif d.default == "Today":
				doc.fields[d.fieldname] = nowdate()

			elif d.default.startswith(":"):
				ref_fieldname = d.default[1:].lower().replace(" ", "_")
				if parent_doc:
					ref_docname = parent_doc.fields[ref_fieldname]
				else:
					ref_docname = webnotes.conn.get_default(ref_fieldname)
				doc.fields[d.fieldname] = webnotes.conn.get_value(d.default[1:], 
					ref_docname, d.fieldname)

			else:
				doc.fields[d.fieldname] = d.default
			
			# convert type of default
			if d.fieldtype in ("Int", "Check"):
				doc.fields[d.fieldname] = cint(doc.fields[d.fieldname])
			elif d.fieldtype in ("Float", "Currency"):
				doc.fields[d.fieldname] = flt(doc.fields[d.fieldname])
				
		elif d.fieldtype == "Time":
			doc.fields[d.fieldname] = nowtime()
			
	return doc
Ejemplo n.º 9
0
def get_new_doc(doctype, parent_doc = None, parentfield = None):
	doc = webnotes.doc({
		"doctype": doctype,
		"__islocal": 1,
		"owner": webnotes.session.user,
		"docstatus": 0
	})
	
	meta = webnotes.get_doctype(doctype)
	
	if parent_doc:
		doc.parent = parent_doc.name
		doc.parenttype = parent_doc.doctype
	
	if parentfield:
		doc.parentfield = parentfield
	
	for d in meta.get({"doctype":"DocField", "parent": doctype}):
		default = webnotes.defaults.get_user_default(d.fieldname)
		if default:
			doc.fields[d.fieldname] = default
		elif d.fields.get("default"):
			if d.default == "__user":
				doc.fields[d.fieldname] = webnotes.session.user
			elif d.default == "Today":
				doc.fields[d.fieldname] = nowdate()

			elif d.default.startswith(":"):
				ref_fieldname = d.default[1:].lower().replace(" ", "_")
				if parent_doc:
					ref_docname = parent_doc.fields[ref_fieldname]
				else:
					ref_docname = webnotes.conn.get_default(ref_fieldname)
				doc.fields[d.fieldname] = webnotes.conn.get_value(d.default[1:], 
					ref_docname, d.fieldname)

			else:
				doc.fields[d.fieldname] = d.default
			
			# convert type of default
			if d.fieldtype in ("Int", "Check"):
				doc.fields[d.fieldname] = cint(doc.fields[d.fieldname])
			elif d.fieldtype in ("Float", "Currency"):
				doc.fields[d.fieldname] = flt(doc.fields[d.fieldname])
				
		elif d.fieldtype == "Time":
			doc.fields[d.fieldname] = nowtime()
			
	return doc
Ejemplo n.º 10
0
	def check_profile(self, user, user_id, pwd, role):
		"check for profile if not exist creates new profile"
		profile = webnotes.conn.sql("select name from tabProfile where name = %s",user)
		if not profile:
			from webnotes.model.doc import Document
			from webnotes.utils import nowdate,  nowtime
			d = Document("Profile")
			d.owner = "Administrator"
			d.email = user
			d.first_name = user_id
			d.enabled = 1
			d.new_password = pwd
			d.creation = nowdate() + ' ' + nowtime()
			d.user_type = "System User"
			d.save(1)

		self.assign_role(user, user_id, role)
Ejemplo n.º 11
0
def on_login_post_session(login_manager):
    """
		called after login
		update login_from and delete parallel sessions
	"""
    # Clear previous sessions i.e. logout previous log-in attempts
    allow_multiple_sessions = ["*****@*****.**", "Administrator", "Guest"]
    if webnotes.session["user"] not in allow_multiple_sessions:
        from webnotes.sessions import clear_sessions

        clear_sessions(webnotes.session.user, keep_current=True)

        # check if account is expired
        check_if_expired()

    if webnotes.session["user"] not in ("Guest", "*****@*****.**"):
        # create feed
        from webnotes.utils import nowtime
        from webnotes.profile import get_user_fullname

        webnotes.conn.begin()
        home.make_feed(
            "Login",
            "Profile",
            login_manager.user,
            login_manager.user,
            "%s logged in at %s" % (get_user_fullname(login_manager.user), nowtime()),
            login_manager.user == "Administrator" and "#8CA2B3" or "#1B750D",
        )
        webnotes.conn.commit()

    if (
        webnotes.conn.get_default("shopping_cart_enabled")
        and webnotes.conn.get_value("Profile", webnotes.session.user, "user_type") == "Website User"
    ):
        from selling.utils.cart import set_cart_count

        set_cart_count()
Ejemplo n.º 12
0
	def create_dn(self):
		'''
		import urllib.request
                import json
		json_dict=[]
		'''
		dn=Document('Delivery Note')
		dn.customer=self.doc.customer
		dn.customer_name=webnotes.conn.get_value("Customer",self.doc.customer,"customer_name")		
		dn.company='InnoWorth'
                dn.conversion_rate=1.00
		dn.posting_date=nowdate()
		dn.posting_time=nowtime()
		dn.customer_address=webnotes.conn.get_value("Address",{"customer":self.doc.customer},"name")
		dn.address_display=get_address_display(dn.customer_address)
		dn.price_list_currency='INR'
                dn.currency='INR'
		dn.docstatus=1
		dn.status="Submitted"
                dn.selling_price_list='Standard Selling'
                dn.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year")
		dn.save()
		j=0
		html=""
		net_tot=0.00
		for s in getlist(self.doclist,"purchase_receipt_details"):
			j=j+1
			dni=Document("Delivery Note Item")
			dni.item_code=s.item_code
			dni.item_name=s.item_name
			dni.description=s.description
			dni.qty=s.qty
			dni.docstatus=1
			dni.ref_rate=webnotes.conn.get_value("Item Price",{"item_code":dni.item_code,"price_list":"Standard Selling"},"ref_rate")
                        dni.export_rate=webnotes.conn.get_value("Item Price",{"item_code":dni.item_code,"price_list":"Standard Selling"},"ref_rate")
			dni.export_amount=cstr(flt(s.qty)*flt(dni.ref_rate))
			net_tot=cstr(flt(net_tot)+flt(dni.export_amount))
			dni.warehouse=s.warehouse
			dni.stock_uom=s.uom
			dni.serial_no=s.serial_no
			dni.parent=dn.name
			dni.save()
			update_bin=("update tabBin set actual_qty=actual_qty-"+cstr(dni.qty)+" and projected_qty=projected_qty-"+cstr(dni.qty)+" where item_code='"+dni.item_code+"' and warehouse='"+dni.warehouse+"'")
			html+=("<tr><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(j)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.item_code)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.description)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;text-align:right;'><div>"+cstr(dni.qty)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'>"+cstr(dni.stock_uom)+"</td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align:right'>₹ "+cstr(dni.ref_rate)+"</div></td><td style='border:1px solid rgb(153, 153, 153);word-wrap: break-word;'><div style='text-align: right'>₹ "+cstr(dni.export_amount)+"</div></td></tr>")
			stl=Document("Stock Ledger Entry")
			stl.item_code=s.item_code
			stl.stock_uom=s.uom
			stl.serial_no=s.serial_no
			stl.warehouse=s.warehouse
			stl.posting_date=nowdate()
			stl.voucher_type="Delivery Note"
			stl.voucher_no=dn.name
			stl.voucher_detail_no=dni.name
			stl.is_cancelled="No"
			stl.fiscal_year=webnotes.conn.get_value("Global Defaults", None, "current_fiscal_year")
			stl.actual_qty=cstr(s.qty)
			qty=webnotes.conn.sql("select qty_after_transaction from `tabStock Ledger Entry` where item_code='"+s.item_code+"' and warehouse='"+s.warehouse+"' order by name desc limit 1",as_list=1)
			stl.qty_after_transaction=cstr(flt(qty[0][0])-flt(s.qty))
			stl.save()
			if dni.serial_no:
				for se in dni.serial_no:
					update=webnotes.conn.sql("update `tabSerial No` set status='Delivered', warehouse=(select name from tabCustomer where 1=2) where name='"+se+"'")
					#json_dict.append({"serial_no":se,"supplier_name":self.doc.supplier_name,"item_code":s.item_code})

		dn_=Document("Delivery Note",dn.name)
		dn_.net_total_export=cstr(net_tot)
                dn_.grand_total_export=cstr(net_tot)
                dn_.rounded_total_export=cstr(net_tot)
		a=html_data({"posting_date":datetime.datetime.strptime(nowdate(),'%Y-%m-%d').strftime('%d/%m/%Y'),"due_date":"","customer_name":dn.customer_name,"net_total":dn_.net_total_export,"grand_total":dn_.grand_total_export,"rounded_total":dn_.rounded_total_export,"table_data":html,"date_1":"Posting Date","date_2":"","doctype":"Delivery Note","doctype_no":dn.name,"company":dn.company,"addr_name":"Address","address":dn.address_display,"tax_detail":""})
                attach_file(a,[dn.name,"Selling/Kirana","Delivery Note"])
		'''
def execute():
    webnotes.conn.auto_commit_on_many_writes = 1
    item_map = {}
    for item in webnotes.conn.sql("""select * from tabItem""", as_dict=1):
        item_map.setdefault(item.name, item)

    warehouse_map = get_warehosue_map()
    naming_series = "STE"

    for company, default_expense_account, cost_center in webnotes.conn.sql(
        "select name, default_expense_account, cost_center from tabCompany"
    ):
        stock_entry = [
            {
                "doctype": "Stock Entry",
                "naming_series": naming_series,
                "posting_date": nowdate(),
                "posting_time": nowtime(),
                "purpose": "Material Transfer",
                "company": company,
                "remarks": "Material Transfer to activate perpetual inventory",
                "fiscal_year": get_fiscal_year(nowdate())[0],
            }
        ]
        stock_entry_details = []
        for bin in webnotes.conn.sql(
            """select * from tabBin bin where ifnull(item_code, '')!='' 
				and ifnull(warehouse, '') in (%s) and ifnull(actual_qty, 0) != 0
				and (select company from tabWarehouse where name=bin.warehouse)=%s"""
            % (", ".join(["%s"] * len(warehouse_map)), "%s"),
            (warehouse_map.keys() + [company]),
            as_dict=1,
        ):
            item_details = item_map[bin.item_code]
            # new_warehouse = warehouse_map[bin.warehouse].get("fixed_asset_warehouse") \
            # 	if cstr(item_details.is_asset_item) == "Yes" \
            # 	else warehouse_map[bin.warehouse].get("current_asset_warehouse")

            # for vence
            new_warehouse = warehouse_map[bin.warehouse].get("current_asset_warehouse") or warehouse_map[
                bin.warehouse
            ].get("fixed_asset_warehouse")

            if item_details.has_serial_no == "Yes":
                serial_no = "\n".join(
                    [
                        d[0]
                        for d in webnotes.conn.sql(
                            """select name 
					from `tabSerial No` where item_code = %s and warehouse = %s 
					and status in ('Available', 'Sales Returned')""",
                            (bin.item_code, bin.warehouse),
                        )
                    ]
                )
            else:
                serial_no = None

            stock_entry_details.append(
                {
                    "doctype": "Stock Entry Detail",
                    "parentfield": "mtn_details",
                    "s_warehouse": bin.warehouse,
                    "t_warehouse": new_warehouse,
                    "item_code": bin.item_code,
                    "item_name": item_details.item_name,
                    "description": item_details.description,
                    "qty": bin.actual_qty,
                    "transfer_qty": bin.actual_qty,
                    "uom": item_details.stock_uom,
                    "stock_uom": item_details.stock_uom,
                    "conversion_factor": 1,
                    "expense_account": default_expense_account,
                    "cost_center": cost_center,
                    "serial_no": serial_no,
                }
            )

        se = []
        for i, details in enumerate(stock_entry_details):
            se.append(details)
            if (i + 1) % 200 == 0:
                webnotes.bean(stock_entry + se).insert()
                se = []
        if len(se) > 1:
            webnotes.bean(stock_entry + se).insert()

    webnotes.conn.auto_commit_on_many_writes = 0
Ejemplo n.º 14
0
def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, posting_time=None,
	 	fiscal_year=None):
	from webnotes.utils import flt, cstr
	from webnotes.model.doc import Document
	from stock.utils import update_bin
	from stock.stock_ledger import update_entries_after
	from accounts.utils import get_fiscal_year
	
	if not posting_date: posting_date = nowdate()
	if not posting_time: posting_time = nowtime()
	if not fiscal_year: fiscal_year = get_fiscal_year(posting_date)[0]
	
	condition = " and item.name='%s'" % item_code.replace("'", "\'") if item_code else ""
		
	bin = webnotes.conn.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 = 'Yes' %s""" % condition)

	for d in bin:
		serial_nos = webnotes.conn.sql("""select count(name) from `tabSerial No` 
			where item_code=%s and warehouse=%s and status = 'Available' 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 = webnotes.conn.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]))

		sl_entries = {
			'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,
			'fiscal_year'				: fiscal_year,
			'is_cancelled'			 	: 'No',
			'batch_no'					: '',
			'serial_no'					: ''
		}
		
		sle = Document(fielddata=sl_entries)
		sle = sle.insert()
		
		args = sl_entries.copy()
		args.update({
			"sle_id": sle.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
		})