本文整理汇总了Python中webnotes._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_uom_is_integer
def validate_uom_is_integer(doclist, uom_field, qty_fields):
if isinstance(qty_fields, basestring):
qty_fields = [qty_fields]
integer_uoms = filter(
lambda uom: webnotes.conn.get_value("UOM", uom, "must_be_whole_number") or None,
doclist.get_distinct_values(uom_field),
)
if not integer_uoms:
return
for d in doclist:
if d.fields.get(uom_field) in integer_uoms:
for f in qty_fields:
if d.fields.get(f):
if cint(d.fields[f]) != d.fields[f]:
webnotes.msgprint(
_("For UOM")
+ " '"
+ d.fields[uom_field]
+ "': "
+ _("Quantity cannot be a fraction.")
+ " "
+ _("In Row")
+ ": "
+ str(d.idx),
raise_exception=UOMMustBeIntegerError,
)
示例2: run
def run(report_name, filters=None):
report = webnotes.doc("Report", report_name)
if filters and isinstance(filters, basestring):
filters = json.loads(filters)
if not webnotes.has_permission(report.ref_doctype, "report"):
webnotes.msgprint(_("Must have report permission to access this report."),
raise_exception=True)
if report.report_type=="Query Report":
if not report.query:
webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
if not report.query.lower().startswith("select"):
webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
result = [list(t) for t in webnotes.conn.sql(report.query, filters)]
columns = [c[0] for c in webnotes.conn.get_description()]
else:
method_name = scrub(webnotes.conn.get_value("DocType", report.ref_doctype, "module")) \
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
columns, result = webnotes.get_method(method_name)(filters or {})
result = get_filtered_data(report.ref_doctype, columns, result)
if cint(report.add_total_row) and result:
result = add_total_row(result, columns)
return {
"result": result,
"columns": columns
}
示例3: validate_max_discount
def validate_max_discount(self):
for d in self.doclist.get({"parentfield": self.fname}):
discount = flt(webnotes.conn.get_value("Item", d.item_code, "max_discount"))
if discount and flt(d.adj_rate) > discount:
webnotes.throw(_("You cannot give more than ") + cstr(discount) + "% " +
_("discount on Item Code") + ": " + cstr(d.item_code))
示例4: check_value
def check_value(self, ref_dt, ref_dn, ref_item_dn, val, item_code):
ref_val = webnotes.conn.get_value(ref_dt + " Item", ref_item_dn, "export_rate")
if flt(ref_val, 2) != flt(val, 2):
msgprint(
_("Rate is not matching with ") + ref_dt + ": " + ref_dn + _(" for item: ") + item_code,
raise_exception=True,
)
示例5: _get_message
def _get_message(url=False):
if url:
name = get_url_to_form(self.doc.doctype, self.doc.name)
else:
name = self.doc.name
return (_("Leave Application") + ": %s - %s") % (name, _(status))
示例6: place_order
def place_order():
quotation = _get_cart_quotation()
quotation.doc.company = webnotes.conn.get_value("Shopping Cart Settings", None, "company")
controller = quotation.make_controller()
for fieldname in ["customer_address", "shipping_address_name"]:
if not quotation.doc.fields.get(fieldname):
msgprint(_("Please select a") + " " + _(controller.meta.get_label(fieldname)), raise_exception=True)
quotation.ignore_permissions = True
quotation.submit()
if quotation.doc.lead:
# company used to create customer accounts
webnotes.defaults.set_user_default("company", quotation.doc.company)
from selling.doctype.quotation.quotation import _make_sales_order
sales_order = webnotes.bean(_make_sales_order(quotation.doc.name, ignore_permissions=True))
for item in sales_order.doclist.get({"parentfield": "sales_order_details"}):
item.reserved_warehouse = webnotes.conn.get_value("Item", item.item_code, "website_warehouse") or None
sales_order.ignore_permissions = True
sales_order.insert()
sales_order.submit()
webnotes._response.set_cookie("cart_count", "")
return sales_order.doc.name
示例7: run
def run(report_name):
report = webnotes.doc("Report", report_name)
if not webnotes.has_permission(report.ref_doctype, "report"):
webnotes.msgprint(_("Must have report permission to access this report."),
raise_exception=True)
if report.report_type=="Query Report":
if not report.query:
webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
if not report.query.lower().startswith("select"):
webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
result = [list(t) for t in webnotes.conn.sql(report.query)]
columns = [c[0] for c in webnotes.conn.get_description()]
else:
from webnotes.modules import scrub
method_name = scrub(webnotes.conn.get_value("DocType", report.ref_doctype, "module")) \
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
columns, result = webnotes.get_method(method_name)()
return {
"result": result,
"columns": columns
}
示例8: upload
def upload(select_doctype=None, rows=None):
from webnotes.utils.datautils import read_csv_content_from_uploaded_file
from webnotes.modules import scrub
from webnotes.model.rename_doc import rename_doc
if not select_doctype:
select_doctype = webnotes.form_dict.select_doctype
if not rows:
rows = read_csv_content_from_uploaded_file()
if not rows:
webnotes.msgprint(_("Please select a valid csv file with data."))
raise Exception
if len(rows) > 500:
webnotes.msgprint(_("Max 500 rows only."))
raise Exception
rename_log = []
for row in rows:
if len(row) > 2:
try:
if rename_doc(select_doctype, row[0], row[1]):
rename_log.append(_("Successful: ") + row[0] + " -> " + row[1])
webnotes.conn.commit()
else:
rename_log.append(_("Ignored: ") + row[0] + " -> " + row[1])
except Exception, e:
rename_log.append("<span style='color: RED'>" + \
_("Failed: ") + row[0] + " -> " + row[1] + "</span>")
rename_log.append("<span style='margin-left: 20px;'>" + repr(e) + "</span>")
示例9: update_last_purchase_rate
def update_last_purchase_rate(self, obj, is_submit):
"""updates last_purchase_rate in item table for each item"""
import webnotes.utils
this_purchase_date = webnotes.utils.getdate(obj.doc.fields.get('posting_date') or obj.doc.fields.get('transaction_date'))
for d in getlist(obj.doclist,obj.fname):
# get last purchase details
last_purchase_details = get_last_purchase_details(d.item_code, obj.doc.name)
# compare last purchase date and this transaction's date
last_purchase_rate = None
if last_purchase_details and \
(last_purchase_details.purchase_date > this_purchase_date):
last_purchase_rate = last_purchase_details['purchase_rate']
elif is_submit == 1:
# even if this transaction is the latest one, it should be submitted
# for it to be considered for latest purchase rate
if flt(d.conversion_factor):
last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)
else:
msgprint(_("Row ") + cstr(d.idx) + ": " +
_("UOM Conversion Factor is mandatory"), raise_exception=1)
# update last purchsae rate
if last_purchase_rate:
webnotes.conn.sql("update `tabItem` set last_purchase_rate = %s where name = %s",
(flt(last_purchase_rate),d.item_code))
示例10: sign_up
def sign_up(email, full_name):
profile = webnotes.conn.get("Profile", {"email": email})
if profile:
if profile.disabled:
return _("Registered but disabled.")
else:
return _("Already Registered")
else:
if (
webnotes.conn.sql(
"""select count(*) from tabProfile where
TIMEDIFF(%s, modified) > '1:00:00' """,
now(),
)[0][0]
> 200
):
raise Exception, "Too Many New Profiles"
from webnotes.utils import random_string
profile = webnotes.bean(
{
"doctype": "Profile",
"email": email,
"first_name": full_name,
"enabled": 1,
"new_password": random_string(10),
"user_type": "Website User",
}
)
profile.ignore_permissions = True
profile.insert()
return _("Registration Details Emailed.")
示例11: validate_filters
def validate_filters(filters, account_details):
if account_details and account_details.group_or_ledger == "Ledger" \
and filters.get("group_by") == "Group by Account":
webnotes.throw(_("Can not filter based on Account, if grouped by Account"))
if filters.get("voucher_no") and filters.get("group_by") == "Group by Voucher":
webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
示例12: validate_data
def validate_data(self):
if not self.doc.reconciliation_json:
return
data = json.loads(self.doc.reconciliation_json)
# strip out extra columns (if any)
data = [row[:4] for row in data]
if self.head_row not in data:
msgprint(_("""Wrong Template: Unable to find head row."""),
raise_exception=1)
# remove the help part and save the json
if data.index(self.head_row) != 0:
data = data[data.index(self.head_row):]
self.doc.reconciliation_json = json.dumps(data)
def _get_msg(row_num, msg):
return _("Row # ") + ("%d: " % (row_num+2)) + _(msg)
self.validation_messages = []
item_warehouse_combinations = []
# validate no of rows
rows = data[data.index(self.head_row)+1:]
if len(rows) > 100:
msgprint(_("""Sorry! We can only allow upto 100 rows for Stock Reconciliation."""),
raise_exception=True)
for row_num, row in enumerate(rows):
# find duplicates
if [row[0], row[1]] in item_warehouse_combinations:
self.validation_messages.append(_get_msg(row_num, "Duplicate entry"))
else:
item_warehouse_combinations.append([row[0], row[1]])
self.validate_item(row[0], row_num)
# note: warehouse will be validated through link validation
# if both not specified
if row[2] == "" :
self.validation_messages.append(_get_msg(row_num,
"Please specify Quantity "))
# do not allow negative quantity
if flt(row[2]) < 0:
self.validation_messages.append(_get_msg(row_num,
"Negative Quantity is not allowed"))
# do not allow negative valuation
#if flt(row[3]) < 0:
# self.validation_messages.append(_get_msg(row_num,
# "Negative Valuation Rate is not allowed"))
# throw all validation messages
if self.validation_messages:
for msg in self.validation_messages:
msgprint(msg)
raise webnotes.ValidationError
示例13: validate_warehouse
def validate_warehouse(self):
if not self.doc.fields.get("__islocal"):
item_code, warehouse = webnotes.conn.get_value("Serial No", self.doc.name, ["item_code", "warehouse"])
if item_code != self.doc.item_code:
webnotes.throw(_("Item Code cannot be changed for Serial No."), SerialNoCannotCannotChangeError)
if not self.via_stock_ledger and warehouse != self.doc.warehouse:
webnotes.throw(_("Warehouse cannot be changed for Serial No."), SerialNoCannotCannotChangeError)
示例14: validate
def validate(self):
if self.doc.buying_or_selling not in ["Buying", "Selling"]:
msgprint(_(self.meta.get_label("buying_or_selling")) + " " + _("must be one of") + " " +
comma_or(["Buying", "Selling"]), raise_exception=True)
# at least one territory
self.validate_table_has_rows("valid_for_territories")
示例15: update_completed_qty
def update_completed_qty(controller, caller_method):
if controller.doc.doctype == "Stock Entry":
material_request_map = {}
for d in controller.doclist.get({"parentfield": "mtn_details"}):
if d.material_request:
if d.material_request not in material_request_map:
material_request_map[d.material_request] = []
material_request_map[d.material_request].append(d.material_request_item)
for mr_name, mr_items in material_request_map.items():
mr_obj = webnotes.get_obj("Material Request", mr_name, with_children=1)
mr_doctype = webnotes.get_doctype("Material Request")
if mr_obj.doc.status in ["Stopped", "Cancelled"]:
msgprint(
_("Material Request")
+ ": %s, " % mr_obj.doc.name
+ _(mr_doctype.get_label("status"))
+ " = %s. " % _(mr_obj.doc.status)
+ _("Cannot continue."),
raise_exception=webnotes.InvalidStatusError,
)
_update_requested_qty(controller, mr_obj, mr_items)
# update ordered percentage and qty
mr_obj.update_completed_qty(mr_items)