def make_test_objects(doctype, test_records, verbose=None): records = [] for doclist in test_records: if not "doctype" in doclist[0]: doclist[0]["doctype"] = doctype d = webnotes.bean((webnotes.doclist(doclist)).copy()) if webnotes.test_objects.get(d.doc.doctype): # do not create test records, if already exists return [] if has_field(d.doc.doctype, "naming_series"): if not d.doc.naming_series: d.doc.naming_series = "_T-" + d.doc.doctype + "-" # submit if docstatus is set to 1 for test record docstatus = d.doc.docstatus d.doc.docstatus = 0 d.insert() if docstatus == 1: d.submit() records.append(d.doc.name) return records
def make_test_objects(doctype, test_records, verbose=None): records = [] for doclist in test_records: if not "doctype" in doclist[0]: doclist[0]["doctype"] = doctype d = webnotes.bean(copy=doclist) if webnotes.test_objects.get(d.doc.doctype): # do not create test records, if already exists return [] if has_field(d.doc.doctype, "naming_series"): if not d.doc.naming_series: d.doc.naming_series = "_T-" + d.doc.doctype + "-" # submit if docstatus is set to 1 for test record docstatus = d.doc.docstatus d.doc.docstatus = 0 d.insert() if docstatus == 1: d.submit() records.append(d.doc.name) return records
def add(args=None): """add in someone's to do list""" if not args: args = webnotes.form_dict if webnotes.conn.sql( """select owner from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", args): webnotes.msgprint("Already in todo", raise_exception=True) return else: from webnotes.model.doc import Document from webnotes.utils import nowdate d = Document("ToDo") d.owner = args['assign_to'] d.reference_type = args['doctype'] d.reference_name = args['name'] d.description = args.get('description') d.priority = args.get('priority', 'Medium') d.date = args.get('date', nowdate()) d.assigned_by = args.get('assigned_by', webnotes.user.name) d.save(1) # set assigned_to if field exists from webnotes.model.meta import has_field if has_field(args['doctype'], "assigned_to"): webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to']) # notify if not args.get("no_notification"): notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.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
def add(args=None): """add in someone's to do list""" if not args: args = webnotes.local.form_dict if webnotes.conn.sql("""select owner from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and status="Open" and owner=%(assign_to)s""", args): webnotes.msgprint("Already in todo", raise_exception=True) return else: from webnotes.utils import nowdate d = webnotes.bean({ "doctype":"ToDo", "owner": args['assign_to'], "reference_type": args['doctype'], "reference_name": args['name'], "description": args.get('description'), "priority": args.get("priority", "Medium"), "status": "Open", "date": args.get('date', nowdate()), "assigned_by": args.get('assigned_by', webnotes.user.name), }).insert(ignore_permissions=True).doc # set assigned_to if field exists from webnotes.model.meta import has_field if has_field(args['doctype'], "assigned_to"): webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to']) try: if cint(args.get("restrict")): from webnotes.core.page.user_properties import user_properties user_properties.add(args['assign_to'], args['doctype'], args['name']) webnotes.msgprint(_("Restriction added")) except webnotes.PermissionError: webnotes.throw("{cannot}: {user}, {_for}: {doctype} {_and}: {name}".format(cannot=_("You cannot restrict User"), user=args['assign_to'], _for=_("for DocType"), doctype=_(args['doctype']), _and=_("and Name"), name=args['name'])) # notify if not args.get("no_notification"): notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify')) # update feeed try: from erpnext.home import make_feed from webnotes.utils import get_fullname 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
def remove(doctype, name, assign_to): """remove from todo""" todo = webnotes.bean("ToDo", {"reference_type":doctype, "reference_name":name, "owner":assign_to, "status":"Open"}) todo.doc.status = "Closed" todo.save(ignore_permissions=True) # clear assigned_to if field exists from webnotes.model.meta import has_field if has_field(doctype, "assigned_to"): webnotes.conn.set_value(doctype, name, "assigned_to", None) notify_assignment(todo.doc.assigned_by, todo.doc.owner, todo.doc.reference_type, todo.doc.reference_name) return get({"doctype": doctype, "name": name})
def make_test_objects(doctype, test_records): records = [] for doclist in test_records: if not "doctype" in doclist[0]: doclist[0]["doctype"] = doctype d = webnotes.model_wrapper((webnotes.doclist(doclist)).copy()) if webnotes.test_objects.get(d.doc.doctype): # do not create test records, if already exists return [] if has_field(d.doc.doctype, "naming_series"): if not d.doc.naming_series: d.doc.naming_series = "_T-" + d.doc.doctype + "-" d.insert() records.append(d.doc.name) return records
def add(args=None): """add in someone's to do list""" if not args: args = webnotes.local.form_dict if webnotes.conn.sql("""select owner from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", args): webnotes.msgprint("Already in todo", raise_exception=True) return else: from webnotes.model.doc import Document from webnotes.utils import nowdate d = Document("ToDo") d.owner = args['assign_to'] d.reference_type = args['doctype'] d.reference_name = args['name'] d.description = args.get('description') d.priority = args.get('priority', 'Medium') d.date = args.get('date', nowdate()) d.assigned_by = args.get('assigned_by', webnotes.user.name) d.save(1) if args['doctype']=='Opportunity': update_assign_to(args) # set assigned_to if field exists from webnotes.model.meta import has_field if has_field(args['doctype'], "assigned_to"): webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to']) # notify if not args.get("no_notification"): notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.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
def remove(doctype, name, assign_to): """remove from todo""" res = webnotes.conn.sql("""\ select assigned_by, owner, reference_type, reference_name from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", locals()) webnotes.conn.sql("""delete from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", locals()) # clear assigned_to if field exists from webnotes.model.meta import has_field if has_field(doctype, "assigned_to"): webnotes.conn.set_value(doctype, name, "assigned_to", None) if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3]) return get({"doctype": doctype, "name": name})
def update_biling_status(self, zero_amount_refdoc, ref_dt, ref_fieldname): for ref_dn in zero_amount_refdoc: ref_doc_qty = flt(webnotes.conn.sql("""select sum(ifnull(qty, 0)) from `tab%s Item` where parent=%s""" % (ref_dt, '%s'), (ref_dn))[0][0]) billed_qty = flt(webnotes.conn.sql("""select sum(ifnull(qty, 0)) from `tab%s Item` where %s=%s and docstatus=1""" % (self.doc.doctype, ref_fieldname, '%s'), (ref_dn))[0][0]) per_billed = ((ref_doc_qty if billed_qty > ref_doc_qty else billed_qty)\ / ref_doc_qty)*100 webnotes.conn.set_value(ref_dt, ref_dn, "per_billed", per_billed) from webnotes.model.meta import has_field if has_field(ref_dt, "billing_status"): if per_billed < 0.001: billing_status = "Not Billed" elif per_billed >= 99.99: billing_status = "Fully Billed" else: billing_status = "Partly Billed" webnotes.conn.set_value(ref_dt, ref_dn, "billing_status", billing_status)
def remove(doctype, name, assign_to): """remove from todo""" res = webnotes.conn.sql( """\ select assigned_by, owner, reference_type, reference_name from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", locals()) webnotes.conn.sql( """delete from `tabToDo` where reference_type=%(doctype)s and reference_name=%(name)s and owner=%(assign_to)s""", locals()) # clear assigned_to if field exists from webnotes.model.meta import has_field if has_field(doctype, "assigned_to"): webnotes.conn.set_value(doctype, name, "assigned_to", None) if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3]) return get({"doctype": doctype, "name": name})