test: Work Order Material Transfer against Job Card
- Tests for multiple items transfer and excess transfer against JC
- Remove unused __future__ imports
- Changed Copyright year
- Sider: (js) Added space before if
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.js b/erpnext/manufacturing/doctype/job_card/job_card.js
index 9b8f81b..35be388 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.js
+++ b/erpnext/manufacturing/doctype/job_card/job_card.js
@@ -26,8 +26,9 @@
refresh: function(frm) {
frappe.flags.pause_job = 0;
frappe.flags.resume_job = 0;
+ let has_items = frm.doc.items && frm.doc.items.length;
- if(!frm.doc.__islocal && frm.doc.items && frm.doc.items.length && frm.doc.docstatus < 2) {
+ if (!frm.doc.__islocal && has_items && frm.doc.docstatus < 2) {
let to_request = frm.doc.for_quantity > frm.doc.transferred_qty;
let excess_transfer_allowed = frm.doc.__onload.job_card_excess_transfer;
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py
index 1906bf6..3209546 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card.py
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
+# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
-
-from __future__ import unicode_literals
-
import datetime
import json
diff --git a/erpnext/manufacturing/doctype/job_card/test_job_card.py b/erpnext/manufacturing/doctype/job_card/test_job_card.py
index 80295bb..57336e1 100644
--- a/erpnext/manufacturing/doctype/job_card/test_job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/test_job_card.py
@@ -1,22 +1,38 @@
# -*- coding: utf-8 -*-
-# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
+# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
-from __future__ import unicode_literals
-
import unittest
import frappe
from frappe.utils import random_string
-from erpnext.manufacturing.doctype.job_card.job_card import OperationMismatchError, OverlapError
+from erpnext.manufacturing.doctype.job_card.job_card import (
+ make_stock_entry as make_stock_entry_from_jc,
+ OperationMismatchError,
+ OverlapError
+)
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
from erpnext.manufacturing.doctype.workstation.test_workstation import make_workstation
+from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
class TestJobCard(unittest.TestCase):
def setUp(self):
- self.work_order = make_wo_order_test_record(item="_Test FG Item 2", qty=2)
+ transfer_material_against, source_warehouse = None, None
+ tests_that_transfer_against_jc = ("test_job_card_multiple_materials_transfer",
+ "test_job_card_excess_material_transfer")
+
+ if self._testMethodName in tests_that_transfer_against_jc:
+ transfer_material_against = "Job Card"
+ source_warehouse = "Stores - _TC"
+
+ self.work_order = make_wo_order_test_record(
+ item="_Test FG Item 2",
+ qty=2,
+ transfer_material_against=transfer_material_against,
+ source_warehouse=source_warehouse
+ )
def tearDown(self):
frappe.db.rollback()
@@ -96,3 +112,84 @@
"employee": employee,
})
self.assertRaises(OverlapError, jc2.save)
+
+ def test_job_card_multiple_materials_transfer(self):
+ "Test transferring RMs separately against Job Card with multiple RMs."
+ make_stock_entry(
+ item_code="_Test Item",
+ target="Stores - _TC",
+ qty=10,
+ basic_rate=100
+ )
+ make_stock_entry(
+ item_code="_Test Item Home Desktop Manufactured",
+ target="Stores - _TC",
+ qty=6,
+ basic_rate=100
+ )
+
+ job_card_name = frappe.db.get_value("Job Card", {'work_order': self.work_order.name})
+ job_card = frappe.get_doc("Job Card", job_card_name)
+
+ transfer_entry_1 = make_stock_entry_from_jc(job_card_name)
+ del transfer_entry_1.items[1] # transfer only 1 of 2 RMs
+ transfer_entry_1.insert()
+ transfer_entry_1.submit()
+
+ job_card.reload()
+
+ self.assertEqual(transfer_entry_1.fg_completed_qty, 2)
+ self.assertEqual(job_card.transferred_qty, 2)
+
+ # transfer second RM
+ transfer_entry_2 = make_stock_entry_from_jc(job_card_name)
+ del transfer_entry_2.items[0]
+ transfer_entry_2.insert()
+ transfer_entry_2.submit()
+
+ # 'For Quantity' here will be 0 since
+ # transfer was made for 2 fg qty in first transfer Stock Entry
+ self.assertEqual(transfer_entry_2.fg_completed_qty, 0)
+
+ def test_job_card_excess_material_transfer(self):
+ "Test transferring more than required RM against Job Card."
+ make_stock_entry(item_code="_Test Item", target="Stores - _TC",
+ qty=25, basic_rate=100)
+ make_stock_entry(item_code="_Test Item Home Desktop Manufactured",
+ target="Stores - _TC", qty=15, basic_rate=100)
+
+ job_card_name = frappe.db.get_value("Job Card", {'work_order': self.work_order.name})
+ job_card = frappe.get_doc("Job Card", job_card_name)
+
+ # fully transfer both RMs
+ transfer_entry_1 = make_stock_entry_from_jc(job_card_name)
+ transfer_entry_1.insert()
+ transfer_entry_1.submit()
+
+ # transfer extra qty of both RM due to previously damaged RM
+ transfer_entry_2 = make_stock_entry_from_jc(job_card_name)
+ # deliberately change 'For Quantity'
+ transfer_entry_2.fg_completed_qty = 1
+ transfer_entry_2.items[0].qty = 5
+ transfer_entry_2.items[1].qty = 3
+ transfer_entry_2.insert()
+ transfer_entry_2.submit()
+
+ job_card.reload()
+ self.assertGreater(job_card.transferred_qty, job_card.for_quantity)
+
+ # Check if 'For Quantity' is negative
+ # as 'transferred_qty' > Qty to Manufacture
+ transfer_entry_3 = make_stock_entry_from_jc(job_card_name)
+ self.assertEqual(transfer_entry_3.fg_completed_qty, 0)
+
+ job_card.append("time_logs", {
+ "from_time": "2021-01-01 00:01:00",
+ "to_time": "2021-01-01 06:00:00",
+ "completed_qty": 2
+ })
+ job_card.save()
+ job_card.submit()
+
+ # JC is Completed with excess transfer
+ self.assertEqual(job_card.status, "Completed")
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py
index bb43149..d87b5ec 100644
--- a/erpnext/manufacturing/doctype/work_order/test_work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py
@@ -1,9 +1,5 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
-
-
-from __future__ import unicode_literals
-
import unittest
import frappe
@@ -814,6 +810,7 @@
wo_order.get_items_and_operations_from_bom()
wo_order.sales_order = args.sales_order or None
wo_order.planned_start_date = args.planned_start_date or now()
+ wo_order.transfer_material_against = args.transfer_material_against or "Work Order"
if args.source_warehouse:
for item in wo_order.get("required_items"):