fix: job card overlap unknown column jc.employee
(#27403)
* fix: incorrect query for job card overlap * test: employee overlap in job cards * test: simplify/refactor job card tests
This commit is contained in:
parent
9670490a1d
commit
678335f8ac
@ -91,7 +91,7 @@ class JobCard(Document):
|
|||||||
if args.get("employee"):
|
if args.get("employee"):
|
||||||
# override capacity for employee
|
# override capacity for employee
|
||||||
production_capacity = 1
|
production_capacity = 1
|
||||||
validate_overlap_for = " and jc.employee = %(employee)s "
|
validate_overlap_for = " and jctl.employee = %(employee)s "
|
||||||
|
|
||||||
extra_cond = ''
|
extra_cond = ''
|
||||||
if check_next_available_slot:
|
if check_next_available_slot:
|
||||||
|
@ -8,71 +8,91 @@ 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
|
from erpnext.manufacturing.doctype.job_card.job_card import 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
|
||||||
|
|
||||||
|
|
||||||
class TestJobCard(unittest.TestCase):
|
class TestJobCard(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.work_order = make_wo_order_test_record(item="_Test FG Item 2", qty=2)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_job_card(self):
|
def test_job_card(self):
|
||||||
data = frappe.get_cached_value('BOM',
|
|
||||||
{'docstatus': 1, 'with_operations': 1, 'company': '_Test Company'}, ['name', 'item'])
|
|
||||||
|
|
||||||
if data:
|
job_cards = frappe.get_all('Job Card',
|
||||||
bom, bom_item = data
|
filters = {'work_order': self.work_order.name}, fields = ["operation_id", "name"])
|
||||||
|
|
||||||
work_order = make_wo_order_test_record(item=bom_item, qty=1, bom_no=bom)
|
if job_cards:
|
||||||
|
job_card = job_cards[0]
|
||||||
|
frappe.db.set_value("Job Card", job_card.name, "operation_row_number", job_card.operation_id)
|
||||||
|
|
||||||
job_cards = frappe.get_all('Job Card',
|
doc = frappe.get_doc("Job Card", job_card.name)
|
||||||
filters = {'work_order': work_order.name}, fields = ["operation_id", "name"])
|
doc.operation_id = "Test Data"
|
||||||
|
self.assertRaises(OperationMismatchError, doc.save)
|
||||||
|
|
||||||
if job_cards:
|
for d in job_cards:
|
||||||
job_card = job_cards[0]
|
frappe.delete_doc("Job Card", d.name)
|
||||||
frappe.db.set_value("Job Card", job_card.name, "operation_row_number", job_card.operation_id)
|
|
||||||
|
|
||||||
doc = frappe.get_doc("Job Card", job_card.name)
|
|
||||||
doc.operation_id = "Test Data"
|
|
||||||
self.assertRaises(OperationMismatchError, doc.save)
|
|
||||||
|
|
||||||
for d in job_cards:
|
|
||||||
frappe.delete_doc("Job Card", d.name)
|
|
||||||
|
|
||||||
def test_job_card_with_different_work_station(self):
|
def test_job_card_with_different_work_station(self):
|
||||||
data = frappe.get_cached_value('BOM',
|
job_cards = frappe.get_all('Job Card',
|
||||||
{'docstatus': 1, 'with_operations': 1, 'company': '_Test Company'}, ['name', 'item'])
|
filters = {'work_order': self.work_order.name},
|
||||||
|
fields = ["operation_id", "workstation", "name", "for_quantity"])
|
||||||
|
|
||||||
if data:
|
job_card = job_cards[0]
|
||||||
bom, bom_item = data
|
|
||||||
|
|
||||||
work_order = make_wo_order_test_record(item=bom_item, qty=1, bom_no=bom)
|
if job_card:
|
||||||
|
workstation = frappe.db.get_value("Workstation",
|
||||||
|
{"name": ("not in", [job_card.workstation])}, "name")
|
||||||
|
|
||||||
job_cards = frappe.get_all('Job Card',
|
if not workstation or job_card.workstation == workstation:
|
||||||
filters = {'work_order': work_order.name},
|
workstation = make_workstation(workstation_name=random_string(5)).name
|
||||||
fields = ["operation_id", "workstation", "name", "for_quantity"])
|
|
||||||
|
|
||||||
job_card = job_cards[0]
|
doc = frappe.get_doc("Job Card", job_card.name)
|
||||||
|
doc.workstation = workstation
|
||||||
|
doc.append("time_logs", {
|
||||||
|
"from_time": "2009-01-01 12:06:25",
|
||||||
|
"to_time": "2009-01-01 12:37:25",
|
||||||
|
"time_in_mins": "31.00002",
|
||||||
|
"completed_qty": job_card.for_quantity
|
||||||
|
})
|
||||||
|
doc.submit()
|
||||||
|
|
||||||
if job_card:
|
completed_qty = frappe.db.get_value("Work Order Operation", job_card.operation_id, "completed_qty")
|
||||||
workstation = frappe.db.get_value("Workstation",
|
self.assertEqual(completed_qty, job_card.for_quantity)
|
||||||
{"name": ("not in", [job_card.workstation])}, "name")
|
|
||||||
|
|
||||||
if not workstation or job_card.workstation == workstation:
|
doc.cancel()
|
||||||
workstation = make_workstation(workstation_name=random_string(5)).name
|
|
||||||
|
|
||||||
doc = frappe.get_doc("Job Card", job_card.name)
|
|
||||||
doc.workstation = workstation
|
|
||||||
doc.append("time_logs", {
|
|
||||||
"from_time": "2009-01-01 12:06:25",
|
|
||||||
"to_time": "2009-01-01 12:37:25",
|
|
||||||
"time_in_mins": "31.00002",
|
|
||||||
"completed_qty": job_card.for_quantity
|
|
||||||
})
|
|
||||||
doc.submit()
|
|
||||||
|
|
||||||
completed_qty = frappe.db.get_value("Work Order Operation", job_card.operation_id, "completed_qty")
|
|
||||||
self.assertEqual(completed_qty, job_card.for_quantity)
|
|
||||||
|
|
||||||
doc.cancel()
|
|
||||||
|
|
||||||
for d in job_cards:
|
for d in job_cards:
|
||||||
frappe.delete_doc("Job Card", d.name)
|
frappe.delete_doc("Job Card", d.name)
|
||||||
|
|
||||||
|
def test_job_card_overlap(self):
|
||||||
|
wo2 = make_wo_order_test_record(item="_Test FG Item 2", qty=2)
|
||||||
|
|
||||||
|
jc1_name = frappe.db.get_value("Job Card", {'work_order': self.work_order.name})
|
||||||
|
jc2_name = frappe.db.get_value("Job Card", {'work_order': wo2.name})
|
||||||
|
|
||||||
|
jc1 = frappe.get_doc("Job Card", jc1_name)
|
||||||
|
jc2 = frappe.get_doc("Job Card", jc2_name)
|
||||||
|
|
||||||
|
employee = "_T-Employee-00001" # from test records
|
||||||
|
|
||||||
|
jc1.append("time_logs", {
|
||||||
|
"from_time": "2021-01-01 00:00:00",
|
||||||
|
"to_time": "2021-01-01 08:00:00",
|
||||||
|
"completed_qty": 1,
|
||||||
|
"employee": employee,
|
||||||
|
})
|
||||||
|
jc1.save()
|
||||||
|
|
||||||
|
# add a new entry in same time slice
|
||||||
|
jc2.append("time_logs", {
|
||||||
|
"from_time": "2021-01-01 00:01:00",
|
||||||
|
"to_time": "2021-01-01 06:00:00",
|
||||||
|
"completed_qty": 1,
|
||||||
|
"employee": employee,
|
||||||
|
})
|
||||||
|
self.assertRaises(OverlapError, jc2.save)
|
||||||
|
Loading…
Reference in New Issue
Block a user