[Enhance] Quality Inspection Template (#12988)

* [Enhance] Quality Inspection Template

* Test case and patch

* Update make_quality_inspection_template.py
This commit is contained in:
rohitwaghchaure
2018-02-22 11:03:48 +05:30
committed by Nabin Hait
parent 79756c44c9
commit 4e8fdf7b3f
25 changed files with 678 additions and 93 deletions

View File

@@ -320,14 +320,20 @@ class StockController(AccountsController):
elif self.doctype in ["Delivery Note", "Sales Invoice"]:
inspection_required_fieldname = "inspection_required_before_delivery"
if not inspection_required_fieldname or \
(self.doctype in ["Sales Invoice", "Purchase Invoice"] and not self.update_stock):
if ((not inspection_required_fieldname and self.doctype != "Stock Entry") or
(self.doctype == "Stock Entry" and not self.inspection_required) or
(self.doctype in ["Sales Invoice", "Purchase Invoice"] and not self.update_stock)):
return
for d in self.get('items'):
if (frappe.db.get_value("Item", d.item_code, inspection_required_fieldname)
and not d.quality_inspection):
raise_exception = False
if (inspection_required_fieldname and not d.quality_inspection and
frappe.db.get_value("Item", d.item_code, inspection_required_fieldname)):
raise_exception = True
elif self.doctype == "Stock Entry" and not d.quality_inspection and d.t_warehouse:
raise_exception = True
if raise_exception:
frappe.msgprint(_("Quality Inspection required for Item {0}").format(d.item_code))
if self.docstatus==1:
raise frappe.ValidationError

View File

@@ -9,15 +9,22 @@ from erpnext.controllers.item_variant import copy_attributes_to_variant, make_va
from six import string_types
class TestItemVariant(unittest.TestCase):
def test_tables_in_template_copied_to_variant(self):
fields = [{'field_name': 'quality_inspection_template'}]
set_item_variant_settings(fields)
variant = make_item_variant()
self.assertEqual(variant.get("quality_inspection_template"), "_Test QC Template")
def create_variant_with_tables(item, args):
if isinstance(args, string_types):
args = json.loads(args)
qc_name = make_quality_inspection_template()
template = frappe.get_doc("Item", item)
template.quality_parameters.append({
"specification": "Moisture",
"value": "< 5%",
})
template.quality_inspection_template = qc_name
template.save()
variant = frappe.new_doc("Item")
variant.variant_based_on = 'Item Attribute'
variant_attributes = []
@@ -34,7 +41,6 @@ def create_variant_with_tables(item, args):
return variant
def make_item_variant():
frappe.delete_doc_if_exists("Item", "_Test Variant Item-S", force=1)
variant = create_variant_with_tables("_Test Variant Item", '{"Test Size": "Small"}')
@@ -43,10 +49,17 @@ def make_item_variant():
variant.save()
return variant
def make_quality_inspection_template():
qc_template = "_Test QC Template"
if frappe.db.exists("Quality Inspection Template", qc_template):
return qc_template
class TestItemVariant(unittest.TestCase):
def test_tables_in_template_copied_to_variant(self):
fields = [{'field_name': 'quality_parameters'}]
set_item_variant_settings(fields)
variant = make_item_variant()
self.assertNotEqual(variant.get("quality_parameters"), [])
qc = frappe.new_doc("Quality Inspection Template")
qc.quality_inspection_template_name = qc_template
qc.append('item_quality_inspection_parameter', {
"specification": "Moisture",
"value": "< 5%",
})
qc.insert()
return qc.name