def create_gateway_account():
	company_name = frappe.db.get_value("Global Defaults", None, "default_company")
	if company_name:
		bank_account = frappe.db.get_value("Account", {"account_name": "PayPal", "company": company_name},
			["name", 'account_currency'], as_dict=1)

		if not bank_account:
			# try creating one
			bank_account = create_bank_account({"company_name": company_name, "bank_account": "PayPal"})
			if not bank_account:
				frappe.msgprint(_("Payment Gateway Account not created, please create one manually."))
				return

		if bank_account:
			try:
				frappe.get_doc({
					"doctype": "Payment Gateway Account",
					"is_default": 1,
					"payment_gateway": "PayPal",
					"payment_account": bank_account.name,
					"currency": bank_account.account_currency
				}).insert(ignore_permissions=True)

			except frappe.DuplicateEntryError:
				# already exists, due to a reinstall?
				pass
Пример #2
0
def create_gateway_bank_account(name):
    """Creates a gateway bank account of the same name"""

    company = frappe.db.get_value("Global Defaults", None, "default_company")

    if not company:
        return

    account = frappe.db.get_value("Account", {
        "account_name": _(name),
        "company": company
    }, ["name", "account_currency"],
                                  as_dict=True)

    if not account:
        account = frappe.db.get_value("Account", {
            "account_name": name,
            "company": company
        }, ["name", "account_currency"],
                                      as_dict=True)

    if not account:
        account = create_bank_account({
            "company_name": company,
            "bank_account": _(name)
        })

    if not account:
        frappe.msgprint(
            _("Payment Gatway '{0}' was not created. Please create one manually."
              .format(name)))
        return None

    return account
def create_gateway_account():
	company_name = frappe.db.get_value("Global Defaults", None, "default_company")
	if company_name:
		bank_account = frappe.db.get_value("Account", {"account_name": "PayPal", "company": company_name},
			["name", "account_type"], as_dict=1)
		if not bank_account:
			bank_account = create_bank_account({"company_name": company_name, "bank_account": "PayPal"})
			bank_account = bank_account.name
		elif bank.account_type == "Bank":
			bank_account = bank.name
		else:
			frappe.msgprint(_("Payment Gateway Account not created, please create one manually."))
			return


		bank_account_currency = frappe.db.get_value("Account", bank_account, "account_currency")
		if bank_account and not frappe.db.get_value("Payment Gateway Account",
			{"payment_gateway": "PayPal", "currency": bank_account_currency}, "name"):

			frappe.get_doc({
				"doctype": "Payment Gateway Account",
				"is_default": 1,
				"payment_gateway": "PayPal",
				"payment_account": bank_account.name,
				"currency": bank_account_currency
			}).insert(ignore_permissions=True)
Пример #4
0
def create_payment_gateway_account(gateway):
    from erpnext.setup.setup_wizard.setup_wizard import create_bank_account

    company = frappe.db.get_value("Global Defaults", None, "default_company")
    if not company:
        return

    # NOTE: we translate Payment Gateway account name because that is going to be used by the end user
    bank_account = frappe.db.get_value("Account", {
        "account_name": _(gateway),
        "company": company
    }, ["name", 'account_currency'],
                                       as_dict=1)

    if not bank_account:
        # check for untranslated one
        bank_account = frappe.db.get_value("Account", {
            "account_name": gateway,
            "company": company
        }, ["name", 'account_currency'],
                                           as_dict=1)

    if not bank_account:
        # try creating one
        bank_account = create_bank_account({
            "company_name": company,
            "bank_account": _(gateway)
        })

    if not bank_account:
        frappe.msgprint(
            _("Payment Gateway Account not created, please create one manually."
              ))
        return

    # if payment gateway account exists, return
    if frappe.db.exists("Payment Gateway Account", {
            "payment_gateway": gateway,
            "currency": bank_account.account_currency
    }):
        return

    try:
        frappe.get_doc({
            "doctype": "Payment Gateway Account",
            "is_default": 1,
            "payment_gateway": gateway,
            "payment_account": bank_account.name,
            "currency": bank_account.account_currency
        }).insert(ignore_permissions=True)

    except frappe.DuplicateEntryError:
        # already exists, due to a reinstall?
        pass
def create_gateway_account():
	company_name = frappe.db.get_value("Global Defaults", None, "default_company")
	if company_name:
		company = frappe.get_doc("Company", company_name)

		try:
			bank_account = create_bank_account({"company_name": company_name, "bank_account": "PayPal"})
		except frappe.DuplicateEntryError:
			pass

		if not frappe.db.get_value("Payment Gateway Account", {"gateway": "PayPal",
			"currency": company.default_currency}, "name"):

			frappe.get_doc({
				"doctype": "Payment Gateway Account",
				"is_default": 1,
				"gateway": "PayPal",
				"payment_account": bank_account.name,
				"currency": company.default_currency
			}).insert(ignore_permissions=True)
def create_payment_gateway_account():
	from erpnext.setup.setup_wizard.setup_wizard import create_bank_account

	company = frappe.db.get_value("Global Defaults", None, "default_company")
	if not company:
		return

	# NOTE: we translate Payment Gateway account name because that is going to be used by the end user
	bank_account = frappe.db.get_value("Account", {"account_name": _("PayPal"), "company": company},
		["name", 'account_currency'], as_dict=1)

	if not bank_account:
		# check for untranslated one
		bank_account = frappe.db.get_value("Account", {"account_name": "PayPal", "company": company},
			["name", 'account_currency'], as_dict=1)

	if not bank_account:
		# try creating one
		bank_account = create_bank_account({"company_name": company, "bank_account": _("PayPal")})

	if not bank_account:
		frappe.msgprint(_("Payment Gateway Account not created, please create one manually."))
		return

	# if payment gateway account exists, return
	if frappe.db.exists("Payment Gateway Account",
		{"payment_gateway": "PayPal", "currency": bank_account.account_currency}):
		return

	try:
		frappe.get_doc({
			"doctype": "Payment Gateway Account",
			"is_default": 1,
			"payment_gateway": "PayPal",
			"payment_account": bank_account.name,
			"currency": bank_account.account_currency
		}).insert(ignore_permissions=True)

	except frappe.DuplicateEntryError:
		# already exists, due to a reinstall?
		pass