fix: not allow to transfer excess materials against the job card

This commit is contained in:
Rohit Waghchaure 2023-05-04 18:15:25 +05:30
parent 3993bfd510
commit 8167b24219
2 changed files with 55 additions and 0 deletions

View File

@ -272,6 +272,42 @@ class TestJobCard(FrappeTestCase):
transfer_entry_2.insert()
self.assertRaises(JobCardOverTransferError, transfer_entry_2.submit)
@change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0})
def test_job_card_excess_material_transfer_with_no_reference(self):
self.transfer_material_against = "Job Card"
self.source_warehouse = "Stores - _TC"
self.generate_required_stock(self.work_order)
job_card_name = frappe.db.get_value("Job Card", {"work_order": self.work_order.name})
# fully transfer both RMs
transfer_entry_1 = make_stock_entry_from_jc(job_card_name)
row = transfer_entry_1.items[0]
# Add new row without reference of the job card item
transfer_entry_1.append(
"items",
{
"item_code": row.item_code,
"item_name": row.item_name,
"item_group": row.item_group,
"qty": row.qty,
"uom": row.uom,
"conversion_factor": row.conversion_factor,
"stock_uom": row.stock_uom,
"basic_rate": row.basic_rate,
"basic_amount": row.basic_amount,
"expense_account": row.expense_account,
"cost_center": row.cost_center,
"s_warehouse": row.s_warehouse,
"t_warehouse": row.t_warehouse,
},
)
self.assertRaises(frappe.ValidationError, transfer_entry_1.insert)
def test_job_card_partial_material_transfer(self):
"Test partial material transfer against Job Card"
self.transfer_material_against = "Job Card"

View File

@ -127,6 +127,7 @@ class StockEntry(StockController):
self.validate_fg_completed_qty()
self.validate_difference_account()
self.set_job_card_data()
self.validate_job_card_item()
self.set_purpose_for_stock_entry()
self.clean_serial_nos()
self.validate_duplicate_serial_no()
@ -211,6 +212,24 @@ class StockEntry(StockController):
self.from_bom = 1
self.bom_no = data.bom_no
def validate_job_card_item(self):
if not self.job_card:
return
if cint(frappe.db.get_single_value("Manufacturing Settings", "job_card_excess_transfer")):
return
for row in self.items:
if row.job_card_item:
continue
msg = f"""Row #{0}: The job card item reference
is missing. Kindly create the stock entry
from the job card. If you have added the row manually
then you won't be able to add job card item reference."""
frappe.throw(_(msg))
def validate_work_order_status(self):
pro_doc = frappe.get_doc("Work Order", self.work_order)
if pro_doc.status == "Completed":