Пример #1
0
def has_match(meta, perms, refdoc):
	from webnotes.defaults import get_user_default_as_list
	
	if isinstance(refdoc, basestring):
		refdoc = doc(meta[0].name, refdoc)
	
	match_failed = {}
	for p in perms:
		if p.match:
			if ":" in p.match:
				keys = p.match.split(":")
			else:
				keys = [p.match, p.match]
			
			if refdoc.fields.get(keys[0],"[No Value]") in get_user_default_as_list(keys[1]):
				return True
			else:
				match_failed[keys[0]] = refdoc.fields.get(keys[0],"[No Value]")
		else:
			# found a permission without a match
			return True

	# no valid permission found
	if match_failed:
		msg = _("Not allowed for: ")
		for key in match_failed:
			msg += "\n" + (meta.get_field(key) and meta.get_label(key) or key) \
				+ " = " + (match_failed[key] or "None")
		msgprint(msg)
	
	return False
Пример #2
0
def _get_basic_details(args, item_bean, warehouse_fieldname):
	item = item_bean.doc
	
	from webnotes.defaults import get_user_default_as_list
	user_default_warehouse_list = get_user_default_as_list('warehouse')
	user_default_warehouse = user_default_warehouse_list[0] \
		if len(user_default_warehouse_list)==1 else ""
	
	out = webnotes._dict({
			"item_code": item.name,
			"description": item.description_html or item.description,
			warehouse_fieldname: user_default_warehouse or item.default_warehouse \
				or args.get(warehouse_fieldname),
			"income_account": item.default_income_account or args.income_account \
				or webnotes.conn.get_value("Company", args.company, "default_income_account"),
			"expense_account": item.purchase_account or args.expense_account \
				or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
			"cost_center": item.default_sales_cost_center or args.cost_center,
			"qty": 1.0,
			"export_amount": 0.0,
			"amount": 0.0,
			"batch_no": None,
			"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in 
				item_bean.doclist.get({"parentfield": "item_tax"})))),
		})
	
	for fieldname in ("item_name", "item_group", "barcode", "brand", "stock_uom"):
		out[fieldname] = item.fields.get(fieldname)
			
	return out
Пример #3
0
def has_match(meta, perms, refdoc):
    from webnotes.defaults import get_user_default_as_list

    if isinstance(refdoc, basestring):
        refdoc = doc(meta[0].name, refdoc)

    match_failed = {}
    for p in perms:
        if p.match:
            if ":" in p.match:
                keys = p.match.split(":")
            else:
                keys = [p.match, p.match]

            if refdoc.fields.get(keys[0],
                                 "[No Value]") in get_user_default_as_list(
                                     keys[1]):
                return True
            else:
                match_failed[keys[0]] = refdoc.fields.get(
                    keys[0], "[No Value]")
        else:
            # found a permission without a match
            return True

    # no valid permission found
    if match_failed:
        msg = _("Not allowed for: ")
        for key in match_failed:
            msg += "\n" + (meta.get_field(key) and meta.get_label(key) or key) \
             + " = " + (match_failed[key] or "None")
        msgprint(msg)

    return False
Пример #4
0
 def get_user_default_price_list(self, price_list_for):
     from webnotes.defaults import get_user_default_as_list
     user_default_price_list = get_user_default_as_list(
         "selling_price_list" if price_list_for ==
         "Selling" else "buying_price_list")
     return user_default_price_list[0] if len(
         user_default_price_list) == 1 else ""
Пример #5
0
def _get_basic_details(args, item_bean, warehouse_fieldname):
    item = item_bean.doc

    from webnotes.defaults import get_user_default_as_list
    user_default_warehouse_list = get_user_default_as_list('warehouse')
    user_default_warehouse = user_default_warehouse_list[0] \
     if len(user_default_warehouse_list)==1 else ""

    out = webnotes._dict({
      "item_code": item.name,
      "description": item.description_html or item.description,
      warehouse_fieldname: user_default_warehouse or item.default_warehouse \
       or args.get(warehouse_fieldname),
      "income_account": item.default_income_account or args.income_account \
       or webnotes.conn.get_value("Company", args.company, "default_income_account"),
      "expense_account": item.purchase_account or args.expense_account \
       or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
      "cost_center": item.default_sales_cost_center or args.cost_center,
      "qty": 1.0,
      "export_amount": 0.0,
      "amount": 0.0,
      "batch_no": None,
      "item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
       item_bean.doclist.get({"parentfield": "item_tax"})))),
     })

    for fieldname in ("item_name", "item_group", "barcode", "brand",
                      "stock_uom"):
        out[fieldname] = item.fields.get(fieldname)

    return out
Пример #6
0
def has_permission(doctype, ptype="read", refdoc=None):
    """check if user has permission"""
    from webnotes.defaults import get_user_default_as_list

    if session.user == "Administrator":
        return True
    if conn.get_value("DocType", doctype, "istable"):
        return True
    if isinstance(refdoc, basestring):
        refdoc = doc(doctype, refdoc)

    perms = conn.sql(
        """select `name`, `match` from tabDocPerm p
		where p.parent = %s
		and ifnull(p.`%s`,0) = 1
		and ifnull(p.permlevel,0) = 0
		and (p.role="All" or p.role in (select `role` from tabUserRole where `parent`=%s))
		"""
        % ("%s", ptype, "%s"),
        (doctype, session.user),
        as_dict=1,
    )

    if refdoc:
        match_failed = {}
        for p in perms:
            if p.match:
                if ":" in p.match:
                    keys = p.match.split(":")
                else:
                    keys = [p.match, p.match]

                if refdoc.fields.get(keys[0], "[No Value]") in get_user_default_as_list(keys[1]):
                    return True
                else:
                    match_failed[keys[0]] = refdoc.fields.get(keys[0], "[No Value]")
            else:
                # found a permission without a match
                return True

                # no valid permission found
        if match_failed:
            doctypelist = get_doctype(doctype)
            msg = _("Not allowed for: ")
            for key in match_failed:
                msg += (
                    "\n"
                    + (doctypelist.get_field(key) and doctypelist.get_label(key) or key)
                    + " = "
                    + (match_failed[key] or "None")
                )
            msgprint(msg)

        return False
    else:
        return perms and True or False
Пример #7
0
def has_permission(doctype, ptype="read", refdoc=None):
    """check if user has permission"""
    from webnotes.defaults import get_user_default_as_list
    if session.user == "Administrator":
        return True
    if conn.get_value("DocType", doctype, "istable"):
        return True
    if isinstance(refdoc, basestring):
        refdoc = doc(doctype, refdoc)

    perms = conn.sql("""select `name`, `match` from tabDocPerm p
		where p.parent = %s
		and ifnull(p.`%s`,0) = 1
		and ifnull(p.permlevel,0) = 0
		and (p.role="All" or p.role in (select `role` from tabUserRole where `parent`=%s))
		""" % ("%s", ptype, "%s"), (doctype, session.user),
                     as_dict=1)

    if refdoc:
        match_failed = {}
        for p in perms:
            if p.match:
                if ":" in p.match:
                    keys = p.match.split(":")
                else:
                    keys = [p.match, p.match]

                if refdoc.fields.get(keys[0],
                                     "[No Value]") in get_user_default_as_list(
                                         keys[1]):
                    return True
                else:
                    match_failed[keys[0]] = refdoc.fields.get(
                        keys[0], "[No Value]")
            else:
                # found a permission without a match
                return True

        # no valid permission found
        if match_failed:
            doctypelist = get_doctype(doctype)
            msg = _("Not allowed for: ")
            for key in match_failed:
                msg += "\n" + (doctypelist.get_field(key) and doctypelist.get_label(key) or key) \
                 + " = " + (match_failed[key] or "None")
            msgprint(msg)

        return False
    else:
        return perms and True or False
Пример #8
0
def has_permission(doctype, ptype="read", doc=None):
	"""check if user has permission"""
	from webnotes.defaults import get_user_default_as_list
	if session.user=="Administrator": 
		return True
	if conn.get_value("DocType", doctype, "istable"):
		return True
	perms = conn.sql("""select `name`, `match` from tabDocPerm p
		where p.parent = %s
		and ifnull(p.`%s`,0) = 1
		and ifnull(p.permlevel,0) = 0
		and (p.role="All" or p.role in (select `role` from tabUserRole where `parent`=%s))
		""" % ("%s", ptype, "%s"), (doctype, session.user), as_dict=1)
	
	if doc:
		match_failed = {}
		for p in perms:
			if p.match:
				if ":" in p.match:
					keys = p.match.split(":")
				else:
					keys = [p.match, p.match]
					
				if doc.fields.get(keys[0],"[No Value]") \
						in get_user_default_as_list(keys[1]):
					return True
				else:
					match_failed[keys[0]] = doc.fields.get(keys[0],"[No Value]")
			else:
				# found a permission without a match
				return True

		# no valid permission found
		if match_failed:
			key = match_failed.keys()[0]
			msgprint(_("Not allowed for: ") + key + "=" + match_failed[key])
		return False
	else:
		return perms and True or False
Пример #9
0
	def get_user_default_price_list(self, price_list_for):
		from webnotes.defaults import get_user_default_as_list
		user_default_price_list = get_user_default_as_list("selling_price_list" 
			if price_list_for=="Selling" else "buying_price_list")
		return user_default_price_list[0] if len(user_default_price_list)==1 else ""