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
This commit is contained in:
parent
9520215e2b
commit
469bb8d977
@ -26,8 +26,9 @@ frappe.ui.form.on('Job Card', {
|
|||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frappe.flags.pause_job = 0;
|
frappe.flags.pause_job = 0;
|
||||||
frappe.flags.resume_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 to_request = frm.doc.for_quantity > frm.doc.transferred_qty;
|
||||||
let excess_transfer_allowed = frm.doc.__onload.job_card_excess_transfer;
|
let excess_transfer_allowed = frm.doc.__onload.job_card_excess_transfer;
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -1,22 +1,38 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import random_string
|
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.work_order.test_work_order import make_wo_order_test_record
|
||||||
from erpnext.manufacturing.doctype.workstation.test_workstation import make_workstation
|
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):
|
class TestJobCard(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
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):
|
def tearDown(self):
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
@ -96,3 +112,84 @@ class TestJobCard(unittest.TestCase):
|
|||||||
"employee": employee,
|
"employee": employee,
|
||||||
})
|
})
|
||||||
self.assertRaises(OverlapError, jc2.save)
|
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")
|
@ -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
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
@ -814,6 +810,7 @@ def make_wo_order_test_record(**args):
|
|||||||
wo_order.get_items_and_operations_from_bom()
|
wo_order.get_items_and_operations_from_bom()
|
||||||
wo_order.sales_order = args.sales_order or None
|
wo_order.sales_order = args.sales_order or None
|
||||||
wo_order.planned_start_date = args.planned_start_date or now()
|
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:
|
if args.source_warehouse:
|
||||||
for item in wo_order.get("required_items"):
|
for item in wo_order.get("required_items"):
|
||||||
|
Loading…
Reference in New Issue
Block a user