Skip to content

Commit

Permalink
fix: indentation issue in the Production Plan Summary report (#38019)
Browse files Browse the repository at this point in the history
fix: Production Plan Summary report
  • Loading branch information
rohitwaghchaure authored Nov 13, 2023
1 parent ffd171a commit 4a111f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ frappe.ui.form.on('Production Plan', {
frm.trigger("show_progress");

if (frm.doc.status !== "Completed") {
frm.add_custom_button(__("Work Order Tree"), ()=> {
frappe.set_route('Tree', 'Work Order', {production_plan: frm.doc.name});
}, __('View'));

frm.add_custom_button(__("Production Plan Summary"), ()=> {
frappe.set_route('query-report', 'Production Plan Summary', {production_plan: frm.doc.name});
}, __('View'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ def get_sub_assembly_items(self, manufacturing_type=None):
# Combine subassembly items
sub_assembly_items_store = self.combine_subassembly_items(sub_assembly_items_store)

sub_assembly_items_store.sort(key=lambda d: d.bom_level, reverse=True) # sort by bom level

for idx, row in enumerate(sub_assembly_items_store):
row.idx = idx + 1
self.append("sub_assembly_items", row)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,49 +664,6 @@ def test_get_sales_order_with_variant(self):

frappe.db.rollback()

def test_subassmebly_sorting(self):
"Test subassembly sorting in case of multiple items with nested BOMs."
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom

prefix = "_TestLevel_"
boms = {
"Assembly": {
"SubAssembly1": {
"ChildPart1": {},
"ChildPart2": {},
},
"ChildPart6": {},
"SubAssembly4": {"SubSubAssy2": {"ChildPart7": {}}},
},
"MegaDeepAssy": {
"SecretSubassy": {
"SecretPart": {"VerySecret": {"SuperSecret": {"Classified": {}}}},
},
# ^ assert that this is
# first item in subassy table
},
}
create_nested_bom(boms, prefix=prefix)

items = [prefix + item_code for item_code in boms.keys()]
plan = create_production_plan(item_code=items[0], do_not_save=True)
plan.append(
"po_items",
{
"use_multi_level_bom": 1,
"item_code": items[1],
"bom_no": frappe.db.get_value("Item", items[1], "default_bom"),
"planned_qty": 1,
"planned_start_date": now_datetime(),
},
)
plan.get_sub_assembly_items()

bom_level_order = [d.bom_level for d in plan.sub_assembly_items]
self.assertEqual(bom_level_order, sorted(bom_level_order, reverse=True))
# lowest most level of subassembly should be first
self.assertIn("SuperSecret", plan.sub_assembly_items[0].production_item)

def test_multiple_work_order_for_production_plan_item(self):
"Test producing Prod Plan (making WO) in parts."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ frappe.query_reports["Production Plan Summary"] = {
"formatter": function(value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);

if (column.fieldname == "document_name") {
if (column.fieldname == "item_code") {
var color = data.pending_qty > 0 ? 'red': 'green';
value = `<a style='color:${color}' href="#Form/${data['document_type']}/${data['document_name']}" data-doctype="${data['document_type']}">${data['document_name']}</a>`;
value = `<a style='color:${color}' href="/app/item/${data['item_code']}" data-doctype="Item">${data['item_code']}</a>`;
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_production_plan_item_details(filters, data, order_details):
{
"indent": 0,
"item_code": row.item_code,
"sales_order": row.get("sales_order"),
"item_name": frappe.get_cached_value("Item", row.item_code, "item_name"),
"qty": row.planned_qty,
"document_type": "Work Order",
Expand Down Expand Up @@ -80,7 +81,7 @@ def get_production_plan_sub_assembly_item_details(

data.append(
{
"indent": 1,
"indent": 1 + item.indent,
"item_code": item.production_item,
"item_name": item.item_name,
"qty": item.qty,
Expand All @@ -98,7 +99,7 @@ def get_work_order_details(filters, order_details):
for row in frappe.get_all(
"Work Order",
filters={"production_plan": filters.get("production_plan")},
fields=["name", "produced_qty", "production_plan", "production_item"],
fields=["name", "produced_qty", "production_plan", "production_item", "sales_order"],
):
order_details.setdefault((row.name, row.production_item), row)

Expand All @@ -118,10 +119,17 @@ def get_column(filters):
"label": _("Finished Good"),
"fieldtype": "Link",
"fieldname": "item_code",
"width": 300,
"width": 240,
"options": "Item",
},
{"label": _("Item Name"), "fieldtype": "data", "fieldname": "item_name", "width": 100},
{"label": _("Item Name"), "fieldtype": "data", "fieldname": "item_name", "width": 150},
{
"label": _("Sales Order"),
"options": "Sales Order",
"fieldtype": "Link",
"fieldname": "sales_order",
"width": 100,
},
{
"label": _("Document Type"),
"fieldtype": "Link",
Expand All @@ -133,10 +141,16 @@ def get_column(filters):
"label": _("Document Name"),
"fieldtype": "Dynamic Link",
"fieldname": "document_name",
"width": 150,
"options": "document_type",
"width": 180,
},
{"label": _("BOM Level"), "fieldtype": "Int", "fieldname": "bom_level", "width": 100},
{"label": _("Order Qty"), "fieldtype": "Float", "fieldname": "qty", "width": 120},
{"label": _("Received Qty"), "fieldtype": "Float", "fieldname": "produced_qty", "width": 160},
{
"label": _("Produced / Received Qty"),
"fieldtype": "Float",
"fieldname": "produced_qty",
"width": 200,
},
{"label": _("Pending Qty"), "fieldtype": "Float", "fieldname": "pending_qty", "width": 110},
]

0 comments on commit 4a111f7

Please sign in to comment.