示例#1
0
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"}')
	variant.item_code = "_Test Variant Item-S"
	variant.item_name = "_Test Variant Item-S"
	variant.save()
	return variant
	def test_max_continuous_leaves(self):
		employee = get_employee()
		leave_period = get_leave_period()
		frappe.delete_doc_if_exists("Leave Type", "Test Leave Type", force=1)
		leave_type = frappe.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 = frappe.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(frappe.ValidationError, leave_application.insert)
示例#3
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()
def execute():
	# new doctype "Plant Room" added, need to sync model first
	frappe.model.sync.sync_all(verbose=True)

	for name in frappe.get_all("Warehouse", {"warehouse_type": "Plant Room"}):
		warehouse = frappe.get_doc("Warehouse", name)
		doc = frappe.new_doc("Plant Room")
		doc.update({
			"plant_room_name": warehouse.get("warehouse_name"),
			"company": warehouse.get("company"),
		})

		doc.save()

		frappe.db.sql(
			"UPDATE tabPlant SET plant_room=%(plant_room)s WHERE warehouse=%(warehouse)s",
			{
				"plant_room": doc.get("name"),
				"warehouse": warehouse.get("name"),
			}
		)

	frappe.db.sql(
		"DELETE FROM tabWarehouse WHERE warehouse_type=%(warehouse_type)s",
		{
			"warehouse_type": "Plant Room",
		}
	)

	frappe.delete_doc_if_exists("Custom Field", "Warehouse-warehouse_type")
示例#5
0
	def test_make_item_variant(self):
		frappe.delete_doc_if_exists("Item", "_Test Variant Item-L")

		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"})
		self.assertRaises(ItemVariantExistsError, variant.save)
示例#6
0
    def test_mandatory(self):
        frappe.delete_doc_if_exists("User", "*****@*****.**")

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

        d.set("first_name", "Test Mandatory")
        d.insert()
        self.assertEquals(frappe.db.get_value("User", d.name), d.name)
示例#7
0
def clean_sales_team_table():
	query = """SELECT name, parent FROM `tabSales Team` WHERE parenttype = 'Customer' 
	AND parent NOT IN (SELECT name FROM `tabCustomer`) """
	list_of_st = frappe.db.sql(query, as_list=1)
	if list_of_st:
		for steam_lst in list_of_st:
			frappe.delete_doc_if_exists("Sales Team", steam_lst[0])
			frappe.db.commit()
			print ("Deleted Sales Team Data " + steam_lst[0] + " For Customer: " + steam_lst[1])
示例#8
0
def clean_sales_team_table():
    query = """SELECT name, parent FROM `tabSales Team` WHERE parenttype = 'Customer' 
	AND parent NOT IN (SELECT name FROM `tabCustomer`) """
    list_of_st = frappe.db.sql(query, as_list=1)
    if list_of_st:
        for steam_lst in list_of_st:
            frappe.delete_doc_if_exists("Sales Team", steam_lst[0])
            frappe.db.commit()
            print("Deleted Sales Team Data " + steam_lst[0] +
                  " For Customer: " + steam_lst[1])
示例#9
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)
示例#10
0
def whitelabel_patch():
    #delete erpnext welcome page
    frappe.delete_doc_if_exists('Page', 'welcome-to-erpnext', force=1)
    #update Welcome Blog Post
    if frappe.db.exists("Blog Post", "Welcome"):
        frappe.db.set_value("Blog Post", "Welcome", "content", "")
    update_field_label()
    if cint(get_frappe_version()) >= 13 and not frappe.db.get_single_value(
            'Whitelabel Setting', 'ignore_onboard_whitelabel'):
        update_onboard_details()
示例#11
0
def make_holiday_list(name, from_date=getdate()-timedelta(days=10), to_date=getdate(), holiday_dates=None):
    frappe.delete_doc_if_exists("Holiday List", name, force=1)
    doc = frappe.get_doc({
        "doctype": "Holiday List",
        "holiday_list_name": name,
        "from_date": from_date,
        "to_date": to_date,
        "holidays": holiday_dates
    }).insert()
    return doc
示例#12
0
def cleanup(sender=None):
    filters = {}
    if sender:
        filters.update({"sender": sender})

    names = frappe.get_list("Communication", filters=filters, fields=["name"])
    for name in names:
        frappe.delete_doc_if_exists("Communication", name.name)
        frappe.delete_doc_if_exists("Communication Link",
                                    {"parent": name.name})
def remove_test_loan(loan="_Test Loan", keep_dependencies=False):
    try:
        doc = frappe.get_doc("Microfinance Loan", loan)
        if doc.docstatus == 1:
            doc.cancel()
    except frappe.DoesNotExistError:
        pass
    frappe.delete_doc_if_exists("Microfinance Loan", loan, force=True)
    if not keep_dependencies:
        remove_test_loanee("_Test Loanee 1")
示例#14
0
def execute():
    """Add missing Twilio patch.

	While making Twilio as a standaone app, we missed to delete Twilio records from DB through migration. Adding the missing patch.
	"""
    frappe.delete_doc_if_exists("DocType", "Twilio Number Group")
    if twilio_settings_doctype_in_integrations():
        frappe.delete_doc_if_exists("DocType", "Twilio Settings")
        frappe.db.sql("delete from `tabSingles` where `doctype`=%s",
                      "Twilio Settings")
示例#15
0
    def setUp(self):
        frappe.db.sql("""DELETE FROM `tabUser Permission`
			WHERE `user` in (
				'*****@*****.**',
				'*****@*****.**',
				'*****@*****.**')""")
        frappe.delete_doc_if_exists("DocType", "Person")
        frappe.db.sql_ddl("DROP TABLE IF EXISTS `tabPerson`")
        frappe.delete_doc_if_exists("DocType", "Doc A")
        frappe.db.sql_ddl("DROP TABLE IF EXISTS `tabDoc A`")
    def test_attendance_update_for_exclude_holidays(self):
        # Case 2: leave type with 'Include holidays within leaves as leaves' disabled
        frappe.delete_doc_if_exists("Leave Type",
                                    "Test Do Not Include Holidays",
                                    force=1)
        leave_type = frappe.get_doc(
            dict(leave_type_name="Test Do Not Include Holidays",
                 doctype="Leave Type",
                 include_holiday=False)).insert()

        date = getdate()
        make_allocation_record(leave_type=leave_type.name,
                               from_date=get_year_start(date),
                               to_date=get_year_ending(date))

        employee = get_employee()
        first_sunday = get_first_sunday(self.holiday_list)

        # already marked attendance on a holiday should be deleted in this case
        config = {
            "doctype": "Attendance",
            "employee": employee.name,
            "status": "Present"
        }
        attendance_on_holiday = frappe.get_doc(config)
        attendance_on_holiday.attendance_date = first_sunday
        attendance_on_holiday.flags.ignore_validate = True
        attendance_on_holiday.save()

        # already marked attendance on a non-holiday should be updated
        attendance = frappe.get_doc(config)
        attendance.attendance_date = add_days(first_sunday, 3)
        attendance.flags.ignore_validate = True
        attendance.save()

        leave_application = make_leave_application(employee.name, first_sunday,
                                                   add_days(first_sunday, 3),
                                                   leave_type.name,
                                                   employee.company)
        leave_application.reload()

        # holiday should be excluded while marking attendance
        self.assertEqual(leave_application.total_leave_days, 3)
        self.assertEqual(
            frappe.db.count("Attendance",
                            {"leave_application": leave_application.name}), 3)

        # attendance on holiday deleted
        self.assertFalse(
            frappe.db.exists("Attendance", attendance_on_holiday.name))

        # attendance on non-holiday updated
        self.assertEqual(
            frappe.db.get_value("Attendance", attendance.name, "status"),
            "On Leave")
示例#17
0
	def test_earned_leaves_creation(self):

		frappe.db.sql("""delete from `tabLeave Period`""")
		frappe.db.sql("""delete from `tabLeave Policy Assignment`""")
		frappe.db.sql("""delete from `tabLeave Allocation`""")
		frappe.db.sql("""delete from `tabLeave Ledger Entry`""")

		leave_period = get_leave_period()
		employee = get_employee()
		leave_type = "Test Earned Leave Type"
		frappe.delete_doc_if_exists("Leave Type", "Test Earned Leave Type", force=1)
		frappe.get_doc(
			dict(
				leave_type_name=leave_type,
				doctype="Leave Type",
				is_earned_leave=1,
				earned_leave_frequency="Monthly",
				rounding=0.5,
				max_leaves_allowed=6,
			)
		).insert()

		leave_policy = frappe.get_doc(
			{
				"doctype": "Leave Policy",
				"title": "Test Leave Policy",
				"leave_policy_details": [{"leave_type": leave_type, "annual_allocation": 6}],
			}
		).insert()

		data = {
			"assignment_based_on": "Leave Period",
			"leave_policy": leave_policy.name,
			"leave_period": leave_period.name,
		}

		leave_policy_assignments = create_assignment_for_multiple_employees(
			[employee.name], frappe._dict(data)
		)

		from erpnext.hr.utils import allocate_earned_leaves

		i = 0
		while i < 14:
			allocate_earned_leaves()
			i += 1
		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 6)

		# validate earned leaves creation without maximum leaves
		frappe.db.set_value("Leave Type", leave_type, "max_leaves_allowed", 0)
		i = 0
		while i < 6:
			allocate_earned_leaves()
			i += 1
		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 9)
    def test_imports_to_ignore(self):
        frappe.delete_doc_if_exists('Website Theme', 'test-theme')
        theme = frappe.get_doc(
            dict(doctype='Website Theme',
                 theme='test-theme',
                 ignored_apps=[{
                     'app': 'frappe'
                 }])).insert()

        self.assertTrue(
            '@import "frappe/public/scss/website"' not in theme.theme_scss)
示例#19
0
	def test_multiple_pricing_rules(self):
		make_pricing_rule(discount_percentage=20, selling=1, priority=1, apply_multiple_pricing_rules=1,
			title="_Test Pricing Rule 1")
		make_pricing_rule(discount_percentage=10, selling=1, title="_Test Pricing Rule 2", priority=2,
			apply_multiple_pricing_rules=1)
		si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1)
		self.assertEqual(si.items[0].discount_percentage, 30)
		si.delete()

		frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1")
		frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 2")
示例#20
0
def execute():
    frappe.delete_doc_if_exists("DocType", "Tag Category")
    frappe.delete_doc_if_exists("DocType", "Tag Doc Category")

    frappe.reload_doc("desk", "doctype", "tag")
    frappe.reload_doc("desk", "doctype", "tag_link")

    tag_list = []
    tag_links = []
    time = frappe.utils.get_datetime()

    for doctype in frappe.get_list("DocType",
                                   filters={
                                       "istable": 0,
                                       "issingle": 0
                                   }):
        if not frappe.db.count(doctype.name) or not frappe.db.has_column(
                doctype.name, "_user_tags"):
            continue

        for _user_tags in frappe.db.sql(
                "select `name`, `_user_tags` from `tab{0}`".format(
                    doctype.name),
                as_dict=True):
            if not _user_tags.get("_user_tags"):
                continue

            for tag in _user_tags.get("_user_tags").split(
                    ",") if _user_tags.get("_user_tags") else []:
                if not tag:
                    continue

                tag_list.append((tag.strip(), time, time, "Administrator"))

                tag_link_name = frappe.generate_hash(
                    _user_tags.name + tag.strip() + doctype.name, 10)
                tag_links.append((tag_link_name, doctype.name, _user_tags.name,
                                  tag.strip(), time, time, "Administrator"))

    frappe.db.bulk_insert(
        "Tag",
        fields=["name", "creation", "modified", "modified_by"],
        values=set(tag_list),
        ignore_duplicates=True,
    )
    frappe.db.bulk_insert(
        "Tag Link",
        fields=[
            "name", "document_type", "document_name", "tag", "creation",
            "modified", "modified_by"
        ],
        values=set(tag_links),
        ignore_duplicates=True,
    )
def execute():
	obs_items = frappe.db.sql("""
		SELECT it.name, ifnull(it.owner, "Administrator"), it.creation
		FROM `tabItem` it
		WHERE 
			it.variant_of IS NULL
			AND it.has_variants <> 1

			AND ifnull((SELECT count(sod.name) FROM `tabMaterial Request Item` sod WHERE sod.item_code = 
				it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabSupplier Quotation Item` sod WHERE sod.item_code = 
				it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabQuotation Item` sod WHERE sod.item_code = 
				it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabSales Order Item` sod WHERE sod.item_code = 
				it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabSales Invoice Item` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabPurchase Order Item` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabPurchase Invoice Item` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabStock Ledger Entry` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabStock Entry Detail` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabStock Reconciliation Item` sod 
				WHERE sod.item_code = it.name GROUP BY sod.item_code),0) = 0
			
			AND ifnull((SELECT count(sod.name) FROM `tabProduction Order` sod 
				WHERE sod.production_item = it.name GROUP BY sod.production_item),0) = 0
		ORDER BY it.owner, it.creation""", 
			as_list = 1)
	j = 1
	for i in obs_items:
		vr = frappe.db.sql("""SELECT name FROM `tabValuation Rate` 
			WHERE item_code = '%s' """% i[0], as_list=1)
		if vr:
			for k in range(len(vr)):
				frappe.delete_doc_if_exists("Valuation Rate", vr[k][0])
				print "Deleted", vr[k][0]
		frappe.delete_doc_if_exists("Item", i[0])
		print "Row#", j, "Deleted Item", i[0], "which was Created By", i[1], "on", i[2]
		j += 1
	print "Total Items Deleted=", len(obs_items)
def create_user_if_not_exists(email, first_name=None):
    frappe.delete_doc_if_exists("User", email)

    frappe.get_doc({
        "doctype": "User",
        "user_type": "Website User",
        "email": email,
        "send_welcome_email": 0,
        "first_name": first_name or email.split("@")[0],
        "birth_date": frappe.utils.now_datetime()
    }).insert(ignore_permissions=True)
示例#23
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 = []

        self.assertRaises(InvalidItemAttributeValueError, attribute.save)
        frappe.db.rollback()
示例#24
0
	def test_item_defaults(self):
		frappe.delete_doc_if_exists("Item", "Test Item With Defaults", force=1)
		make_item("Test Item With Defaults", {
			"item_group": "_Test Item Group",
			"brand": "_Test Brand With Item Defaults",
			"item_defaults": [{
				"company": "_Test Company",
				"default_warehouse": "_Test Warehouse 2 - _TC",  # no override
				"expense_account": "_Test Account Stock Expenses - _TC",  # override brand default
				"buying_cost_center": "_Test Write Off Cost Center - _TC",  # override item group default
			}]
		})

		sales_item_check = {
			"item_code": "Test Item With Defaults",
			"warehouse": "_Test Warehouse 2 - _TC",  # from item
			"income_account": "_Test Account Sales - _TC",  # from brand
			"expense_account": "_Test Account Stock Expenses - _TC",  # from item
			"cost_center": "_Test Cost Center 2 - _TC",  # from item group
		}
		sales_item_details = get_item_details({
			"item_code": "Test Item With Defaults",
			"company": "_Test Company",
			"price_list": "_Test Price List",
			"currency": "_Test Currency",
			"doctype": "Sales Invoice",
			"conversion_rate": 1,
			"price_list_currency": "_Test Currency",
			"plc_conversion_rate": 1,
			"customer": "_Test Customer",
		})
		for key, value in iteritems(sales_item_check):
			self.assertEqual(value, sales_item_details.get(key))

		purchase_item_check = {
			"item_code": "Test Item With Defaults",
			"warehouse": "_Test Warehouse 2 - _TC",  # from item
			"expense_account": "_Test Account Stock Expenses - _TC",  # from item
			"income_account": "_Test Account Sales - _TC",  # from brand
			"cost_center": "_Test Write Off Cost Center - _TC"  # from item
		}
		purchase_item_details = get_item_details({
			"item_code": "Test Item With Defaults",
			"company": "_Test Company",
			"price_list": "_Test Price List",
			"currency": "_Test Currency",
			"doctype": "Purchase Invoice",
			"conversion_rate": 1,
			"price_list_currency": "_Test Currency",
			"plc_conversion_rate": 1,
			"supplier": "_Test Supplier",
		})
		for key, value in iteritems(purchase_item_check):
			self.assertEqual(value, purchase_item_details.get(key))
 def tearDown(self):
     if self.fixture:
         frappe.delete_doc_if_exists('Loan Collateral',
                                     self.fixture.name,
                                     force=1)
         self.fixture = None
     if self.loan_name:
         loan = frappe.get_doc('Gold Loan', self.loan_name)
         loan.cancel()
         frappe.delete_doc_if_exists('Gold Loan', self.loan_name, force=1)
         self.loan_name = None
示例#26
0
def execute():
    frappe.reload_doctype("ERPNext Support Issue")
    frappe.db.sql(
        "UPDATE `tabERPNext Support Issue` SET frappe_issue_id=associated_issue"
    )

    if frappe.conf.erpnext_support_url == frappe.utils.get_url():
        server_fields()

        frappe.db.sql("UPDATE `tabIssue` SET client_issue_id=associated_issue")
        frappe.delete_doc_if_exists("Custom Field", "Issue-associated_issue")
def execute():

	frappe.db.sql("UPDATE tabItem SET `bio_barcode` = `barcode` WHERE `transaction_id` IS NOT NULL")
	frappe.db.sql("UPDATE tabItem SET `bio_remaining_quantity` = `actual_qty`")
	frappe.db.sql("UPDATE tabItem SET `bio_last_sync` = `last_sync`")

	frappe.delete_doc_if_exists("Custom Field", "Item-sub_items")
	frappe.delete_doc_if_exists("Custom Field", "Item-sub_lot_sec")
	frappe.delete_doc_if_exists("Custom Field", "Item-actual_qty")
	frappe.delete_doc_if_exists("Custom Field", "Item-last_sync")
	frappe.delete_doc_if_exists("Custom Field", "Item-external_qty")
 def test_loan_on_jv_cancel(self):
     loan = make_gold_loan()
     self.fixture = loan
     jv_name = make_foreclosure_jv(loan.name, posting_date='2018-03-12')
     jv = frappe.get_doc('Journal Entry', jv_name)
     jv.cancel()
     loan_status, foreclosure_jv = frappe.get_value(
         'Gold Loan', loan.name, ['status', 'foreclosure_jv'])
     self.assertEqual(loan_status, 'Open')
     self.assertEqual(foreclosure_jv, None)
     frappe.delete_doc_if_exists('Journal Entry', jv_name, force=1)
示例#29
0
    def test_make_customer(self):
        from erpnext.crm.doctype.lead.lead import make_customer

        frappe.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()
示例#30
0
	def tearDown(self):
		for entry in frappe.db.get_all("Ledger Merge"):
			frappe.delete_doc("Ledger Merge", entry.name)

		test_accounts = [
			"Indirect Test Expenses - _TC",
			"Administrative Test Expenses - _TC",
			"Indirect Test Income - _TC",
			"Administrative Test Income - _TC",
		]
		for account in test_accounts:
			frappe.delete_doc_if_exists("Account", account)
示例#31
0
	def insert_custom_field(self):
		frappe.delete_doc_if_exists("Custom Field", "User-test_custom_field")
		frappe.get_doc({
			"doctype": "Custom Field",
			"dt": "User",
			"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()
示例#32
0
 def insert_custom_field(self):
     frappe.delete_doc_if_exists("Custom Field", "User-test_custom_field")
     frappe.get_doc({
         "doctype": "Custom Field",
         "dt": "User",
         "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()
示例#33
0
    def on_trash(self):
        material_list = frappe.get_list(
            "Material de Impresion Items", {
                "parent": self.name,
                "parenttype": "Dimensiones",
                "parentfield": "materials",
            }, ["materials", "parent"])

        for material in material_list:
            item_name = "{materials}, {parent}".format(**material)

            frappe.delete_doc_if_exists("Item", item_name)
示例#34
0
    def test_mandatory(self):
        frappe.delete_doc_if_exists("User", "*****@*****.**")

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

        d.set("first_name", "Test Mandatory")
        d.insert()
        self.assertEqual(frappe.db.get_value("User", d.name), d.name)
def execute():
	'''Get 'Disable CWIP Accounting value' from Asset Settings, set it in 'Enable Capital Work in Progress Accounting' field
	in Company, delete Asset Settings '''

	if frappe.db.exists("DocType", "Asset Settings"):
		frappe.reload_doctype("Asset Category")
		cwip_value = frappe.db.get_single_value("Asset Settings", "disable_cwip_accounting")
		
		frappe.db.sql("""UPDATE `tabAsset Category` SET enable_cwip_accounting = %s""", cint(cwip_value))

		frappe.db.sql("""DELETE FROM `tabSingles` where doctype = 'Asset Settings'""")
		frappe.delete_doc_if_exists("DocType", "Asset Settings")
	def test_make_customer(self):
		from erpnext.selling.doctype.lead.lead import make_customer

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

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

		customer.company = "_Test Company"
		customer.customer_group = "_Test Customer Group"
		customer.insert()
示例#37
0
	def setUp(self):
		test_users = (
			"*****@*****.**",
			"*****@*****.**",
			"*****@*****.**",
		)
		frappe.db.delete("User Permission", {
			"user": ("in", test_users)
		})
		frappe.delete_doc_if_exists("DocType", "Person")
		frappe.db.sql_ddl("DROP TABLE IF EXISTS `tabPerson`")
		frappe.delete_doc_if_exists("DocType", "Doc A")
		frappe.db.sql_ddl("DROP TABLE IF EXISTS `tabDoc A`")
示例#38
0
	def insert_custom_field(self):
		frappe.delete_doc_if_exists("Custom Field", "Event-test_custom_field")
		frappe.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": frappe.get_meta('Event').fields[-1].fieldname
		}).insert()
def execute():

    frappe.db.sql(
        "UPDATE tabItem SET `bio_barcode` = `barcode` WHERE `transaction_id` IS NOT NULL"
    )
    frappe.db.sql("UPDATE tabItem SET `bio_remaining_quantity` = `actual_qty`")
    frappe.db.sql("UPDATE tabItem SET `bio_last_sync` = `last_sync`")

    frappe.delete_doc_if_exists("Custom Field", "Item-sub_items")
    frappe.delete_doc_if_exists("Custom Field", "Item-sub_lot_sec")
    frappe.delete_doc_if_exists("Custom Field", "Item-actual_qty")
    frappe.delete_doc_if_exists("Custom Field", "Item-last_sync")
    frappe.delete_doc_if_exists("Custom Field", "Item-external_qty")
示例#40
0
def create_earned_leave_type(leave_type, based_on_doj=False):
    frappe.delete_doc_if_exists("Leave Type", leave_type, force=1)

    return frappe.get_doc(
        dict(
            leave_type_name=leave_type,
            doctype="Leave Type",
            is_earned_leave=1,
            earned_leave_frequency="Monthly",
            rounding=0.5,
            is_carry_forward=1,
            based_on_date_of_joining=based_on_doj,
        )).insert()
示例#41
0
    def test_mandatory(self):
        # TODO: recheck if it is OK to force delete
        frappe.delete_doc_if_exists("User", "*****@*****.**", 1)

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

        d.set("first_name", "Test Mandatory")
        d.insert()
        self.assertEqual(frappe.db.get_value("User", d.name), d.name)
示例#42
0
	def test_pricing_rule_with_margin_and_discount(self):
		frappe.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)
示例#43
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()
def execute():
	"""bench execute erpnext_biotrack.patches.delete_all_sample_items.execute"""
	# Disable feed update
	frappe.flags.in_patch = True

	for name in frappe.get_all("Item", {"is_sample": 1}):
		print name
		frappe.db.sql("UPDATE tabItem SET sample = NULL WHERE sample = %(name)s", name)
		frappe.db.sql("DELETE FROM `tabItem Sub Lot` WHERE item_code = %(name)s", name)
		delete_item(name)
		frappe.db.commit()

	frappe.delete_doc_if_exists("Custom Field", "Item-is_sample")
	frappe.delete_doc_if_exists("Custom Field", "Item-sample")
	frappe.flags.in_patch = False
def execute():
	for role in ('Customer', 'Supplier'):
		frappe.db.sql('''delete from `tabUserRole`
			where role=%s and parent in ("Administrator", "Guest")''', role)

		if not frappe.db.sql('select name from `tabUserRole` where role=%s', role):

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

			# delete Role
			frappe.delete_doc_if_exists('Role', role)
示例#46
0
	def test_cannot_create_direct(self):
		frappe.delete_doc_if_exists("Serial No", "_TCSER0001")

		sr = frappe.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)
示例#47
0
	def test_applicable_after(self):
		employee = get_employee()
		leave_period = get_leave_period()
		frappe.delete_doc_if_exists("Leave Type", "Test Leave Type", force=1)
		leave_type = frappe.get_doc(dict(
			leave_type_name = 'Test Leave Type',
			doctype = 'Leave Type',
			applicable_after = 15
		)).insert()
		date = add_days(nowdate(), -7)
		frappe.db.set_value('Employee', employee.name, "date_of_joining", date)
		allocate_leaves(employee, leave_period, leave_type.name, 10)

		leave_application = frappe.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(frappe.ValidationError, leave_application.insert)

		frappe.delete_doc_if_exists("Leave Type", "Test Leave Type 1", force=1)
		leave_type_1 = frappe.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 = frappe.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())
		frappe.db.set_value('Employee', employee.name, "date_of_joining", "2010-01-01")
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 frappe.db.sql_list("""select name from `tabProperty Setter`
			where property='default_print_format' and value=%s""", fmt):
			ps = frappe.get_doc("Property Setter", ps)
			ps.value = "Standard"
			ps.save(ignore_permissions = True)

		frappe.delete_doc_if_exists("Print Format", fmt)
示例#49
0
def clean_dynamic_link_table():
	query = """SELECT name FROM `tabDynamic Link` 
		WHERE parenttype = 'Contact' 
		AND parent NOT IN (SELECT name FROM `tabContact`)"""
	wrong_contact_list = frappe.db.sql(query, as_list=1)
	for contact in wrong_contact_list:
		print (contact)

	query = """SELECT name FROM `tabDynamic Link` 
		WHERE parenttype = 'Address' 
		AND parent NOT IN (SELECT name FROM `tabAddress`)"""
	wrong_add_list = frappe.db.sql(query, as_list=1)
	if wrong_add_list:
		for address in wrong_add_list:
			frappe.delete_doc_if_exists("Dynamic Link", address[0])
			frappe.db.commit()
			print("Deleted Dynamic Link " + address[0])
示例#50
0
    def test_link_validation(self):
        frappe.delete_doc_if_exists("User", "*****@*****.**")

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

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

        self.assertEquals(frappe.db.get_value("User", d.name), d.name)
def execute():
	frappe.reload_doc("buying", "doctype", "request_for_quotation_supplier")
	frappe.reload_doc("buying", "doctype", "request_for_quotation_item")
	frappe.reload_doc("buying", "doctype", "request_for_quotation")
	frappe.reload_doc("projects", "doctype", "timesheet")
	
	for role in ('Customer', 'Supplier'):
		frappe.db.sql('''delete from `tabHas Role`
			where role=%s and parent in ("Administrator", "Guest")''', role)

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

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

			# delete Role
			frappe.delete_doc_if_exists('Role', role)
示例#52
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()
	def test_make_supplier_quotation_with_special_characters(self):
		from erpnext.buying.doctype.request_for_quotation.request_for_quotation import make_supplier_quotation

		frappe.delete_doc_if_exists("Supplier", "_Test Supplier '1", force=1)
		supplier = frappe.new_doc("Supplier")
		supplier.supplier_name = "_Test Supplier '1"
		supplier.supplier_type = "_Test Supplier Type"
		supplier.insert()

		rfq = make_request_for_quotation(supplier_wt_appos)

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

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

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

		# reset form_dict
		frappe.form_dict.name = None
	def test_make_item_variant_with_numeric_values(self):
		# cleanup
		frappe.delete_doc_if_exists("Item", "_Test Numeric Template Item")
		frappe.delete_doc_if_exists("Item", "_Test Numeric Variant-L-1.5")
		frappe.delete_doc_if_exists("Item Attribute", "Test Item Length")

		# 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
				}
			],
			"default_warehouse": "_Test Warehouse - _TC"
		})

		variant = create_variant("_Test Numeric Template Item", {"Test Size": "Large", "Test Item Length": 1.1})
		self.assertEquals(variant.item_code, None)
		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.assertEquals(variant.item_code, None)
		variant.item_code = "_Test Numeric Variant-L-1.5"
		variant.item_name = "_Test Numeric Variant Large 1.5m"
		variant.save()
def execute():
        frappe.delete_doc_if_exists("DocType", "User Permission for Page and Report")
示例#56
0
	def tearDown(self):
		frappe.delete_doc_if_exists('Physician', '_Testdoctor2', force=1)
def execute():
	for warehouse, user in frappe.db.sql("""select parent, user from `tabWarehouse User`"""):
		frappe.permissions.add_user_permission("Warehouse", warehouse, user)

	frappe.delete_doc_if_exists("DocType", "Warehouse User")
	frappe.reload_doc("stock", "doctype", "warehouse")
示例#58
0
def execute():
	frappe.delete_doc_if_exists("DocType", "BOM Replace Tool")

	frappe.reload_doctype("BOM")
	frappe.db.sql("update tabBOM set conversion_rate=1 where conversion_rate is null or conversion_rate=0")
	frappe.db.sql("update tabBOM set set_rate_of_sub_assembly_item_based_on_bom=1")
示例#59
0
def execute():
    frappe.delete_doc_if_exists('Page', 'bom-browser')