2017-07-04 10:13:02 +00:00
|
|
|
import json
|
|
|
|
import unittest
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
import frappe
|
|
|
|
|
2017-07-04 10:13:02 +00:00
|
|
|
from erpnext.controllers.item_variant import copy_attributes_to_variant, make_variant_item_code
|
2021-09-02 11:14:59 +00:00
|
|
|
from erpnext.stock.doctype.item.test_item import set_item_variant_settings
|
|
|
|
from erpnext.stock.doctype.quality_inspection.test_quality_inspection import (
|
|
|
|
create_quality_inspection_parameter,
|
|
|
|
)
|
2017-07-04 10:13:02 +00:00
|
|
|
|
|
|
|
|
2018-02-22 05:33:48 +00:00
|
|
|
class TestItemVariant(unittest.TestCase):
|
|
|
|
def test_tables_in_template_copied_to_variant(self):
|
2022-03-28 13:22:46 +00:00
|
|
|
fields = [{"field_name": "quality_inspection_template"}]
|
2018-02-22 05:33:48 +00:00
|
|
|
set_item_variant_settings(fields)
|
|
|
|
variant = make_item_variant()
|
|
|
|
self.assertEqual(variant.get("quality_inspection_template"), "_Test QC Template")
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2017-07-04 10:13:02 +00:00
|
|
|
def create_variant_with_tables(item, args):
|
2021-11-04 14:18:32 +00:00
|
|
|
if isinstance(args, str):
|
2017-07-04 10:13:02 +00:00
|
|
|
args = json.loads(args)
|
|
|
|
|
2018-02-22 05:33:48 +00:00
|
|
|
qc_name = make_quality_inspection_template()
|
2017-07-04 10:13:02 +00:00
|
|
|
template = frappe.get_doc("Item", item)
|
2018-02-22 05:33:48 +00:00
|
|
|
template.quality_inspection_template = qc_name
|
|
|
|
template.save()
|
|
|
|
|
2017-07-04 10:13:02 +00:00
|
|
|
variant = frappe.new_doc("Item")
|
2022-03-28 13:22:46 +00:00
|
|
|
variant.variant_based_on = "Item Attribute"
|
2017-07-04 10:13:02 +00:00
|
|
|
variant_attributes = []
|
|
|
|
|
|
|
|
for d in template.attributes:
|
2022-03-28 13:22:46 +00:00
|
|
|
variant_attributes.append({"attribute": d.attribute, "attribute_value": args.get(d.attribute)})
|
2017-07-04 10:13:02 +00:00
|
|
|
|
|
|
|
variant.set("attributes", variant_attributes)
|
|
|
|
copy_attributes_to_variant(template, variant)
|
|
|
|
make_variant_item_code(template.item_code, template.item_name, variant)
|
|
|
|
|
|
|
|
return variant
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2017-07-04 10:13:02 +00:00
|
|
|
def make_item_variant():
|
2019-04-10 12:25:59 +00:00
|
|
|
frappe.delete_doc_if_exists("Item", "_Test Variant Item-XSL", force=1)
|
|
|
|
variant = create_variant_with_tables("_Test Variant Item", '{"Test Size": "Extra Small"}')
|
|
|
|
variant.item_code = "_Test Variant Item-XSL"
|
|
|
|
variant.item_name = "_Test Variant Item-XSL"
|
2017-07-04 10:13:02 +00:00
|
|
|
variant.save()
|
|
|
|
return variant
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2018-02-22 05:33:48 +00:00
|
|
|
def make_quality_inspection_template():
|
|
|
|
qc_template = "_Test QC Template"
|
|
|
|
if frappe.db.exists("Quality Inspection Template", qc_template):
|
|
|
|
return qc_template
|
2017-07-04 10:13:02 +00:00
|
|
|
|
2018-02-22 05:33:48 +00:00
|
|
|
qc = frappe.new_doc("Quality Inspection Template")
|
|
|
|
qc.quality_inspection_template_name = qc_template
|
2021-01-04 05:40:04 +00:00
|
|
|
|
|
|
|
create_quality_inspection_parameter("Moisture")
|
2022-03-28 13:22:46 +00:00
|
|
|
qc.append(
|
|
|
|
"item_quality_inspection_parameter",
|
|
|
|
{
|
|
|
|
"specification": "Moisture",
|
|
|
|
"value": "< 5%",
|
|
|
|
},
|
|
|
|
)
|
2018-02-22 05:33:48 +00:00
|
|
|
|
|
|
|
qc.insert()
|
|
|
|
return qc.name
|