Exemplo n.º 1
0
def make_test_objects(doctype, test_records, verbose=None):
	records = []
		
	for doclist in test_records:
		if "doctype" not in doclist[0]:
			doclist[0]["doctype"] = doctype
		d = frappe.bean(copy=doclist)
		
		if frappe.local.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
Exemplo n.º 2
0
    def update_biling_status(self, zero_amount_refdoc, ref_dt, ref_fieldname):
        for ref_dn in zero_amount_refdoc:
            ref_doc_qty = flt(
                frappe.db.sql(
                    """select sum(ifnull(qty, 0)) from `tab%s Item` 
				where parent=%s""" % (ref_dt, '%s'), (ref_dn))[0][0])

            billed_qty = flt(
                frappe.db.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
            frappe.db.set_value(ref_dt, ref_dn, "per_billed", per_billed)

            from frappe.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"

                frappe.db.set_value(ref_dt, ref_dn, "billing_status",
                                    billing_status)
Exemplo n.º 3
0
def remove(doctype, name, assign_to):
    """remove from todo"""
    todo = frappe.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 frappe.model.meta import has_field
    if has_field(doctype, "assigned_to"):
        frappe.db.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})
Exemplo n.º 4
0
def get_item_details(args):
    """
		args = {
			"item_code": "",
			"warehouse": None,
			"customer": "",
			"conversion_rate": 1.0,
			"selling_price_list": None,
			"price_list_currency": None,
			"plc_conversion_rate": 1.0
			"doctype": "",
			"docname": "",
			"supplier": None,
			"transaction_date": None,
			"conversion_rate": 1.0,
			"buying_price_list": None,
			"is_subcontracted": "Yes" / "No",
			"transaction_type": "selling"
		}
	"""

    if isinstance(args, basestring):
        args = json.loads(args)
    args = frappe._dict(args)

    if not args.get("transaction_type"):
        args.transaction_type = "buying" if has_field(args.get("doctype"), "supplier") \
         else "selling"

    if not args.get("price_list"):
        args.price_list = args.get("selling_price_list") or args.get(
            "buying_price_list")

    if args.barcode:
        args.item_code = get_item_code(barcode=args.barcode)
    elif not args.item_code and args.serial_no:
        args.item_code = get_item_code(serial_no=args.serial_no)

    item_bean = frappe.bean("Item", args.item_code)
    item = item_bean.doc

    validate_item_details(args, item)

    out = get_basic_details(args, item_bean)

    get_party_item_code(args, item_bean, out)

    if out.get("warehouse"):
        out.update(get_available_qty(args.item_code, out.warehouse))
        out.update(get_projected_qty(item.name, out.warehouse))

    get_price_list_rate(args, item_bean, out)

    out.update(get_item_discount(out.item_group, args.customer))

    if args.transaction_type == "selling" and cint(args.is_pos):
        out.update(get_pos_settings_item_details(args.company, args))

    if args.get("doctype") in ("Sales Invoice", "Delivery Note"):
        if item_bean.doc.has_serial_no == "Yes" and not args.serial_no:
            out.serial_no = get_serial_nos_by_fifo(args, item_bean)

    if args.transaction_date and item.lead_time_days:
        out.schedule_date = out.lead_time_date = add_days(
            args.transaction_date, item.lead_time_days)

    return out
Exemplo n.º 5
0
def add(args=None):
    """add in someone's to do list"""
    if not args:
        args = frappe.local.form_dict

    if frappe.db.sql(
            """select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
		and owner=%(assign_to)s""", args):
        frappe.msgprint("Already in todo", raise_exception=True)
        return
    else:
        from frappe.utils import nowdate

        d = frappe.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', frappe.user.name),
        }).insert(ignore_permissions=True).doc

        # set assigned_to if field exists
        from frappe.model.meta import has_field
        if has_field(args['doctype'], "assigned_to"):
            frappe.db.set_value(args['doctype'], args['name'], "assigned_to",
                                args['assign_to'])

    try:
        if cint(args.get("restrict")):
            from frappe.core.page.user_properties import user_properties
            user_properties.add(args['assign_to'], args['doctype'],
                                args['name'])
            frappe.msgprint(_("Restriction added"))
    except frappe.PermissionError:
        frappe.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 frappe.utils import get_fullname
        make_feed('Assignment', d.reference_type, d.reference_name,
                  frappe.session['user'],
                  '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)),
                  '#C78F58')
    except ImportError, e:
        pass