Merge pull request #55091 from rohitwaghchaure/fixed-job-card-pending-qty

feat: pending qty in job card
This commit is contained in:
rohitwaghchaure
2026-05-22 15:21:44 +05:30
committed by GitHub
7 changed files with 575 additions and 419 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7,25 +7,34 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"section_break_smqo",
"job_card_dashboard",
"section_break_fsba",
"work_order",
"column_break_uqjq",
"production_item",
"column_break_qrpg",
"for_quantity",
"column_break_yecz",
"bom_no",
"section_break_oisd",
"company",
"naming_series",
"work_order",
"employee",
"column_break_4",
"posting_date",
"project",
"bom_no",
"is_subcontracted",
"semi_finished_good__finished_good_section",
"finished_good",
"production_item",
"semi_fg_bom",
"total_completed_qty",
"column_break_mcnb",
"for_quantity",
"transferred_qty",
"manufactured_qty",
"semi_fg_bom",
"section_break_folk",
"pending_qty",
"column_break_cyjw",
"process_loss_qty",
"total_completed_qty",
"section_break_wpjf",
"transferred_qty",
"column_break_lgte",
"manufactured_qty",
"production_section",
"operation",
"source_warehouse",
@@ -36,6 +45,7 @@
"workstation_type",
"workstation",
"target_warehouse",
"employee",
"section_break_8",
"items",
"quality_inspection_section",
@@ -72,8 +82,10 @@
"item_name",
"requested_qty",
"is_paused",
"is_subcontracted",
"track_semi_finished_goods",
"column_break_20",
"project",
"remarks",
"section_break_dfoc",
"status",
@@ -626,12 +638,64 @@
"fieldname": "secondary_items_section",
"fieldtype": "Tab Break",
"label": "Secondary Items"
},
{
"fieldname": "section_break_folk",
"fieldtype": "Section Break",
"hide_border": 1
},
{
"fieldname": "column_break_cyjw",
"fieldtype": "Column Break"
},
{
"allow_on_submit": 1,
"fieldname": "pending_qty",
"fieldtype": "Float",
"label": "Pending Qty"
},
{
"fieldname": "section_break_wpjf",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_lgte",
"fieldtype": "Column Break"
},
{
"fieldname": "job_card_dashboard",
"fieldtype": "HTML"
},
{
"fieldname": "section_break_oisd",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_uqjq",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_qrpg",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_yecz",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_smqo",
"fieldtype": "Section Break",
"hide_border": 1
},
{
"fieldname": "section_break_fsba",
"fieldtype": "Section Break"
}
],
"grid_page_length": 50,
"is_submittable": 1,
"links": [],
"modified": "2026-05-12 12:17:17.750857",
"modified": "2026-05-21 18:37:05.688342",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Job Card",

View File

@@ -104,6 +104,7 @@ class JobCard(Document):
operation_id: DF.Data | None
operation_row_id: DF.Int
operation_row_number: DF.Literal[None]
pending_qty: DF.Float
posting_date: DF.Date | None
process_loss_qty: DF.Float
production_item: DF.Link | None
@@ -882,7 +883,9 @@ class JobCard(Document):
precision = self.precision("total_completed_qty")
total_completed_qty = flt(
flt(self.total_completed_qty, precision) + flt(self.process_loss_qty, precision)
flt(self.total_completed_qty, precision)
+ flt(self.process_loss_qty, precision)
+ flt(self.pending_qty, precision)
)
if self.for_quantity and flt(total_completed_qty, precision) != flt(self.for_quantity, precision):
@@ -929,8 +932,10 @@ class JobCard(Document):
self.process_loss_qty = 0.0
if self.total_completed_qty and self.for_quantity > self.total_completed_qty:
self.process_loss_qty = flt(self.for_quantity, precision) - flt(
self.total_completed_qty, precision
self.process_loss_qty = (
flt(self.for_quantity, precision)
- flt(self.total_completed_qty, precision)
- flt(self.pending_qty, precision)
)
def update_work_order(self):
@@ -944,13 +949,14 @@ class JobCard(Document):
):
return
for_quantity, time_in_mins, process_loss_qty = 0, 0, 0
for_quantity, time_in_mins, process_loss_qty, pending_qty = 0, 0, 0, 0
data = self.get_current_operation_data()
if data and len(data) > 0:
for_quantity = flt(data[0].completed_qty)
time_in_mins = flt(data[0].time_in_mins)
process_loss_qty = flt(data[0].process_loss_qty)
pending_qty = flt(data[0].pending_qty)
wo = frappe.get_doc("Work Order", self.work_order)
@@ -958,8 +964,8 @@ class JobCard(Document):
self.update_corrective_in_work_order(wo)
elif self.operation_id:
self.validate_produced_quantity(for_quantity, process_loss_qty, wo)
self.update_work_order_data(for_quantity, process_loss_qty, time_in_mins, wo)
self.validate_produced_quantity(for_quantity, process_loss_qty, pending_qty, wo)
self.update_work_order_data(for_quantity, process_loss_qty, pending_qty, time_in_mins, wo)
def update_semi_finished_good_details(self):
if self.operation_id:
@@ -988,11 +994,11 @@ class JobCard(Document):
wo.flags.ignore_validate_update_after_submit = True
wo.save()
def validate_produced_quantity(self, for_quantity, process_loss_qty, wo):
def validate_produced_quantity(self, for_quantity, process_loss_qty, pending_qty, wo):
if self.docstatus < 2:
return
if wo.produced_qty > for_quantity + process_loss_qty:
if wo.produced_qty > for_quantity + process_loss_qty + pending_qty:
first_part_msg = _(
"The {0} {1} is used to calculate the valuation cost for the finished good {2}."
).format(frappe.bold(_("Job Card")), frappe.bold(self.name), frappe.bold(self.production_item))
@@ -1005,7 +1011,7 @@ class JobCard(Document):
_("{0} {1}").format(first_part_msg, second_part_msg), JobCardCancelError, title=_("Error")
)
def update_work_order_data(self, for_quantity, process_loss_qty, time_in_mins, wo):
def update_work_order_data(self, for_quantity, process_loss_qty, pending_qty, time_in_mins, wo):
workstation_hour_rate = frappe.get_value("Workstation", self.workstation, "hour_rate")
jc = frappe.qb.DocType("Job Card")
jctl = frappe.qb.DocType("Job Card Time Log")
@@ -1027,6 +1033,7 @@ class JobCard(Document):
if data.get("name") == self.operation_id:
data.completed_qty = for_quantity
data.process_loss_qty = process_loss_qty
data.pending_qty = pending_qty
data.actual_operation_time = time_in_mins
data.actual_start_time = time_data[0].start_time if time_data else None
data.actual_end_time = time_data[0].end_time if time_data else None
@@ -1052,6 +1059,7 @@ class JobCard(Document):
{"SUM": "total_time_in_mins", "as": "time_in_mins"},
{"SUM": "total_completed_qty", "as": "completed_qty"},
{"SUM": "process_loss_qty", "as": "process_loss_qty"},
{"SUM": "pending_qty", "as": "pending_qty"},
],
filters={
"docstatus": 1,
@@ -1446,10 +1454,19 @@ class JobCard(Document):
if isinstance(kwargs, dict):
kwargs = frappe._dict(kwargs)
if kwargs.end_time:
if kwargs.for_quantity:
self.for_quantity = kwargs.for_quantity
if flt(kwargs.pending_qty) and flt(kwargs.pending_qty) < 0:
frappe.throw(_("Pending quantity cannot be negative."))
if flt(kwargs.process_loss_qty) and flt(kwargs.process_loss_qty) < 0:
frappe.throw(_("Process loss quantity cannot be negative."))
if flt(kwargs.pending_qty) and flt(kwargs.pending_qty) > self.for_quantity:
frappe.throw(_("Pending quantity cannot be greater than the for quantity."))
self.pending_qty = flt(kwargs.pending_qty)
self.process_loss_qty = flt(kwargs.process_loss_qty)
if kwargs.end_time:
self.add_time_logs(
to_time=kwargs.end_time,
completed_qty=kwargs.qty,

View File

@@ -721,6 +721,7 @@ class TestJobCard(ERPNextTestSuite):
)
jc.time_logs[0].completed_qty = 8
jc.pending_qty = 0.0
jc.save()
jc.submit()

View File

@@ -167,18 +167,19 @@ class WorkOrder(Document):
self.set_onload("backflush_raw_materials_based_on", based_on)
def show_create_job_card_button(self):
operation_details = frappe._dict(
frappe.get_all(
"Job Card",
fields=["operation", {"SUM": "for_quantity"}],
filters={"docstatus": ("<", 2), "work_order": self.name},
as_list=1,
group_by="operation_id",
)
jc_doctype = frappe.qb.DocType("Job Card")
query = (
frappe.qb.from_(jc_doctype)
.select(jc_doctype.operation_id, Sum(jc_doctype.for_quantity - IfNull(jc_doctype.pending_qty, 0)))
.where((jc_doctype.docstatus < 2) & (jc_doctype.work_order == self.name))
.groupby(jc_doctype.operation_id)
)
operation_details = query.run(as_list=1)
operation_details = frappe._dict(operation_details)
for d in self.operations:
job_card_qty = self.qty - flt(operation_details.get(d.operation))
job_card_qty = self.qty - flt(operation_details.get(d.name))
if job_card_qty > 0:
return True

View File

@@ -1,5 +1,6 @@
{
"actions": [],
"allow_bulk_edit": 1,
"creation": "2025-04-09 12:12:19.824560",
"doctype": "DocType",
"editable_grid": 1,
@@ -10,6 +11,7 @@
"status",
"completed_qty",
"process_loss_qty",
"pending_qty",
"column_break_4",
"bom",
"workstation_type",
@@ -301,13 +303,20 @@
"fieldname": "quality_inspection_required",
"fieldtype": "Check",
"label": "Quality Inspection Required"
},
{
"fieldname": "pending_qty",
"fieldtype": "Float",
"label": "Pending Qty",
"no_copy": 1,
"read_only": 1
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2026-03-30 17:20:08.874381",
"modified": "2026-05-20 13:01:21.827200",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order Operation",

View File

@@ -32,6 +32,7 @@ class WorkOrderOperation(Document):
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
pending_qty: DF.Float
planned_end_time: DF.Datetime | None
planned_operating_cost: DF.Currency
planned_start_time: DF.Datetime | None