本文整理汇总了Python中webnotes.model.doc.Document类的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_warranty_amc_history
def update_warranty_amc_history(self, submit=1):
if self.doc.order_type in ["AMC", "OTS (One Time Service)"]:
sr_list = []
if submit:
for d in getlist(self.doclist, "service_order_details"):
sr = Document("Serial No", d.serial_no)
child = addchild(sr, "warranty_amc_history", "Warranty AMC History", 0)
child.from_date = d.start_date
child.to_date = d.end_date
child.status = (self.doc.order_type == "AMC") and "Under AMC" or "OTS (One Time Service)"
child.against_doctype = self.doc.doctype
child.against_docname = self.doc.name
child.customer = self.doc.customer
child.territory = self.doc.territory
child.save()
sr.warranty_amc_status = (self.doc.order_type == "AMC") and "Under AMC" or "OTS (One Time Service)"
sr.amc_expiry_date = d.end_date
sr.save()
sr_list.append(d.serial_no)
else:
sql(
"delete from `tabWarranty AMC History` where against_doctype = %s and against_docname = %s",
(self.doc.doctype, self.doc.name),
)
for d in getlist(self.doclist, "service_order_details"):
sql("update `tabSerial No` set amc_expiry_date = '' where name = '%s'" % (d.serial_no))
sr_list.append(d.serial_no)
self.update_serial_no_warranty_amc_status(serial_no_list=sr_list)
示例2: create_production_order
def create_production_order(self,company, fy, pp_detail = '', pro_detail = ''):
pro_lbl = {'production_item': 0, 'description': 1, 'qty' : 2, 'stock_uom' : 3, 'bom_no': 4, 'consider_sa_items': 5}
default_values = { 'transaction_date' : now(),
'origin' : pp_detail and 'MRP' or 'Direct',
'wip_warehouse' : 'MB1-Stores',
'status' : 'Draft',
'company' : company,
'fiscal_year' : fy }
pro_list, count = pp_detail and pp_detail or pro_detail, 0
while (count < len(pro_list)):
pro_doc = Document('Production Order')
for key in pro_lbl.keys():
pro_doc.fields[key] = pro_list[count][pro_lbl[key]]
for key in default_values:
pro_doc.fields[key] = default_values[key]
pro_doc.save(new = 1)
pro_list[count] = pro_doc.name
# This was for adding raw materials in pro detail and get sa items
#sa_list = get_obj('Porduction Order', pro_doc.name, with_children = 1).get_purchase_item( get_sa_items = 1, add_child= 1)
#for sa_item in sa_list:
# pro_list.append(sa_item)
count = count + 1
return pro_list
示例3: save_entries
def save_entries(gl_map, cancel, adv_adj, update_outstanding):
total_debit = total_credit = 0.0
def _swap(gle):
gle.debit, gle.credit = abs(flt(gle.credit)), abs(flt(gle.debit))
for entry in gl_map:
gle = Document('GL Entry', fielddata=entry)
# toggle debit, credit if negative entry
if flt(gle.debit) < 0 or flt(gle.credit) < 0:
_swap(gle)
# toggled debit/credit in two separate condition because
# both should be executed at the
# time of cancellation when there is negative amount (tax discount)
if cancel:
_swap(gle)
gle_obj = webnotes.get_obj(doc=gle)
# validate except on_cancel
if not cancel:
gle_obj.validate()
# save
gle.save(1)
gle_obj.on_update(adv_adj, cancel, update_outstanding)
# update total debit / credit
total_debit += flt(gle.debit)
total_credit += flt(gle.credit)
# print gle.account, gle.debit, gle.credit, total_debit, total_credit
if not cancel:
validate_total_debit_credit(total_debit, total_credit)
示例4: validate_incoming
def validate_incoming(self):
"""
Checks support ticket email settings
"""
if self.doc.sync_support_mails and self.doc.support_host:
from webnotes.utils.email_lib.receive import POP3Mailbox
from webnotes.model.doc import Document
import _socket, poplib
inc_email = Document('Incoming Email Settings')
inc_email.host = self.doc.support_host.encode('utf-8')
inc_email.use_ssl = self.doc.support_use_ssl
try:
inc_email.username = self.doc.support_username.encode('utf-8')
inc_email.password = self.doc.support_password.encode('utf-8')
except AttributeError, e:
webnotes.msgprint('User Name or Support Password missing. Please enter and try again.')
webnotes.msgprint(e)
pop_mb = POP3Mailbox(inc_email)
try:
pop_mb.connect()
except _socket.error, e:
# Invalid mail server -- due to refusing connection
webnotes.msgprint('Invalid POP3 Mail Server. Please rectify and try again.')
webnotes.msgprint(e)
示例5: 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
示例6: addchild
def addchild(self, fieldname, childtype = '', doclist=None):
"""
Returns a child record of the give `childtype`.
* if local is set, it does not save the record
* if doclist is passed, it append the record to the doclist
"""
from webnotes.model.doc import Document
d = Document()
d.parent = self.name
d.parenttype = self.doctype
d.parentfield = fieldname
d.doctype = childtype
d.docstatus = 0;
d.name = ''
d.owner = webnotes.session['user']
d.fields['__islocal'] = 1 # for Client to identify unsaved doc
if doclist != None:
doclist.append(d)
if doclist:
d.idx = max([(d.idx or 0) for d in doclist if d.doctype==childtype]) + 1
return d
示例7: load_data
def load_data():
test_purchase_receipt.load_data()
webnotes.insert({"doctype": "Account", "account_name": "Cost for Goods Sold",
"parent_account": "Expenses - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "Excise Duty",
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "Education Cess",
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess",
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "CST",
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "Discount",
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
from webnotes.model.doc import Document
item = Document("Item", "Home Desktop 100")
# excise duty
item_tax = item.addchild("item_tax", "Item Tax")
item_tax.tax_type = "Excise Duty - %s" % abbr
item_tax.tax_rate = 10
item_tax.save()
示例8: save_file
def save_file(fname, content, module=None):
from webnotes.model.doc import Document
from filecmp import cmp
check_max_file_size(content)
new_fname = write_file(content)
# some browsers return the full path
if '\\' in fname:
fname = fname.split('\\')[-1]
if '/' in fname:
fname = fname.split('/')[-1]
# we use - for versions, so remove them from the name!
fname = fname.replace('-', '')
fpath = os.path.join(get_files_path(), fname)
if os.path.exists(fpath) and cmp(fpath, new_fname):
# remove new file, already exists!
os.remove(new_fname)
return fname
else:
# generate the ID (?)
f = Document('File Data')
f.file_name = fname
f.save(1)
# rename new file
os.rename(new_fname, os.path.join(get_files_path(), f.name))
return f.name
示例9: make_single_entry
def make_single_entry(self,parent,d,le_map,cancel, merge_entries):
if self.get_val(le_map['account'], d, parent) and \
(self.get_val(le_map['debit'], d, parent) \
or self.get_val(le_map['credit'], d, parent)):
flist = ['account', 'cost_center', 'against', 'debit', 'credit', 'remarks',
'voucher_type', 'voucher_no', 'posting_date', 'fiscal_year', 'against_voucher',
'against_voucher_type', 'company', 'is_opening', 'aging_date']
# Check budget before gl entry
#check budget only if account is expense account
is_expense_acct = webnotes.conn.sql("""select name from tabAccount
where is_pl_account='Yes' and debit_or_credit='Debit'
and name=%s""",self.get_val(le_map['account'], d, parent))
if is_expense_acct and self.get_val(le_map['cost_center'], d, parent):
get_obj('Budget Control').check_budget([self.get_val(le_map[k], d, parent)
for k in flist if k in ['account', 'cost_center', 'debit',
'credit', 'posting_date', 'fiscal_year', 'company']],cancel)
# Create new GL entry object and map values
le = Document('GL Entry')
for k in flist:
le.fields[k] = self.get_val(le_map[k], d, parent)
# if there is already an entry in this account then just add it to that entry
same_head = self.check_if_in_list(le)
if same_head and merge_entries:
same_head = same_head[0]
same_head.debit = flt(same_head.debit) + flt(le.debit)
same_head.credit = flt(same_head.credit) + flt(le.credit)
else:
self.entries.append(le)
示例10: import_docs
def import_docs(docs = []):
from webnotes.model.doc import Document
import webnotes.model.code
doc_list = {}
created_docs = []
already_exists = []
out, tmp ="", ""
for d in docs:
cur_doc = Document(fielddata = d)
if not cur_doc.parent in already_exists: # parent should not exist
try:
cur_doc.save(1)
out += "Created: " + cur_doc.name + "\n"
created_docs.append(cur_doc)
# make in groups
if cur_doc.parent:
if not doc_list.has_key(cur_doc.parent):
doc_list[cur_doc.parent] = []
doc_list[cur_doc.parent].append(cur_doc)
except Exception, e:
out += "Creation Warning/Error: " + cur_doc.name + " :"+ str(e) + "\n"
already_exists.append(cur_doc.name)
示例11: create_child
def create_child(self):
from datetime import datetime
# date_a=cstr(datetime.combine(datetime.strptime(self.doc.encounter_date,'%Y-%m-%d').date(),datetime.strptime(self.doc.start_time,'%H:%M').time()))
# date_b=cstr(datetime.combine(datetime.strptime(self.doc.encounter_date,'%Y-%m-%d').date(),datetime.strptime(self.doc.end_time,'%H:%M').time()))
if self.doc.appointment_slot:
webnotes.errprint([self.doc.start_time])
check_confirmed=webnotes.conn.sql("select true from `tabSlot Child` where slot='"+self.doc.appointment_slot+"' and modality='"+self.doc.encounter+"' and study='"+self.doc.study+"' and date_format(start_time,'%Y-%m-%d %H:%M')=date_format('"+date_a+"','%Y-%m-%d %H:%M') and date_format(end_time,'%Y-%m-%d %H:%M')=date_format('"+date_b+"','%Y-%m-%d %H:%M') and status='Confirm'",debug=1)
webnotes.errprint(check_confirmed)
if not check_confirmed:
check_status=webnotes.conn.sql("select case when count(*)<2 then true else false end from `tabSlot Child` where slot='"+self.doc.appointment_slot+"' and modality='"+self.doc.encounter+"' and study='"+self.doc.study+"' and date_format(start_time,'%Y-%m-%d %H:%M')=date_format('"+date_a+"','%Y-%m-%d %H:%M') and date_format(end_time,'%Y-%m-%d %H:%M')=date_format('"+date_b+"','%Y-%m-%d %H:%M') and status<>'Cancel'",as_list=1)
webnotes.errprint(check_status[0][0])
if check_status[0][0]==1:
d=Document("Slot Child")
d.slot=self.doc.appointment_slot
d.modality=self.doc.encounter
d.study=self.doc.study
d.status='Waiting'
d.encounter=self.doc.name
d.start_time=date_a
d.end_time=date_b
d.save()
self.make_event(d.name)
self.doc.slot=d.name
else:
webnotes.msgprint("Selected slot is not available",raise_exception=1)
else:
webnotes.msgprint("Selected slot is not available",raise_exception=1)
示例12: update_warranty_amc_history
def update_warranty_amc_history(self, submit = 1):
if self.doc.order_type in ['AMC', 'OTS (One Time Service)']:
sr_list = []
if submit:
for d in getlist(self.doclist, 'service_order_details'):
sr = Document('Serial No', d.serial_no)
child = addchild(sr, 'warranty_amc_history', 'Warranty AMC History', 0)
child.from_date = d.start_date
child.to_date = d.end_date
child.status = (self.doc.order_type == 'AMC') and 'Under AMC' or 'OTS (One Time Service)'
child.against_doctype = self.doc.doctype
child.against_docname = self.doc.name
child.customer = self.doc.customer
child.territory = self.doc.territory
child.save()
sr.warranty_amc_status = (self.doc.order_type == 'AMC') and 'Under AMC' or 'OTS (One Time Service)'
sr.amc_expiry_date = d.end_date
sr.save()
sr_list.append(d.serial_no)
else:
sql("delete from `tabWarranty AMC History` where against_doctype = %s and against_docname = %s", (self.doc.doctype, self.doc.name))
for d in getlist(self.doclist, 'service_order_details'):
sql("update `tabSerial No` set amc_expiry_date = '' where name = '%s'" % (d.serial_no))
sr_list.append(d.serial_no)
self.update_serial_no_warranty_amc_status(serial_no_list = sr_list)
示例13: add
def add():
"""add in someone's to do list"""
if webnotes.conn.sql("""select owner from `tabToDo Item`
where reference_type=%(doctype)s and reference_name=%(name)s
and owner=%(assign_to)s""", webnotes.form_dict):
webnotes.msgprint("Already in todo")
return
else:
from webnotes.model.doc import Document
from webnotes.utils import nowdate
d = Document("ToDo Item")
d.owner = webnotes.form_dict['assign_to']
d.reference_type = webnotes.form_dict['doctype']
d.reference_name = webnotes.form_dict['name']
d.description = webnotes.form_dict['description']
d.priority = webnotes.form_dict.get('priority', 'Medium')
d.date = webnotes.form_dict.get('date', nowdate())
d.assigned_by = webnotes.user.name
d.save(1)
# notify
notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=webnotes.form_dict.get('notify'))
# update feeed
try:
import home
from webnotes.utils import get_fullname
home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
'[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
except ImportError, e:
pass
示例14: make_item_group_active
def make_item_group_active(self):
"""show item group in website"""
if self.doc.published:
from webnotes.model.doc import Document
ig = Document('Item Group', self.doc.item_group)
ig.show_in_website = 1
ig.save()
示例15: create_production_order
def create_production_order(self,company, pp_items):
"""Create production order. Called from Production Planning Tool"""
default_values = {
'posting_date' : nowdate(),
'origin' : 'MRP',
'wip_warehouse' : '',
'fg_warehouse' : '',
'status' : 'Draft',
'company' : company,
'fiscal_year' : get_defaults()['fiscal_year']
}
pro_list = []
for d in pp_items:
pro_doc = Document('Production Order')
for key in d.keys():
pro_doc.fields[key] = d[key]
for key in default_values:
pro_doc.fields[key] = default_values[key]
pro_doc.save(new = 1)
pro_list.append(pro_doc.name)
return pro_list