-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report to see the consumed materials against the work order
- Loading branch information
1 parent
aa68987
commit c5fad91
Showing
5 changed files
with
355 additions
and
15 deletions.
There are no files selected for viewing
Empty file.
70 changes: 70 additions & 0 deletions
70
erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
/* eslint-disable */ | ||
|
||
frappe.query_reports["Work Order Consumed Materials"] = { | ||
"filters": [ | ||
{ | ||
label: __("Company"), | ||
fieldname: "company", | ||
fieldtype: "Link", | ||
options: "Company", | ||
default: frappe.defaults.get_user_default("Company"), | ||
reqd: 1 | ||
}, | ||
{ | ||
label: __("From Date"), | ||
fieldname:"from_date", | ||
fieldtype: "Date", | ||
default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), | ||
reqd: 1 | ||
}, | ||
{ | ||
fieldname:"to_date", | ||
label: __("To Date"), | ||
fieldtype: "Date", | ||
default: frappe.datetime.get_today(), | ||
reqd: 1 | ||
}, | ||
{ | ||
label: __("Work Order"), | ||
fieldname: "name", | ||
fieldtype: "Link", | ||
options: "Work Order", | ||
get_query: function() { | ||
return { | ||
filters: { | ||
status: ["in", ["In Process", "Completed", "Stopped"]] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
label: __("Production Item"), | ||
fieldname: "production_item", | ||
fieldtype: "Link", | ||
depends_on: "eval: !doc.name", | ||
options: "Item" | ||
}, | ||
{ | ||
label: __("Status"), | ||
fieldname: "status", | ||
fieldtype: "Select", | ||
options: ["In Process", "Completed", "Stopped"] | ||
}, | ||
{ | ||
label: __("Excess Materials Consumed"), | ||
fieldname: "show_extra_consumed_materials", | ||
fieldtype: "Check" | ||
} | ||
], | ||
"formatter": function(value, row, column, data, default_formatter) { | ||
value = default_formatter(value, row, column, data); | ||
|
||
if (column.fieldname == "raw_material_name" && data && data.extra_consumed_qty > 0 ) { | ||
value = `<div style="color:red">${value}</div>`; | ||
} | ||
|
||
return value; | ||
}, | ||
}; |
30 changes: 30 additions & 0 deletions
30
...ext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"add_total_row": 0, | ||
"columns": [], | ||
"creation": "2021-11-22 17:36:11.886939", | ||
"disable_prepared_report": 0, | ||
"disabled": 0, | ||
"docstatus": 0, | ||
"doctype": "Report", | ||
"filters": [], | ||
"idx": 0, | ||
"is_standard": "Yes", | ||
"letter_head": "Gadgets International", | ||
"modified": "2021-11-22 17:36:14.999091", | ||
"modified_by": "Administrator", | ||
"module": "Manufacturing", | ||
"name": "Work Order Consumed Materials", | ||
"owner": "Administrator", | ||
"prepared_report": 0, | ||
"ref_doctype": "Work Order", | ||
"report_name": "Work Order Consumed Materials", | ||
"report_type": "Script Report", | ||
"roles": [ | ||
{ | ||
"role": "Manufacturing User" | ||
}, | ||
{ | ||
"role": "Stock User" | ||
} | ||
] | ||
} |
135 changes: 135 additions & 0 deletions
135
erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
import json | ||
from frappe import _ | ||
|
||
def execute(filters=None): | ||
columns, data = [], [] | ||
columns = get_columns() | ||
data = get_data(filters) | ||
|
||
return columns, data | ||
|
||
def get_data(report_filters): | ||
fields = get_fields() | ||
filters = get_filter_condition(report_filters) | ||
|
||
wo_items = {} | ||
for d in frappe.get_all("Work Order", filters = filters, fields=fields): | ||
d.extra_consumed_qty = 0.0 | ||
if d.consumed_qty and d.consumed_qty > d.required_qty: | ||
d.extra_consumed_qty = d.consumed_qty - d.required_qty | ||
|
||
if d.extra_consumed_qty or not report_filters.show_extra_consumed_materials: | ||
wo_items.setdefault((d.name, d.production_item), []).append(d) | ||
|
||
data = [] | ||
for key, wo_data in wo_items.items(): | ||
for index, row in enumerate(wo_data): | ||
if index != 0: | ||
#If one work order has multiple raw materials then show parent data in the first row only | ||
for field in ["name", "status", "production_item", "qty", "produced_qty"]: | ||
row[field] = "" | ||
|
||
for key in ["transferred_batch_no", "consumed_batch_no"]: | ||
if row.get(key): | ||
row[key] = ','.join(json.loads(row.get(key)).keys()) | ||
|
||
data.append(row) | ||
|
||
return data | ||
|
||
def get_fields(): | ||
return ["`tabWork Order Item`.`parent`", "`tabWork Order Item`.`item_code` as raw_material_item_code", | ||
"`tabWork Order Item`.`item_name` as raw_material_name", "`tabWork Order Item`.`required_qty`", | ||
"`tabWork Order Item`.`transferred_qty`", "`tabWork Order Item`.`consumed_qty`", "`tabWork Order`.`status`", | ||
"`tabWork Order`.`name`", "`tabWork Order`.`production_item`", "`tabWork Order`.`qty`", | ||
"`tabWork Order`.`produced_qty`"] | ||
|
||
def get_filter_condition(report_filters): | ||
filters = { | ||
"docstatus": 1, "status": ("in", ["In Process", "Completed", "Stopped"]), | ||
"creation": ("between", [report_filters.from_date, report_filters.to_date]) | ||
} | ||
|
||
for field in ["name", "production_item", "company", "status"]: | ||
value = report_filters.get(field) | ||
if value: | ||
key = f"`{field}`" | ||
filters.update({key: value}) | ||
|
||
return filters | ||
|
||
def get_columns(): | ||
return [ | ||
{ | ||
"label": _("Id"), | ||
"fieldname": "name", | ||
"fieldtype": "Link", | ||
"options": "Work Order", | ||
"width": 80 | ||
}, | ||
{ | ||
"label": _("Status"), | ||
"fieldname": "status", | ||
"fieldtype": "Data", | ||
"width": 80 | ||
}, | ||
{ | ||
"label": _("Production Item"), | ||
"fieldname": "production_item", | ||
"fieldtype": "Link", | ||
"options": "Item", | ||
"width": 130 | ||
}, | ||
{ | ||
"label": _("Qty to Produce"), | ||
"fieldname": "qty", | ||
"fieldtype": "Float", | ||
"width": 120 | ||
}, | ||
{ | ||
"label": _("Produced Qty"), | ||
"fieldname": "produced_qty", | ||
"fieldtype": "Float", | ||
"width": 110 | ||
}, | ||
{ | ||
"label": _("Raw Material Item"), | ||
"fieldname": "raw_material_item_code", | ||
"fieldtype": "Link", | ||
"options": "Item", | ||
"width": 150 | ||
}, | ||
{ | ||
"label": _("Item Name"), | ||
"fieldname": "raw_material_name", | ||
"width": 130 | ||
}, | ||
{ | ||
"label": _("Required Qty"), | ||
"fieldname": "required_qty", | ||
"fieldtype": "Float", | ||
"width": 100 | ||
}, | ||
{ | ||
"label": _("Transferred Qty"), | ||
"fieldname": "transferred_qty", | ||
"fieldtype": "Float", | ||
"width": 100 | ||
}, | ||
{ | ||
"label": _("Consumed Qty"), | ||
"fieldname": "consumed_qty", | ||
"fieldtype": "Float", | ||
"width": 100 | ||
}, | ||
{ | ||
"label": _("Extra Consumed Qty"), | ||
"fieldname": "extra_consumed_qty", | ||
"fieldtype": "Float", | ||
"width": 100 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters