本文整理汇总了Python中frappe.throw方法的典型用法代码示例。如果您正苦于以下问题:Python frappe.throw方法的具体用法?Python frappe.throw怎么用?Python frappe.throw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frappe
的用法示例。
在下文中一共展示了frappe.throw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: before_cancel
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def before_cancel(plant_entry):
if plant_entry.purpose == "Convert" or not plant_entry.bio_transaction:
return
if plant_entry.purpose == "Harvest":
action = "plant_harvest_undo"
else:
action = "plant_cure_undo"
try:
call(action, {
"transactionid": plant_entry.bio_transaction
})
except BioTrackClientError as e:
frappe.throw(cstr(e.message), title="BioTrackTHC sync up failed")
plant_entry.bio_transaction = ""
示例2: validate_price_list_currency
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def validate_price_list_currency(doc, method):
'''Called from Shopping Cart Settings hook'''
if doc.enabled and doc.enable_checkout:
if not doc.payment_gateway_account:
doc.enable_checkout = 0
return
payment_gateway_account = frappe.get_doc("Payment Gateway Account", doc.payment_gateway_account)
if payment_gateway_account.payment_gateway=="Razorpay":
price_list_currency = frappe.db.get_value("Price List", doc.price_list, "currency")
validate_transaction_currency(price_list_currency)
if price_list_currency != payment_gateway_account.currency:
frappe.throw(_("Currency '{0}' of Price List '{1}' should be same as the Currency '{2}' of Payment Gateway Account '{3}'").format(price_list_currency, doc.price_list, payment_gateway_account.currency, payment_gateway_account.name))
示例3: validate_account_types
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def validate_account_types(company):
account_types_for_ledger = ["Cost of Goods Sold", "Depreciation", "Expenses Included In Valuation",
"Fixed Asset", "Payable", "Receivable", "Stock Adjustment", "Stock Received But Not Billed"]
for account_type in account_types_for_ledger:
if not frappe.db.get_value("Account",
{"company": company, "account_type": account_type, "is_group": 0}):
frappe.throw(_("Please identify / create {0} Account (Ledger)").format(account_type))
account_types_for_group = ["Bank", "Cash", "Stock"]
for account_type in account_types_for_group:
if not frappe.db.get_value("Account",
{"company": company, "account_type": account_type, "is_group": 1}):
frappe.throw(_("Please identify / create {0} Account (Group)").format(account_type))
示例4: add_testing_results
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def add_testing_results(name, testing_results, is_testing_rejected=None):
if frappe.db.get_value("Warranty Request", name, "is_testing_completed"):
frappe.throw("Testing is already completed.")
frappe.db.set_value("Warranty Request", name, "is_testing_completed", 1)
update_status("Warranty Request", name, "Testing Completed")
frappe.db.set_value("Warranty Request Purposes", {"parent": name}, "testing_results", testing_results)
doc_warranty_request = frappe.get_doc("Warranty Request", name)
doc_warranty_request.add_comment("Comment", _("Testing Item has been completed"))
frappe.msgprint("Testing Item has been completed.")
if is_testing_rejected:
frappe.db.set_value("Warranty Request", name, "is_testing_rejected", 1)
dn = make_delivery_note(name)
dn.insert()
frappe.db.set_value("Warranty Request", name, "delivery_note", dn.name)
update_status("Warranty Request", name, "Closed")
frappe.msgprint("Delivery Note %s was created automatically" % dn.name)
warranty_claim = frappe.db.get_value("Warranty Request", name, "warranty_claim")
if warranty_claim:
update_status("Warranty Claim", warranty_claim, frappe.db.get_value("Warranty Request", name, "status"))
frappe.clear_cache(doctype="Warranty Request")
示例5: add_repairing_results
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def add_repairing_results(name, repairing_results, is_item_to_be_replaced=None):
if frappe.db.get_value("Warranty Request", name, "is_repairing_completed"):
frappe.throw("Repairing is already completed")
frappe.db.set_value("Warranty Request", name, "is_repairing_completed", 1)
update_status("Warranty Request", name, "Repairing Completed")
frappe.db.set_value("Warranty Request", name, "resolution_date", now_datetime())
frappe.db.set_value("Warranty Request Purposes", {"parent": name}, "work_done", repairing_results)
warranty_claim = frappe.db.get_value("Warranty Request", name, "warranty_claim")
if warranty_claim:
update_status("Warranty Claim", warranty_claim, "Repairing Completed")
doc_warranty_request = frappe.get_doc("Warranty Request", name)
doc_warranty_request.add_comment("Comment", _("Repairing Item has been completed"))
if is_item_to_be_replaced:
frappe.db.set_value("Warranty Request", name, "is_item_to_be_replaced", 1)
so = make_sales_order(name)
so.insert()
frappe.db.set_value("Warranty Request", name, "sales_order", so.name)
update_status("Warranty Request", name, "Closed")
frappe.msgprint("sales Order %s was created automatically" % so.name)
frappe.clear_cache(doctype="Warranty Request")
示例6: destroy_schedule
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def destroy_schedule(self, reason, reason_txt=None, override=None):
if self.destroy_scheduled and not override:
frappe.throw(
"Plant <strong>{}</strong> has already been scheduled for destruction.".format(
self.name))
reason_type = removal_reasons.keys()[removal_reasons.values().index(reason)]
if not self.flags.ignore_hooks:
self.run_method("on_destroy_schedule", reason_type=reason_type, reason=reason_txt, override=override)
self.destroy_scheduled = 1
self.remove_reason = reason_txt or reason
self.remove_time = now()
self.flags.ignore_validate_update_after_submit = True
self.save()
示例7: on_conversion
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def on_conversion(doc, method):
qty = 0
data = []
for entry in doc.get("items"):
bio_barcode = frappe.get_value("Item", entry.item_code, "bio_barcode")
if not bio_barcode:
frappe.throw(_("{0} is not a BioTrack Item. Consider to select BioTrack items only or turn off BioTrack sync-up").format(entry.item_code))
data.append({
"barcodeid": bio_barcode,
"remove_quantity": entry.qty,
"remove_quantity_uom": "g",
})
qty += entry.qty
if doc.conversion == 'Create Lot':
_create_lot(doc, data)
else:
_create_product(doc, data)
示例8: after_insert
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def after_insert(doc):
bio_id = generate_id(doc)
try:
res = call("plant_room_add", {
"id": bio_id,
"name": doc.plant_room_name,
"location": get_location(),
})
except BioTrackClientError as e:
frappe.throw(cstr(e.message), title="BioTrackTHC sync up failed")
else:
frappe.db.set_value(doc.doctype, doc.name, {
"bio_id": bio_id,
"bio_name": doc.plant_room_name,
"bio_transactionid": res.get("transactionid")
}, None, update_modified=False)
示例9: on_update
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def on_update(doc):
if is_bio_plant_room(doc) and doc.plant_room_name != doc.bio_name:
frappe.log(doc.plant_room_name)
frappe.log(doc.bio_name)
try:
res = call("plant_room_modify", {
"id": doc.bio_id,
"name": doc.plant_room_name,
"location": get_location(),
})
except BioTrackClientError as e:
frappe.throw(cstr(e.message), title="BioTrackTHC sync up failed")
else:
frappe.db.set_value(doc.doctype, doc.name, {
"bio_name": doc.plant_room_name,
"bio_transactionid": res.get("transactionid")
}, None, update_modified=False)
示例10: on_plant_move
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def on_plant_move(plants, plant_room):
if not plant_room.external_id:
return
barcodeid = []
for plant in plants:
if is_bio_plant(plant):
barcodeid.append(plant.get("bio_barcode"))
if len(barcodeid):
try:
call("plant_move", {
"room": plant_room.external_id,
"barcodeid": barcodeid,
})
except BioTrackClientError as e:
frappe.throw(cstr(e.message), title="BioTrackTHC sync up failed")
示例11: convert_on_submit
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def convert_on_submit(plant_entry, barcodeid):
res = None
try:
res = call("plant_convert_to_inventory", {
"barcodeid": barcodeid
})
except BioTrackClientError as e:
frappe.throw(cstr(e.message), title="BioTrackTHC sync up failed")
if res:
plant_entry.bio_transaction = res.get("transactionid")
items = plant_entry.items or {}
for name in items:
item = items[name]
if not item.barcode:
plant = frappe.get_doc("Plant", name)
if is_bio_plant(plant):
item.barcode = plant.get("bio_barcode")
item.bio_barcode = plant.get("bio_barcode")
item.save()
示例12: raise_exception
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def raise_exception(res, exc):
if hasattr(exc.args[0], "startswith"):
if exc.args[0] and exc.args[0].startswith("400"):
raise InvalidRequest(res.json().get("error", {}).get("description"))
elif exc.args[0] and exc.args[0].startswith("401"):
raise AuthenticationError(res.json().get("error", {}).get("description"))
elif exc.args[0] and (exc.args[0].startswith("500") or exc.args[0].startswith("502") or exc.args[0].startswith("504")):
raise GatewayError(res.json().get("error", {}).get("description"))
else:
frappe.throw(exc.message)
示例13: validate_transaction_currency
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def validate_transaction_currency(transaction_currency):
if transaction_currency != "INR":
frappe.throw(_("Please select another payment method. Razorpay does not support transactions in currency '{0}'").format(transaction_currency))
示例14: validate_razorpay_credentials
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
def validate_razorpay_credentials(doc=None, method=None, razorpay_settings=None):
if not razorpay_settings:
razorpay_settings = get_razorpay_settings()
try:
get_request(url="https://api.razorpay.com/v1/payments", auth=frappe._dict({
"api_key": razorpay_settings.api_key,
"api_secret": razorpay_settings.api_secret
}))
except AuthenticationError, e:
frappe.throw(_(e.message))
示例15: create_payment_gateway_account
# 需要导入模块: import frappe [as 别名]
# 或者: from frappe import throw [as 别名]
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": _("Razorpay"), "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": "Razorpay", "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": _("Razorpay")})
if not bank_account:
frappe.throw(_("Payment Gateway Account not created, please create one manually."))
# if payment gateway account exists, return
if frappe.db.exists("Payment Gateway Account",
{"payment_gateway": "Razorpay", "currency": bank_account.account_currency}):
return
try:
frappe.get_doc({
"doctype": "Payment Gateway Account",
"is_default": 1,
"payment_gateway": "Razorpay",
"payment_account": bank_account.name,
"currency": bank_account.account_currency
}).insert(ignore_permissions=True)
except frappe.DuplicateEntryError:
# already exists, due to a reinstall?
pass