本文整理匯總了Python中webnotes.model.doclist.DocList類的典型用法代碼示例。如果您正苦於以下問題:Python DocList類的具體用法?Python DocList怎麽用?Python DocList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DocList類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getchildren
def getchildren(name, childtype, field='', parenttype='', from_doctype=0, prefix='tab'):
import webnotes
from webnotes.model.doclist import DocList
condition = ""
values = []
if field:
condition += ' and parentfield=%s '
values.append(field)
if parenttype:
condition += ' and parenttype=%s '
values.append(parenttype)
dataset = webnotes.conn.sql("""select * from `%s%s` where parent=%s %s order by idx""" \
% (prefix, childtype, "%s", condition), tuple([name]+values))
desc = webnotes.conn.get_description()
l = DocList()
for i in dataset:
d = Document()
d.doctype = childtype
d._load_values(i, desc)
l.append(d)
return l
示例2: savedocs
def savedocs():
"""save / submit / cancel / update doclist"""
try:
from webnotes.model.doclist import DocList
form = webnotes.form_dict
doclist = DocList()
doclist.from_compressed(form.get('docs'), form.get('docname'))
# action
action = form.get('action')
if action=='Update': action='update_after_submit'
getattr(doclist, action.lower())()
# update recent documents
webnotes.user.update_recent(doclist.doc.doctype, doclist.doc.name)
# send updated docs
webnotes.response['saved'] = '1'
webnotes.response['main_doc_name'] = doclist.doc.name
webnotes.response['docname'] = doclist.doc.name
webnotes.response['docs'] = [doclist.doc] + doclist.children
except Exception, e:
webnotes.msgprint('Did not save')
webnotes.errprint(webnotes.utils.getTraceback())
raise e
示例3: testFailAssert
def testFailAssert(self):
if docnotok:
with self.assertRaises(Exception) as context:
d = DocList()
d.doc = docnotok[0]
d.children = None
d.doc.fields['__islocal']=1
d.save(1)
示例4: testInsert
def testInsert(self):
d = DocList()
count_before = flt(sql("select count(*) from tab"+_doctype)[0][0])
if docok:
for i in docok:
d.doc = i
d.children = None
d.doc.fields['__islocal']=1
d.save(1)
count_after = flt(sql("select count(*) from tab"+_doctype)[0][0])
self.assertTrue(count_before+len(docok)==count_after)
示例5: cancel_packing_slips
def cancel_packing_slips(self):
"""
Cancel submitted packing slips related to this delivery note
"""
res = webnotes.conn.sql("""\
SELECT name, count(*) FROM `tabPacking Slip`
WHERE delivery_note = %s AND docstatus = 1
""", self.doc.name)
if res and res[0][1]>0:
from webnotes.model.doclist import DocList
for r in res:
ps = DocList(dt='Packing Slip', dn=r[0])
ps.cancel()
webnotes.msgprint("%s Packing Slip(s) Cancelled" % res[0][1])
示例6: sort_fields
def sort_fields(doclist):
"""sort on basis of previous_field"""
from webnotes.model.doclist import DocList
newlist = DocList([])
pending = filter(lambda d: d.doctype=='DocField', doclist)
maxloops = 20
while (pending and maxloops>0):
maxloops -= 1
for d in pending[:]:
if d.previous_field:
# field already added
for n in newlist:
if n.fieldname==d.previous_field:
newlist.insert(newlist.index(n)+1, d)
pending.remove(d)
break
else:
newlist.append(d)
pending.remove(d)
# recurring at end
if pending:
newlist += pending
# renum
idx = 1
for d in newlist:
d.idx = idx
idx += 1
doclist.get({"doctype":["!=", "DocField"]}).extend(newlist)
示例7: runserverobj
def runserverobj():
"""
Run server objects
"""
import webnotes.model.code
from webnotes.model.doclist import DocList
from webnotes.utils import cint
form = webnotes.form
doclist = None
method = form.getvalue('method')
arg = form.getvalue('arg')
dt = form.getvalue('doctype')
dn = form.getvalue('docname')
if dt: # not called from a doctype (from a page)
if not dn: dn = dt # single
so = webnotes.model.code.get_obj(dt, dn)
else:
doclist = DocList()
doclist.from_compressed(form.getvalue('docs'), dn)
so = doclist.make_obj()
check_guest_access(so.doc)
if so:
r = webnotes.model.code.run_server_obj(so, method, arg)
if r:
#build output as csv
if cint(webnotes.form.getvalue('as_csv')):
make_csv_output(r, so.doc.doctype)
else:
webnotes.response['message'] = r
webnotes.response['docs'] =[so.doc] + so.doclist
示例8: getchildren
def getchildren(name, childtype, field='', parenttype='', from_doctype=0, prefix='tab'):
import webnotes
from webnotes.model.doclist import DocList
tmp = ''
if field:
tmp = ' and parentfield="%s" ' % field
if parenttype:
tmp = ' and parenttype="%s" ' % parenttype
dataset = webnotes.conn.sql("select * from `%s%s` where parent='%s' %s order by idx" \
% (prefix, childtype, name, tmp))
desc = webnotes.conn.get_description()
l = DocList()
for i in dataset:
d = Document()
d.doctype = childtype
d._load_values(i, desc)
l.append(d)
return l
示例9: sort_fields
def sort_fields(doclist):
"""sort on basis of previous_field"""
from webnotes.model.doclist import DocList
newlist = DocList([])
pending = doclist.get({"doctype":"DocField"})
if doclist[0].get("_idx"):
for fieldname in json.loads(doclist[0].get("_idx")):
d = doclist.get({"fieldname": fieldname})
if d:
newlist.append(d[0])
pending.remove(d[0])
else:
maxloops = 20
while (pending and maxloops>0):
maxloops -= 1
for d in pending[:]:
if d.previous_field:
# field already added
for n in newlist:
if n.fieldname==d.previous_field:
newlist.insert(newlist.index(n)+1, d)
pending.remove(d)
break
else:
newlist.append(d)
pending.remove(d)
# recurring at end
if pending:
newlist += pending
# renum
idx = 1
for d in newlist:
d.idx = idx
idx += 1
doclist.get({"doctype":["!=", "DocField"]}).extend(newlist)
示例10: import_vouchers
def import_vouchers(common_values, data, start_idx, import_type):
from webnotes.model.doc import Document
from webnotes.model.doclist import DocList
from webnotes.model.code import get_obj
from accounts.utils import get_fiscal_year
from webnotes.utils.dateutils import parse_date
messages = []
def get_account_details(account):
acc_details = webnotes.conn.sql("""select is_pl_account,
master_name from tabAccount where name=%s""", account, as_dict=1)
if not acc_details:
webnotes.msgprint("%s is not an Account" % account, raise_exception=1)
return acc_details[0]
def apply_cost_center_and_against_invoice(detail, d):
account = get_account_details(detail.account)
if account.is_pl_account=="Yes":
detail.cost_center = d.cost_center
if account.master_name:
map_fields(["against_sales_invoice:against_invoice",
"against_purhase_invoice:against_voucher",
"against_journal_voucher:against_jv"], d, detail.fields)
webnotes.conn.commit()
for i in xrange(len(data)):
d = data[i][0]
jv = webnotes.DictObj()
try:
d.posting_date = parse_date(d.posting_date)
d.due_date = d.due_date and parse_date(d.due_date) or None
if d.ref_number:
if not d.ref_date:
raise webnotes.ValidationError, \
"""Ref Date is Mandatory if Ref Number is specified"""
d.ref_date = parse_date(d.ref_date)
d.company = common_values.company
jv = Document("Journal Voucher")
map_fields(["voucher_type", "posting_date", "naming_series", "remarks:user_remark",
"ref_number:cheque_no", "ref_date:cheque_date", "is_opening",
"amount:total_debit", "amount:total_credit", "due_date", "company"], d, jv.fields)
jv.fiscal_year = get_fiscal_year(jv.posting_date)[0]
details = []
if import_type == "Voucher Import: Two Accounts":
detail1 = Document("Journal Voucher Detail")
detail1.parent = True
detail1.parentfield = "entries"
map_fields(["debit_account:account","amount:debit"], d, detail1.fields)
apply_cost_center_and_against_invoice(detail1, d)
detail2 = Document("Journal Voucher Detail")
detail2.parent = True
detail2.parentfield = "entries"
map_fields(["credit_account:account","amount:credit"], d, detail2.fields)
apply_cost_center_and_against_invoice(detail2, d)
details = [detail1, detail2]
elif import_type == "Voucher Import: Multiple Accounts":
accounts = data[i][1]
for acc in accounts:
detail = Document("Journal Voucher Detail")
detail.parent = True
detail.parentfield = "entries"
detail.account = acc
detail.debit = flt(accounts[acc]) > 0 and flt(accounts[acc]) or 0
detail.credit = flt(accounts[acc]) < 0 and -1*flt(accounts[acc]) or 0
apply_cost_center_and_against_invoice(detail, d)
details.append(detail)
if not details:
messages.append("""<p style='color: red'>No accounts found.
If you entered accounts correctly, please check template once</p>""")
return
webnotes.conn.begin()
doclist = DocList([jv]+details)
doclist.submit()
webnotes.conn.commit()
messages.append("""<p style='color: green'>[row #%s]
<a href=\"#Form/Journal Voucher/%s\">%s</a> imported</p>""" \
% ((start_idx + 1) + i, jv.name, jv.name))
except Exception, e:
webnotes.conn.rollback()
err_msg = webnotes.message_log and webnotes.message_log[0] or unicode(e)
messages.append("<p style='color: red'>[row #%s] %s failed: %s</p>" \
% ((start_idx + 1) + i, jv.name or "", err_msg or "No message"))
webnotes.errprint(webnotes.getTraceback())
webnotes.message_log = []