Example #1
0
def get_data(filters, columns):
    data = []
    entry = frappe.get_all("Work Order",
                           fields=[
                               "creation", "modified", "actual_start_date",
                               "actual_end_date", "planned_start_date",
                               "planned_end_date", "status"
                           ],
                           filters={
                               "docstatus": 1,
                               "company": filters["company"]
                           })

    periodic_data = get_periodic_data(filters, entry)

    labels = [
        "All Work Orders", "Not Started", "Overdue", "Pending", "Completed"
    ]
    chart_data = get_chart_data(periodic_data, columns)
    ranges = get_period_date_ranges(filters)

    for label in labels:
        work = {}
        work["Status"] = label
        for dummy, end_date in ranges:
            period = get_period(end_date, filters)
            if periodic_data.get(label).get(period):
                work[scrub(period)] = periodic_data.get(label).get(period)
            else:
                work[scrub(period)] = 0.0
        data.append(work)

    return data, chart_data
Example #2
0
def prepare_chart_data(data, filters):
    labels = []

    periodic_data = {"Pending": {}, "Completed": {}}

    filters.range = "Monthly"

    ranges = get_period_date_ranges(filters)
    for from_date, end_date in ranges:
        period = get_period(end_date, filters)
        if period not in labels:
            labels.append(period)

        if period not in periodic_data["Pending"]:
            periodic_data["Pending"][period] = 0

        if period not in periodic_data["Completed"]:
            periodic_data["Completed"][period] = 0

        for d in data:
            if getdate(d.planned_start_date) >= from_date and getdate(
                    d.planned_start_date) <= end_date:
                periodic_data["Pending"][period] += (flt(d.qty) -
                                                     flt(d.produced_qty))
                periodic_data["Completed"][period] += flt(d.produced_qty)

    return labels, periodic_data
Example #3
0
def get_periodic_data(filters, entry):
    periodic_data = {
        "All Work Orders": {},
        "Not Started": {},
        "Overdue": {},
        "Pending": {},
        "Completed": {}
    }

    ranges = get_period_date_ranges(filters)

    for from_date, end_date in ranges:
        period = get_period(end_date, filters)
        for d in entry:
            if getdate(d.creation) <= getdate(from_date) or getdate(
                    d.creation) <= getdate(end_date):
                periodic_data = update_periodic_data(periodic_data,
                                                     "All Work Orders", period)
                if d.status == 'Completed':
                    if getdate(
                            d.actual_end_date) < getdate(from_date) or getdate(
                                d.modified) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Completed", period)
                    elif getdate(d.actual_start_date) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Pending", period)
                    elif getdate(d.planned_start_date) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Overdue", period)
                    else:
                        periodic_data = update_periodic_data(
                            periodic_data, "Not Started", period)

                elif d.status == 'In Process':
                    if getdate(d.actual_start_date) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Pending", period)
                    elif getdate(d.planned_start_date) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Overdue", period)
                    else:
                        periodic_data = update_periodic_data(
                            periodic_data, "Not Started", period)

                elif d.status == 'Not Started':
                    if getdate(d.planned_start_date) < getdate(from_date):
                        periodic_data = update_periodic_data(
                            periodic_data, "Overdue", period)
                    else:
                        periodic_data = update_periodic_data(
                            periodic_data, "Not Started", period)

    return periodic_data
Example #4
0
def get_columns(filters):
    columns = [{
        "label": _("Status"),
        "fieldname": "Status",
        "fieldtype": "Data",
        "width": 140
    }]

    ranges = get_period_date_ranges(filters)

    for dummy, end_date in ranges:

        period = get_period(end_date, filters)

        columns.append({
            "label": _(period),
            "fieldname": scrub(period),
            "fieldtype": "Float",
            "width": 120
        })

    return columns
Example #5
0
def prepare_chart_data(job_card_details, filters):
    labels = []

    periodic_data = {"Open": {}, "Completed": {}}

    filters.range = "Monthly"

    ranges = get_period_date_ranges(filters)
    for from_date, end_date in ranges:
        period = get_period(end_date, filters)
        if period not in labels:
            labels.append(period)

        for d in job_card_details:
            if getdate(d.posting_date) > from_date and getdate(
                    d.posting_date) <= end_date:
                status = "Completed" if d.status == "Completed" else "Open"

                if periodic_data.get(status).get(period):
                    periodic_data[status][period] += 1
                else:
                    periodic_data[status][period] = 1

    return labels, periodic_data