当前位置: 首页>>代码示例>>Python>>正文


Python DocList.submit方法代码示例

本文整理汇总了Python中webnotes.model.doclist.DocList.submit方法的典型用法代码示例。如果您正苦于以下问题:Python DocList.submit方法的具体用法?Python DocList.submit怎么用?Python DocList.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webnotes.model.doclist.DocList的用法示例。


在下文中一共展示了DocList.submit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_vouchers

# 需要导入模块: from webnotes.model.doclist import DocList [as 别名]
# 或者: from webnotes.model.doclist.DocList import submit [as 别名]
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 = []
开发者ID:trycatcher,项目名称:erpnext,代码行数:102,代码来源:voucher_import_tool.py


注:本文中的webnotes.model.doclist.DocList.submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。