本文整理汇总了Python中webnotes.bean函数的典型用法代码示例。如果您正苦于以下问题:Python bean函数的具体用法?Python bean怎么用?Python bean使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bean函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_custom_field_for_workflow_state
def create_custom_field_for_workflow_state(self):
webnotes.clear_cache(doctype=self.doc.document_type)
doctypeobj = webnotes.get_doctype(self.doc.document_type)
if not len(doctypeobj.get({"doctype": "DocField", "fieldname": self.doc.workflow_state_field})):
# create custom field
webnotes.bean(
[
{
"doctype": "Custom Field",
"dt": self.doc.document_type,
"__islocal": 1,
"fieldname": self.doc.workflow_state_field,
"label": self.doc.workflow_state_field.replace("_", " ").title(),
"hidden": 1,
"fieldtype": "Link",
"options": "Workflow State",
# "insert_after": doctypeobj.get({"doctype":"DocField"})[-1].fieldname
}
]
).save()
webnotes.msgprint(
"Created Custom Field '%s' in '%s'" % (self.doc.workflow_state_field, self.doc.document_type)
)
示例2: _get_cart_quotation
def _get_cart_quotation(party=None):
if not party:
party = get_lead_or_customer()
quotation = webnotes.conn.get_value("Quotation",
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0})
if quotation:
qbean = webnotes.bean("Quotation", quotation)
else:
qbean = webnotes.bean({
"doctype": "Quotation",
"naming_series": webnotes.defaults.get_user_default("shopping_cart_quotation_series") or "QTN-CART-",
"quotation_to": party.doctype,
"company": webnotes.defaults.get_user_default("company"),
"order_type": "Shopping Cart",
"status": "Draft",
"docstatus": 0,
"__islocal": 1,
(party.doctype.lower()): party.name
})
if party.doctype == "Customer":
qbean.doc.contact_person = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user,
"customer": party.name})
qbean.run_method("set_contact_fields")
qbean.run_method("onload_post_render")
apply_cart_settings(party, qbean)
return qbean
示例3: add_support_communication
def add_support_communication(subject, content, sender, docname=None, mail=None):
if docname:
ticket = webnotes.bean("Support Ticket", docname)
ticket.doc.status = 'Open'
ticket.ignore_permissions = True
ticket.doc.save()
else:
ticket = webnotes.bean([decode_dict({
"doctype":"Support Ticket",
"description": content,
"subject": subject,
"raised_by": sender,
"content_type": mail.content_type if mail else None,
"status": "Open",
})])
ticket.ignore_permissions = True
ticket.insert()
make(content=content, sender=sender, subject = subject,
doctype="Support Ticket", name=ticket.doc.name,
date=mail.date if mail else today(), sent_or_received="Received")
if mail:
mail.save_attachments_in_doc(ticket.doc)
return ticket
示例4: test_monthly_budget_on_cancellation
def test_monthly_budget_on_cancellation(self):
from accounts.utils import BudgetError
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Stop")
self.clear_account_balance()
jv = webnotes.bean(copy=test_records[0])
jv.doclist[1].account = "_Test Account Cost for Goods Sold - _TC"
jv.doclist[1].cost_center = "_Test Cost Center - _TC"
jv.doclist[1].credit = 30000.0
jv.doclist[2].debit = 30000.0
jv.submit()
self.assertTrue(webnotes.conn.get_value("GL Entry",
{"voucher_type": "Journal Voucher", "voucher_no": jv.doc.name}))
jv1 = webnotes.bean(copy=test_records[0])
jv1.doclist[2].account = "_Test Account Cost for Goods Sold - _TC"
jv1.doclist[2].cost_center = "_Test Cost Center - _TC"
jv1.doclist[2].debit = 40000.0
jv1.doclist[1].credit = 40000.0
jv1.submit()
self.assertTrue(webnotes.conn.get_value("GL Entry",
{"voucher_type": "Journal Voucher", "voucher_no": jv1.doc.name}))
self.assertRaises(BudgetError, jv.cancel)
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Ignore")
示例5: test_material_transfer_gl_entry
def test_material_transfer_gl_entry(self):
self._clear_stock()
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
mr = webnotes.bean(copy=test_records[0])
mr.insert()
mr.submit()
mtn = webnotes.bean(copy=test_records[2])
mtn.insert()
mtn.submit()
self.check_stock_ledger_entries("Stock Entry", mtn.doc.name,
[["_Test Item", "_Test Warehouse", -45.0], ["_Test Item", "_Test Warehouse 1", 45.0]])
# no gl entry
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
where voucher_type = 'Stock Entry' and voucher_no=%s""", mtn.doc.name)
self.assertFalse(gl_entries)
mtn.cancel()
self.check_stock_ledger_entries("Stock Entry", mtn.doc.name,
sorted([["_Test Item", "_Test Warehouse", 45.0],
["_Test Item", "_Test Warehouse 1", -45.0],
["_Test Item", "_Test Warehouse", -45.0],
["_Test Item", "_Test Warehouse 1", 45.0]]))
# no gl entry
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
where voucher_type = 'Stock Entry' and voucher_no=%s""", mtn.doc.name)
self.assertFalse(gl_entries)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.conn.set_default("company", self.old_default_company)
示例6: process_message
def process_message(self, mail):
if mail.from_email == self.email_settings.fields.get('support_email'):
return
thread_id = mail.get_thread_id()
ticket = None
new_ticket = False
if thread_id and webnotes.conn.exists("Support Ticket", thread_id):
ticket = webnotes.bean("Support Ticket", thread_id)
ticket.doc.status = 'Open'
ticket.doc.save()
else:
ticket = webnotes.bean([{
"doctype":"Support Ticket",
"description": mail.content,
"subject": mail.mail["Subject"],
"raised_by": mail.from_email,
"content_type": mail.content_type,
"status": "Open"
}])
ticket.insert()
new_ticket = True
mail.save_attachments_in_doc(ticket.doc)
make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject,
doctype="Support Ticket", name=ticket.doc.name,
lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date)
if new_ticket and cint(self.email_settings.send_autoreply) and \
"mailer-daemon" not in mail.from_email.lower():
self.send_auto_reply(ticket.doc)
示例7: test_incorrect_mapping_of_stock_entry
def test_incorrect_mapping_of_stock_entry(self):
# submit material request of type Purchase
mr = webnotes.bean(copy=test_records[0])
mr.doc.material_request_type = "Transfer"
mr.insert()
mr.submit()
# map a stock entry
se_doclist = webnotes.map_doclist([["Material Request", "Stock Entry"],
["Material Request Item", "Stock Entry Detail"]], mr.doc.name)
se_doclist[0].fields.update({
"posting_date": "2013-03-01",
"posting_time": "00:00"
})
se_doclist[1].fields.update({
"qty": 60.0,
"transfer_qty": 60.0,
"s_warehouse": "_Test Warehouse",
"t_warehouse": "_Test Warehouse 1",
"incoming_rate": 1.0
})
se_doclist[2].fields.update({
"qty": 3.0,
"transfer_qty": 3.0,
"s_warehouse": "_Test Warehouse 1",
"incoming_rate": 1.0
})
# check for stopped status of Material Request
se = webnotes.bean(copy=se_doclist)
self.assertRaises(webnotes.MappingMismatchError, se.insert)
示例8: import_doc
def import_doc(d, doctype, overwrite, row_idx, submit=False, ignore_links=False):
"""import main (non child) document"""
if d.get("name") and webnotes.conn.exists(doctype, d['name']):
if overwrite:
bean = webnotes.bean(doctype, d['name'])
bean.ignore_links = ignore_links
bean.doc.fields.update(d)
if d.get("docstatus") == 1:
bean.update_after_submit()
else:
bean.save()
return 'Updated row (#%d) %s' % (row_idx + 1, getlink(doctype, d['name']))
else:
return 'Ignored row (#%d) %s (exists)' % (row_idx + 1,
getlink(doctype, d['name']))
else:
bean = webnotes.bean([d])
bean.ignore_links = ignore_links
bean.insert()
if submit:
bean.submit()
return 'Inserted row (#%d) %s' % (row_idx + 1, getlink(doctype,
bean.doc.fields['name']))
示例9: update_for_doc
def update_for_doc(doctype, doc):
for filedata in doc.file_list.split("\n"):
if not filedata:
continue
filedata = filedata.split(",")
if len(filedata)==2:
filename, fileid = filedata[0], filedata[1]
else:
continue
exists = True
if not (filename.startswith("http://") or filename.startswith("https://")):
if not os.path.exists(webnotes.utils.get_path("public", "files", filename)):
exists = False
if exists:
if webnotes.conn.exists("File Data", fileid):
try:
fd = webnotes.bean("File Data", fileid)
if not (fd.doc.attached_to_doctype and fd.doc.attached_to_name):
fd.doc.attached_to_doctype = doctype
fd.doc.attached_to_name = doc.name
fd.save()
else:
fd = webnotes.bean("File Data", copy=fd.doclist)
fd.doc.attached_to_doctype = doctype
fd.doc.attached_to_name = doc.name
fd.doc.name = None
fd.insert()
except webnotes.DuplicateEntryError:
pass
else:
webnotes.conn.sql("""delete from `tabFile Data` where name=%s""",
fileid)
示例10: execute
def execute():
webnotes.reload_doc("selling", "doctype", "shopping_cart_price_list")
webnotes.reload_doc("stock", "doctype", "item_price")
for t in [
("Supplier Quotation", "price_list_name", "buying_price_list"),
("Purchase Order", "price_list_name", "buying_price_list"),
("Purchase Invoice", "price_list_name", "buying_price_list"),
("Purchase Receipt", "price_list_name", "buying_price_list"),
("Quotation", "price_list_name", "selling_price_list"),
("Sales Order", "price_list_name", "selling_price_list"),
("Delivery Note", "price_list_name", "selling_price_list"),
("Sales Invoice", "price_list_name", "selling_price_list"),
("POS Setting", "price_list_name", "selling_price_list"),
("Shopping Cart Price List", "price_list", "selling_price_list"),
("Item Price", "price_list_name", "price_list"),
("BOM", "price_list", "buying_price_list"),
]:
table_columns = webnotes.conn.get_table_columns(t[0])
if t[2] in table_columns and t[1] in table_columns:
# already reloaded, so copy into new column and drop old column
webnotes.conn.sql("""update `tab%s` set `%s`=`%s`""" % (t[0], t[2], t[1]))
webnotes.conn.sql_ddl("""alter table `tab%s` drop column `%s`""" % (t[0], t[1]))
elif t[1] in table_columns:
webnotes.conn.sql_ddl("alter table `tab%s` change `%s` `%s` varchar(180)" % t)
webnotes.reload_doc(webnotes.conn.get_value("DocType", t[0], "module"), "DocType", t[0])
webnotes.conn.sql("""update tabSingles set field='selling_price_list'
where field='price_list_name' and doctype='Selling Settings'""")
webnotes.reload_doc("Selling", "DocType", "Selling Settings")
webnotes.bean("Selling Settings").save()
示例11: execute
def execute():
webnotes.reload_doc("utilities", "doctype", "note")
webnotes.reload_doc("utilities", "doctype", "note_user")
for question in webnotes.conn.sql("""select * from tabQuestion""", as_dict=True):
if question.question:
try:
name = question.question[:180]
if webnotes.conn.exists("Note", name):
webnotes.delete_doc("Note", name)
note = webnotes.bean({
"doctype":"Note",
"title": name,
"content": "<hr>".join([markdown2.markdown(c) for c in webnotes.conn.sql_list("""
select answer from tabAnswer where question=%s""", question.name)]),
"owner": question.owner,
"creation": question.creation,
"public": 1
}).insert()
except NameError:
pass
webnotes.delete_doc("DocType", "Question")
webnotes.delete_doc("DocType", "Answer")
webnotes.bean("Style Settings").save()
# update comment delete
webnotes.conn.sql("""update tabDocPerm \
set cancel=1 where parent='Comment' and role='System Manager'""")
示例12: get_warehouse_account
def get_warehouse_account(self):
for d in webnotes.conn.sql("select name from tabWarehouse"):
webnotes.bean("Warehouse", d[0]).save()
warehouse_account = dict(webnotes.conn.sql("""select master_name, name from tabAccount
where account_type = 'Warehouse' and ifnull(master_name, '') != ''"""))
return warehouse_account
示例13: execute
def execute():
webnotes.reload_doc("utilities", "doctype", "note")
webnotes.reload_doc("utilities", "doctype", "note_user")
for question in webnotes.conn.sql("""select * from tabQuestion""", as_dict=True):
if question.question:
try:
name = question.question[:180]
if webnotes.conn.exists("Note", name):
webnotes.delete_doc("Note", name)
similar_questions = webnotes.conn.sql_list("""select name from `tabQuestion`
where question like %s""", "%s%%" % name)
answers = [markdown2.markdown(c) for c in webnotes.conn.sql_list("""
select answer from tabAnswer where question in (%s)""" % \
", ".join(["%s"]*len(similar_questions)), similar_questions)]
webnotes.bean({
"doctype":"Note",
"title": name,
"content": "<hr>".join(answers),
"owner": question.owner,
"creation": question.creation,
"public": 1
}).insert()
except NameError:
pass
except Exception, e:
if e.args[0] != 1062:
raise
示例14: create_default_warehouses
def create_default_warehouses(self):
for whname in ("Stores", "Work In Progress", "Finished Goods"):
webnotes.bean({
"doctype":"Warehouse",
"warehouse_name": whname,
"company": self.doc.name
}).insert()
示例15: test_purchase_invoice_with_advance
def test_purchase_invoice_with_advance(self):
from accounts.doctype.journal_voucher.test_journal_voucher \
import test_records as jv_test_records
jv = webnotes.bean(copy=jv_test_records[1])
jv.insert()
jv.submit()
pi = webnotes.bean(copy=test_records[0])
pi.doclist.append({
"doctype": "Purchase Invoice Advance",
"parentfield": "advance_allocation_details",
"journal_voucher": jv.doc.name,
"jv_detail_no": jv.doclist[1].name,
"advance_amount": 400,
"allocated_amount": 300,
"remarks": jv.doc.remark
})
pi.run_method("calculate_taxes_and_totals")
pi.insert()
pi.submit()
pi.load_from_db()
self.assertTrue(webnotes.conn.sql("""select name from `tabJournal Voucher Detail`
where against_voucher=%s""", pi.doc.name))
self.assertTrue(webnotes.conn.sql("""select name from `tabJournal Voucher Detail`
where against_voucher=%s and debit=300""", pi.doc.name))
self.assertEqual(pi.doc.outstanding_amount, 1212.30)
pi.cancel()
self.assertTrue(not webnotes.conn.sql("""select name from `tabJournal Voucher Detail`
where against_voucher=%s""", pi.doc.name))