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:
Ankush Menat 2021-09-09 12:24:23 +05:30 committed by GitHub
parent 9670490a1d
commit 678335f8ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 48 deletions

View File

@ -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:

View File

@ -8,23 +8,23 @@ 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:
bom, bom_item = data
work_order = make_wo_order_test_record(item=bom_item, qty=1, bom_no=bom)
job_cards = frappe.get_all('Job Card', job_cards = frappe.get_all('Job Card',
filters = {'work_order': work_order.name}, fields = ["operation_id", "name"]) filters = {'work_order': self.work_order.name}, fields = ["operation_id", "name"])
if job_cards: if job_cards:
job_card = job_cards[0] job_card = job_cards[0]
@ -38,16 +38,8 @@ class TestJobCard(unittest.TestCase):
frappe.delete_doc("Job Card", d.name) 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',
{'docstatus': 1, 'with_operations': 1, 'company': '_Test Company'}, ['name', 'item'])
if data:
bom, bom_item = data
work_order = make_wo_order_test_record(item=bom_item, qty=1, bom_no=bom)
job_cards = frappe.get_all('Job Card', job_cards = frappe.get_all('Job Card',
filters = {'work_order': work_order.name}, filters = {'work_order': self.work_order.name},
fields = ["operation_id", "workstation", "name", "for_quantity"]) fields = ["operation_id", "workstation", "name", "for_quantity"])
job_card = job_cards[0] job_card = job_cards[0]
@ -76,3 +68,31 @@ class TestJobCard(unittest.TestCase):
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)