def execute():
    for warehouse, user in dataent.db.sql(
            """select parent, user from `tabWarehouse User`"""):
        dataent.permissions.add_user_permission("Warehouse", warehouse, user)

    dataent.delete_doc_if_exists("DocType", "Warehouse User")
    dataent.reload_doc("stock", "doctype", "warehouse")
	def test_max_continuous_leaves(self):
		employee = get_employee()
		leave_period = get_leave_period()
		dataent.delete_doc_if_exists("Leave Type", "Test Leave Type", force=1)
		leave_type = dataent.get_doc(dict(
			leave_type_name = 'Test Leave Type',
			doctype = 'Leave Type',
			max_leaves_allowed = 15,
			max_continuous_days_allowed = 3
		)).insert()

		date = add_days(nowdate(), -7)

		allocate_leaves(employee, leave_period, leave_type.name, 10)

		leave_application = dataent.get_doc(dict(
			doctype = 'Leave Application',
			employee = employee.name,
			leave_type = leave_type.name,
			from_date = date,
			to_date = add_days(date, 4),
			company = "_Test Company",
			docstatus = 1,
            status = "Approved"
		))

		self.assertRaises(dataent.ValidationError, leave_application.insert)
Exemple #3
0
def make_item_variant():
    dataent.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"
    variant.save()
    return variant
Exemple #4
0
def execute():
    dataent.delete_doc_if_exists("DocType", "BOM Replace Tool")

    dataent.reload_doctype("BOM")
    dataent.db.sql(
        "update tabBOM set conversion_rate=1 where conversion_rate is null or conversion_rate=0"
    )
    dataent.db.sql(
        "update tabBOM set set_rate_of_sub_assembly_item_based_on_bom=1")
Exemple #5
0
    def test_make_item_variant(self):
        dataent.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)
Exemple #6
0
	def test_make_customer(self):
		from epaas.crm.doctype.lead.lead import make_customer

		dataent.delete_doc_if_exists("Customer", "_Test Lead")

		customer = make_customer("_T-Lead-00001")
		self.assertEqual(customer.doctype, "Customer")
		self.assertEqual(customer.lead_name, "_T-Lead-00001")

		customer.company = "_Test Company"
		customer.customer_group = "_Test Customer Group"
		customer.insert()
Exemple #7
0
    def test_mandatory(self):
        dataent.delete_doc_if_exists("User", "*****@*****.**")

        d = dataent.get_doc({
            "doctype": "User",
            "email": "*****@*****.**",
        })
        self.assertRaises(dataent.MandatoryError, d.insert)

        d.set("first_name", "Test Mandatory")
        d.insert()
        self.assertEqual(dataent.db.get_value("User", d.name), d.name)
	def insert_custom_field(self):
		dataent.delete_doc_if_exists("Custom Field", "Event-test_custom_field")
		dataent.get_doc({
			"doctype": "Custom Field",
			"dt": "Event",
			"label": "Test Custom Field",
			"description": "A Custom Field for Testing",
			"fieldtype": "Select",
			"in_list_view": 1,
			"options": "\nCustom 1\nCustom 2\nCustom 3",
			"default": "Custom 3",
			"insert_after": dataent.get_meta('Event').fields[-1].fieldname
		}).insert()
Exemple #9
0
    def test_item_attribute_change_after_variant(self):
        dataent.delete_doc_if_exists("Item", "_Test Variant Item-L", force=1)

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

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

        # reset flags
        dataent.flags.attribute_values = None

        self.assertRaises(InvalidItemAttributeValueError, attribute.save)
        dataent.db.rollback()
Exemple #10
0
	def test_cannot_create_direct(self):
		dataent.delete_doc_if_exists("Serial No", "_TCSER0001")

		sr = dataent.new_doc("Serial No")
		sr.item_code = "_Test Serialized Item"
		sr.warehouse = "_Test Warehouse - _TC"
		sr.serial_no = "_TCSER0001"
		sr.purchase_rate = 10
		self.assertRaises(SerialNoCannotCreateDirectError, sr.insert)

		sr.warehouse = None
		sr.insert()
		self.assertTrue(sr.name)

		sr.warehouse = "_Test Warehouse - _TC"
		self.assertTrue(SerialNoCannotCannotChangeError, sr.save)
	def test_applicable_after(self):
		employee = get_employee()
		leave_period = get_leave_period()
		dataent.delete_doc_if_exists("Leave Type", "Test Leave Type", force=1)
		leave_type = dataent.get_doc(dict(
			leave_type_name = 'Test Leave Type',
			doctype = 'Leave Type',
			applicable_after = 15
		)).insert()
		date = add_days(nowdate(), -7)
		dataent.db.set_value('Employee', employee.name, "date_of_joining", date)
		allocate_leaves(employee, leave_period, leave_type.name, 10)

		leave_application = dataent.get_doc(dict(
			doctype = 'Leave Application',
			employee = employee.name,
			leave_type = leave_type.name,
			from_date = date,
			to_date = add_days(date, 4),
			company = "_Test Company",
			docstatus = 1,
            status = "Approved"
		))

		self.assertRaises(dataent.ValidationError, leave_application.insert)

		dataent.delete_doc_if_exists("Leave Type", "Test Leave Type 1", force=1)
		leave_type_1 = dataent.get_doc(dict(
			leave_type_name = 'Test Leave Type 1',
			doctype = 'Leave Type'
		)).insert()

		allocate_leaves(employee, leave_period, leave_type_1.name, 10)

		leave_application = dataent.get_doc(dict(
		doctype = 'Leave Application',
			employee = employee.name,
			leave_type = leave_type_1.name,
			from_date = date,
			to_date = add_days(date, 4),
			company = "_Test Company",
			docstatus = 1,
            status = "Approved"
		))

		self.assertTrue(leave_application.insert())
		dataent.db.set_value('Employee', employee.name, "date_of_joining", "2010-01-01")
Exemple #12
0
    def test_pricing_rule_with_margin_and_discount(self):
        dataent.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule')
        make_pricing_rule(selling=1,
                          margin_type="Percentage",
                          margin_rate_or_amount=10,
                          discount_percentage=10)
        si = create_sales_invoice(do_not_save=True)
        si.items[0].price_list_rate = 1000
        si.payment_schedule = []
        si.insert(ignore_permissions=True)

        item = si.items[0]
        self.assertEquals(item.margin_rate_or_amount, 10)
        self.assertEquals(item.rate_with_margin, 1100)
        self.assertEqual(item.discount_percentage, 10)
        self.assertEquals(item.discount_amount, 110)
        self.assertEquals(item.rate, 990)
Exemple #13
0
    def test_link_validation(self):
        dataent.delete_doc_if_exists("User",
                                     "*****@*****.**")

        d = dataent.get_doc({
            "doctype": "User",
            "email": "*****@*****.**",
            "first_name": "Link Validation",
            "roles": [{
                "role": "ABC"
            }]
        })
        self.assertRaises(dataent.LinkValidationError, d.insert)

        d.roles = []
        d.append("roles", {"role": "System Manager"})
        d.insert()

        self.assertEqual(dataent.db.get_value("User", d.name), d.name)
def execute():
    old_formats = ("Sales Invoice", "Sales Invoice Spartan",
                   "Sales Invoice Modern", "Sales Invoice Classic",
                   "Sales Order Spartan", "Sales Order Modern",
                   "Sales Order Classic", "Purchase Order Spartan",
                   "Purchase Order Modern", "Purchase Order Classic",
                   "Quotation Spartan", "Quotation Modern",
                   "Quotation Classic", "Delivery Note Spartan",
                   "Delivery Note Modern", "Delivery Note Classic")

    for fmt in old_formats:
        # update property setter
        for ps in dataent.db.sql_list(
                """select name from `tabProperty Setter`
			where property='default_print_format' and value=%s""", fmt):
            ps = dataent.get_doc("Property Setter", ps)
            ps.value = "Standard"
            ps.save(ignore_permissions=True)

        dataent.delete_doc_if_exists("Print Format", fmt)
Exemple #15
0
    def test_copy_fields_from_template_to_variants(self):
        dataent.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 dataent.db.get_value('Item Attribute Value', {
                'parent': 'Test Size',
                'attribute_value': 'Extra Large'
        }, 'name'):
            item_attribute = dataent.get_doc('Item Attribute', 'Test Size')
            item_attribute.append('item_attribute_values', {
                'attribute_value': 'Extra Large',
                'abbr': 'XL'
            })
            item_attribute.save()

        template = dataent.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 = dataent.get_doc('Item', '_Test Variant Item-XL')
        for fieldname in allow_fields:
            self.assertEqual(template.get(fieldname), variant.get(fieldname))

        template = dataent.get_doc('Item', '_Test Variant Item')
        template.item_group = "_Test Item Group Desktops"
        template.save()
def execute():
    dataent.reload_doc("buying", "doctype", "request_for_quotation_supplier")
    dataent.reload_doc("buying", "doctype", "request_for_quotation_item")
    dataent.reload_doc("buying", "doctype", "request_for_quotation")
    dataent.reload_doc("projects", "doctype", "timesheet")

    for role in ('Customer', 'Supplier'):
        dataent.db.sql(
            '''delete from `tabHas Role`
			where role=%s and parent in ("Administrator", "Guest")''', role)

        if not dataent.db.sql('select name from `tabHas Role` where role=%s',
                              role):

            # delete DocPerm
            for doctype in dataent.db.sql(
                    'select parent from tabDocPerm where role=%s', role):
                d = dataent.get_doc("DocType", doctype[0])
                d.permissions = [p for p in d.permissions if p.role != role]
                d.save()

            # delete Role
            dataent.delete_doc_if_exists('Role', role)
Exemple #17
0
    def test_make_supplier_quotation_with_special_characters(self):
        from epaas.buying.doctype.request_for_quotation.request_for_quotation import make_supplier_quotation

        dataent.delete_doc_if_exists("Supplier", "_Test Supplier '1", force=1)
        supplier = dataent.new_doc("Supplier")
        supplier.supplier_name = "_Test Supplier '1"
        supplier.supplier_group = "_Test Supplier Group"
        supplier.insert()

        rfq = make_request_for_quotation(supplier_wt_appos)

        sq = make_supplier_quotation(rfq.name,
                                     supplier_wt_appos[0].get("supplier"))
        sq.submit()

        dataent.form_dict = dataent.local("form_dict")
        dataent.form_dict.name = rfq.name

        self.assertEqual(
            check_supplier_has_docname_access(
                supplier_wt_appos[0].get('supplier')), True)

        # reset form_dict
        dataent.form_dict.name = None
Exemple #18
0
def execute():
    dataent.delete_doc_if_exists('Page', 'bom-browser')
Exemple #19
0
    def test_make_item_variant_with_numeric_values(self):
        # cleanup
        for d in dataent.db.get_all(
                'Item', filters={'variant_of': '_Test Numeric Template Item'}):
            dataent.delete_doc_if_exists("Item", d.name)

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

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

        dataent.flags.attribute_values = None

        # make item attribute
        dataent.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()
Exemple #20
0
def execute():
        dataent.delete_doc_if_exists("DocType", "User Permission for Page and Report")