Ejemplo n.º 1
0
    def test_make_item_variant(self):
        frappe.delete_doc_if_exists("Item", "_Test Variant Item-L", force=1)

        variant = create_variant("_Test Variant Item", {"Test Size": "Large"})
        variant.save()

        # doing it again should raise error
        variant = create_variant("_Test Variant Item", {"Test Size": "Large"})
        variant.item_code = "_Test Variant Item-L-duplicate"
        self.assertRaises(ItemVariantExistsError, variant.save)
Ejemplo n.º 2
0
def make_item_variant():
    if not frappe.db.exists("Item", "_Test Variant Item-S"):
        variant = create_variant("_Test Variant Item",
                                 """{"Test Size": "Small"}""")
        variant.item_code = "_Test Variant Item-S"
        variant.item_name = "_Test Variant Item-S"
        variant.save()
Ejemplo n.º 3
0
    def test_item_attribute_change_after_variant(self):
        frappe.delete_doc_if_exists("Item", "_Test Variant Item-L", force=1)

        variant = create_variant("_Test Variant Item", {"Test Size": "Large"})
        variant.save()

        attribute = frappe.get_doc('Item Attribute', 'Test Size')
        attribute.item_attribute_values = []

        # reset flags
        frappe.flags.attribute_values = None

        self.assertRaises(InvalidItemAttributeValueError, attribute.save)
        frappe.db.rollback()
Ejemplo n.º 4
0
    def test_copy_fields_from_template_to_variants(self):
        frappe.delete_doc_if_exists("Item", "_Test Variant Item-XL", force=1)

        fields = [{
            'field_name': 'item_group'
        }, {
            'field_name': 'is_stock_item'
        }]
        allow_fields = [d.get('field_name') for d in fields]
        set_item_variant_settings(fields)

        if not frappe.db.get_value('Item Attribute Value', {
                'parent': 'Test Size',
                'attribute_value': 'Extra Large'
        }, 'name'):
            item_attribute = frappe.get_doc('Item Attribute', 'Test Size')
            item_attribute.append('item_attribute_values', {
                'attribute_value': 'Extra Large',
                'abbr': 'XL'
            })
            item_attribute.save()

        template = frappe.get_doc('Item', '_Test Variant Item')
        template.item_group = "_Test Item Group D"
        template.save()

        variant = create_variant("_Test Variant Item",
                                 {"Test Size": "Extra Large"})
        variant.item_code = "_Test Variant Item-XL"
        variant.item_name = "_Test Variant Item-XL"
        variant.save()

        variant = frappe.get_doc('Item', '_Test Variant Item-XL')
        for fieldname in allow_fields:
            self.assertEqual(template.get(fieldname), variant.get(fieldname))

        template = frappe.get_doc('Item', '_Test Variant Item')
        template.item_group = "_Test Item Group Desktops"
        template.save()
Ejemplo n.º 5
0
    def test_make_item_variant_with_numeric_values(self):
        # cleanup
        for d in frappe.db.get_all(
                'Item', filters={'variant_of': '_Test Numeric Template Item'}):
            frappe.delete_doc_if_exists("Item", d.name)

        frappe.delete_doc_if_exists("Item", "_Test Numeric Template Item")
        frappe.delete_doc_if_exists("Item Attribute", "Test Item Length")

        frappe.db.sql('''delete from `tabItem Variant Attribute`
			where attribute="Test Item Length"''')

        frappe.flags.attribute_values = None

        # make item attribute
        frappe.get_doc({
            "doctype": "Item Attribute",
            "attribute_name": "Test Item Length",
            "numeric_values": 1,
            "from_range": 0.0,
            "to_range": 100.0,
            "increment": 0.5
        }).insert()

        # make template item
        make_item(
            "_Test Numeric Template Item", {
                "attributes": [{
                    "attribute": "Test Size"
                }, {
                    "attribute": "Test Item Length",
                    "numeric_values": 1,
                    "from_range": 0.0,
                    "to_range": 100.0,
                    "increment": 0.5
                }],
                "item_defaults": [{
                    "default_warehouse": "_Test Warehouse - _TC",
                    "company": "_Test Company"
                }],
                "has_variants":
                1
            })

        variant = create_variant("_Test Numeric Template Item", {
            "Test Size": "Large",
            "Test Item Length": 1.1
        })
        self.assertEqual(variant.item_code,
                         "_Test Numeric Template Item-L-1.1")
        variant.item_code = "_Test Numeric Variant-L-1.1"
        variant.item_name = "_Test Numeric Variant Large 1.1m"
        self.assertRaises(InvalidItemAttributeValueError, variant.save)

        variant = create_variant("_Test Numeric Template Item", {
            "Test Size": "Large",
            "Test Item Length": 1.5
        })
        self.assertEqual(variant.item_code,
                         "_Test Numeric Template Item-L-1.5")
        variant.item_code = "_Test Numeric Variant-L-1.5"
        variant.item_name = "_Test Numeric Variant Large 1.5m"
        variant.save()