def create_custom_field_for_owner_match():
	frappe.db.sql("""update `tabDocPerm` set apply_user_permissions=1 where `match`='owner'""")

	for dt in frappe.db.sql_list("""select distinct parent from `tabDocPerm`
		where `match`='owner' and permlevel=0 and parent != 'User'"""):

		# a link field pointing to User already exists
		if (frappe.db.get_value("DocField", {"parent": dt, "fieldtype": "Link", "options": "User", "default": "__user"})
			or frappe.db.get_value("Custom Field", {"dt": dt, "fieldtype": "Link", "options": "User", "default": "__user"})):
			print("User link field already exists for", dt)
			continue

		fieldname = "{}_owner".format(frappe.scrub(dt))

		create_custom_field(dt, frappe._dict({
			"permlevel": 0,
			"label": "{} Owner".format(dt),
			"fieldname": fieldname,
			"fieldtype": "Link",
			"options": "User",
			"default": "__user"
		}))

		frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=owner""".format(doctype=dt,
			fieldname=fieldname))

		# commit is required so that we don't lose these changes because of an error in next loop's ddl
		frappe.db.commit()
Example #2
0
def add_dimension_to_budget_doctype(df, doc):
    df.update({
        "insert_after":
        "cost_center",
        "depends_on":
        "eval:doc.budget_against == '{0}'".format(doc.document_type)
    })

    create_custom_field("Budget", df)

    property_setter = frappe.db.exists("Property Setter",
                                       "Budget-budget_against-options")

    if property_setter:
        property_setter_doc = frappe.get_doc("Property Setter",
                                             "Budget-budget_against-options")
        property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
        property_setter_doc.save()

        frappe.clear_cache(doctype='Budget')
    else:
        frappe.get_doc({
            "doctype": "Property Setter",
            "doctype_or_field": "DocField",
            "doc_type": "Budget",
            "field_name": "budget_against",
            "property": "options",
            "property_type": "Text",
            "value": "\nCost Center\nProject\n" + doc.document_type
        }).insert(ignore_permissions=True)
Example #3
0
def apply_custom_fields():
    create_custom_field('Healthcare Practitioner', {
        'fieldname': 'vc_color',
        'label': 'Color',
        'insert_after': 'office_phone'
    })
    return True
def create_custom_field_for_owner_match():
	frappe.db.sql("""update `tabDocPerm` set apply_user_permissions=1 where `match`='owner'""")

	for dt in frappe.db.sql_list("""select distinct parent from `tabDocPerm`
		where `match`='owner' and permlevel=0 and parent != 'User'"""):

		# a link field pointing to User already exists
		if (frappe.db.get_value("DocField", {"parent": dt, "fieldtype": "Link", "options": "User", "default": "__user"})
			or frappe.db.get_value("Custom Field", {"dt": dt, "fieldtype": "Link", "options": "User", "default": "__user"})):
			print "User link field already exists for", dt
			continue

		fieldname = "{}_owner".format(frappe.scrub(dt))

		create_custom_field(dt, frappe._dict({
			"permlevel": 0,
			"label": "{} Owner".format(dt),
			"fieldname": fieldname,
			"fieldtype": "Link",
			"options": "User",
			"default": "__user"
		}))

		frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=owner""".format(doctype=dt,
			fieldname=fieldname))

		# commit is required so that we don't lose these changes because of an error in next loop's ddl
		frappe.db.commit()
Example #5
0
def make_custom_fields(doctype, local_doc, original_doc):
	"""
	check fields and create a custom field equivalent for non standard fields
	"""
	local_fields, original_fields = get_fields_dict(local_doc), get_fields_dict(original_doc)
	local_fields = sorted(local_fields.items(), key=lambda x: x[1]["idx"])
	doctype_doc = frappe.get_doc("DocType", doctype)

	custom_docfield_properties, prev = get_custom_docfield_properties(), ""
	for field, field_dict in local_fields:
		df = {}
		if field not in original_fields:
			for prop in field_dict:
				if prop in custom_docfield_properties:
					df[prop] = field_dict[prop]

			df["insert_after"] = prev if prev else ""

			doctype_doc.fields = [d for d in doctype_doc.fields if d.fieldname != df["fieldname"]]
			doctype_doc.update_children()

			create_custom_field(doctype, df)

		# set current field as prev field for next field
		prev = field
Example #6
0
def make_dimension_in_accounting_doctypes(doc):
    doclist = get_doctypes_with_dimensions()
    doc_count = len(get_accounting_dimensions())
    count = 0

    for doctype in doclist:

        if (doc_count + 1) % 2 == 0:
            insert_after_field = 'dimension_col_break'
        else:
            insert_after_field = 'accounting_dimensions_section'

        df = {
            "fieldname": doc.fieldname,
            "label": doc.label,
            "fieldtype": "Link",
            "options": doc.document_type,
            "insert_after": insert_after_field,
            "owner": "Administrator"
        }

        if doctype == "Budget":
            add_dimension_to_budget_doctype(df, doc)
        else:
            meta = frappe.get_meta(doctype, cached=False)
            fieldnames = [d.fieldname for d in meta.get("fields")]

            if df['fieldname'] not in fieldnames:
                create_custom_field(doctype, df)

        count += 1

        frappe.publish_progress(count * 100 / len(doclist),
                                title=_("Creating Dimensions..."))
        frappe.clear_cache(doctype=doctype)
Example #7
0
def add_custom_fields():
    hsn_sac_field = dict(fieldname='gst_hsn_code',
                         label='HSN/SAC',
                         fieldtype='Data',
                         options='item_code.gst_hsn_code',
                         insert_after='description')

    custom_fields = {
        'Address': [
            dict(fieldname='gst_state_number',
                 label='GST State Number',
                 fieldtype='Int',
                 insert_after='gst_state'),
        ],
        'Sales Invoice': [
            dict(
                fieldname='invoice_copy',
                label='Invoice Copy',
                fieldtype='Select',
                insert_after='project',
                print_hide=1,
                allow_on_submit=1,
                options=
                'ORIGINAL FOR RECIPIENT\nDUPLICATE FOR TRANSPORTER\nTRIPLICATE FOR SUPPLIER'
            ),
        ],
        'Sales Order Item': [hsn_sac_field],
        'Delivery Note Item': [hsn_sac_field],
        'Purchase Order Item': [hsn_sac_field],
        'Purchase Receipt Item': [hsn_sac_field]
    }

    for doctype, fields in custom_fields.items():
        for df in fields:
            create_custom_field(doctype, df)
Example #8
0
	def make_repeatable(self):
		"""If allow_auto_repeat is set, add auto_repeat custom field."""
		if self.allow_auto_repeat:
			if not frappe.db.exists('Custom Field', {'fieldname': 'auto_repeat', 'dt': self.name}):
				insert_after = self.fields[len(self.fields) - 1].fieldname
				df = dict(fieldname='auto_repeat', label='Auto Repeat', fieldtype='Link', options='Auto Repeat', insert_after=insert_after, read_only=1, no_copy=1, print_hide=1)
				create_custom_field(self.name, df)
def execute():
	# auto repeat is not submittable in v12
	frappe.reload_doc("automation", "doctype", "Auto Repeat")
	frappe.db.sql("update `tabDocPerm` set submit=0, cancel=0, amend=0 where parent='Auto Repeat'")
	frappe.db.sql("update `tabAuto Repeat` set docstatus=0 where docstatus=1 or docstatus=2")

	for entry in frappe.get_all("Auto Repeat"):
		doc = frappe.get_doc("Auto Repeat", entry.name)

		# create custom field for allow auto repeat
		fields = frappe.get_meta(doc.reference_doctype).fields
		insert_after = fields[len(fields) - 1].fieldname
		df = dict(
			fieldname="auto_repeat",
			label="Auto Repeat",
			fieldtype="Link",
			insert_after=insert_after,
			options="Auto Repeat",
			hidden=1,
			print_hide=1,
			read_only=1,
		)
		create_custom_field(doc.reference_doctype, df)

		if doc.status in ["Draft", "Stopped", "Cancelled"]:
			doc.disabled = 1

		doc.flags.ignore_links = 1
		# updates current status as Active, Disabled or Completed on validate
		doc.save()
Example #10
0
    def test_log_touched_tables(self):
        frappe.flags.in_migrate = True
        frappe.flags.touched_tables = set()
        frappe.db.set_value('System Settings', 'System Settings',
                            'backup_limit', 5)
        self.assertIn('tabSingles', frappe.flags.touched_tables)

        frappe.flags.touched_tables = set()
        todo = frappe.get_doc({
            'doctype': 'ToDo',
            'description': 'Random Description'
        })
        todo.save()
        self.assertIn('tabToDo', frappe.flags.touched_tables)

        frappe.flags.touched_tables = set()
        todo.description = "Another Description"
        todo.save()
        self.assertIn('tabToDo', frappe.flags.touched_tables)

        frappe.flags.touched_tables = set()
        todo.delete()
        self.assertIn('tabToDo', frappe.flags.touched_tables)

        frappe.flags.touched_tables = set()
        create_custom_field('ToDo', {'label': 'ToDo Custom Field'})

        self.assertIn('tabToDo', frappe.flags.touched_tables)
        self.assertIn('tabCustom Field', frappe.flags.touched_tables)
        frappe.flags.in_migrate = False
        frappe.flags.touched_tables.clear()
Example #11
0
def make_custom_fields(doctype, local_doc, original_doc):
	'''
		check fields and create a custom field equivalent for non standard fields
	'''
	local_fields, original_fields = get_fields_dict(local_doc), get_fields_dict(original_doc)
	local_fields = sorted(local_fields.items(), key=lambda x: x[1]['idx'])
	doctype_doc = frappe.get_doc('DocType', doctype)

	custom_docfield_properties, prev = get_custom_docfield_properties(), ""
	for field, field_dict in local_fields:
		df = {}
		if field not in original_fields:
			for prop in field_dict:
				if prop in custom_docfield_properties:
					df[prop] = field_dict[prop]

			df['insert_after'] = prev if prev else ''

			doctype_doc.fields = [d for d in doctype_doc.fields if d.fieldname != df['fieldname']]
			doctype_doc.update_children()

			create_custom_field(doctype, df)

		# set current field as prev field for next field
		prev = field
Example #12
0
	def test_get_single_value(self):
		#setup
		values_dict = {
			"Float": 1.5,
			"Int": 1,
			"Percent": 55.5,
			"Currency": 12.5,
			"Data": "Test",
			"Date": datetime.datetime.now().date(),
			"Datetime": datetime.datetime.now(),
			"Time": datetime.timedelta(hours=9, minutes=45, seconds=10)
		}
		test_inputs = [{
			"fieldtype": fieldtype,
			"value": value} for fieldtype, value in values_dict.items()]
		for fieldtype in values_dict.keys():
			create_custom_field("Print Settings", {
				"fieldname": f"test_{fieldtype.lower()}",
				"label": f"Test {fieldtype}",
				"fieldtype": fieldtype,
			})

		#test
		for inp in test_inputs:
			fieldname = f"test_{inp['fieldtype'].lower()}"
			frappe.db.set_value("Print Settings", "Print Settings", fieldname, inp["value"])
			self.assertEqual(frappe.db.get_single_value("Print Settings", fieldname), inp["value"])

		#teardown
		clear_custom_fields("Print Settings")
Example #13
0
 def add_custom_field(field):
     create_custom_field(
         test_doctype, {
             "fieldname": field.lower(),
             "label": field.title(),
             "fieldtype": 'Data',
         })
Example #14
0
    def create_delete_custom_fields(self):
        if self.enable_sync:
            custom_fields = {}
            # create
            for doctype in ["Customer", "Sales Order", "Item", "Address"]:
                df = dict(
                    fieldname="woocommerce_id",
                    label="Woocommerce ID",
                    fieldtype="Data",
                    read_only=1,
                    print_hide=1,
                )
                create_custom_field(doctype, df)

            for doctype in ["Customer", "Address"]:
                df = dict(
                    fieldname="woocommerce_email",
                    label="Woocommerce Email",
                    fieldtype="Data",
                    read_only=1,
                    print_hide=1,
                )
                create_custom_field(doctype, df)

            if not frappe.get_value("Item Group",
                                    {"name": _("WooCommerce Products")}):
                item_group = frappe.new_doc("Item Group")
                item_group.item_group_name = _("WooCommerce Products")
                item_group.parent_item_group = get_root_of("Item Group")
                item_group.insert()
def make_dimension_in_accounting_doctypes(doc):
    doclist = get_doctypes_with_dimensions()
    doc_count = len(get_accounting_dimensions())
    count = 0

    for doctype in doclist:

        if (doc_count + 1) % 2 == 0:
            insert_after_field = 'dimension_col_break'
        else:
            insert_after_field = 'accounting_dimensions_section'

        df = {
            "fieldname": doc.fieldname,
            "label": doc.label,
            "fieldtype": "Link",
            "options": doc.document_type,
            "insert_after": insert_after_field
        }

        if frappe.db.exists("DocType", doctype):
            if doctype == "Budget":
                add_dimension_to_budget_doctype(df, doc)
            else:
                create_custom_field(doctype, df)

        count += 1

        frappe.publish_progress(count * 100 / len(doclist),
                                title=_("Creating Dimensions..."))
        frappe.clear_cache(doctype=doctype)
Example #16
0
	def create_custom_fields(self):
		"""create custom field to store remote docname and remote site url"""
		for entry in self.producer_doctypes:
			if not entry.use_same_name:
				if not frappe.db.exists(
					"Custom Field", {"fieldname": "remote_docname", "dt": entry.ref_doctype}
				):
					df = dict(
						fieldname="remote_docname",
						label="Remote Document Name",
						fieldtype="Data",
						read_only=1,
						print_hide=1,
					)
					create_custom_field(entry.ref_doctype, df)
				if not frappe.db.exists(
					"Custom Field", {"fieldname": "remote_site_name", "dt": entry.ref_doctype}
				):
					df = dict(
						fieldname="remote_site_name",
						label="Remote Site",
						fieldtype="Data",
						read_only=1,
						print_hide=1,
					)
					create_custom_field(entry.ref_doctype, df)
Example #17
0
def add_custom_fields():
    df = dict(fieldname='auto_repeat',
              label='Auto Repeat',
              fieldtype='Link',
              insert_after='sender',
              options='Auto Repeat')
    create_custom_field('ToDo', df)
Example #18
0
	def test_log_touched_tables(self):
		frappe.flags.in_migrate = True
		frappe.flags.touched_tables = set()
		frappe.db.set_value('System Settings', 'System Settings', 'backup_limit', 5)
		self.assertIn('tabSingles', frappe.flags.touched_tables)

		frappe.flags.touched_tables = set()
		todo = frappe.get_doc({'doctype': 'ToDo', 'description': 'Random Description'})
		todo.save()
		self.assertIn('tabToDo', frappe.flags.touched_tables)

		frappe.flags.touched_tables = set()
		todo.description = "Another Description"
		todo.save()
		self.assertIn('tabToDo', frappe.flags.touched_tables)

		frappe.flags.touched_tables = set()
		todo.delete()
		self.assertIn('tabToDo', frappe.flags.touched_tables)

		frappe.flags.touched_tables = set()
		create_custom_field('ToDo', {'label': 'ToDo Custom Field'})

		self.assertIn('tabToDo', frappe.flags.touched_tables)
		self.assertIn('tabCustom Field', frappe.flags.touched_tables)
		frappe.flags.in_migrate = False
		frappe.flags.touched_tables.clear()
def execute():

    doctypes = [
        "salary_component",
        "Employee Tax Exemption Declaration",
        "Employee Tax Exemption Proof Submission",
        "Employee Tax Exemption Declaration Category",
        "Employee Tax Exemption Proof Submission Detail",
        "gratuity_rule",
        "gratuity_rule_slab",
        "gratuity_applicable_component",
    ]

    for doctype in doctypes:
        frappe.reload_doc("Payroll", "doctype", doctype, force=True)

    reports = [
        "Professional Tax Deductions", "Provident Fund Deductions",
        "E-Invoice Summary"
    ]
    for report in reports:
        frappe.reload_doc("Regional", "Report", report)
        frappe.reload_doc("Regional", "Report", report)

    if erpnext.get_region() == "India":
        create_custom_field(
            "Salary Component",
            dict(
                fieldname="component_type",
                label="Component Type",
                fieldtype="Select",
                insert_after="description",
                options=
                "\nProvident Fund\nAdditional Provident Fund\nProvident Fund Loan\nProfessional Tax",
                depends_on='eval:doc.type == "Deduction"',
            ),
        )

    if frappe.db.exists("Salary Component", "Income Tax"):
        frappe.db.set_value("Salary Component", "Income Tax",
                            "is_income_tax_component", 1)
    if frappe.db.exists("Salary Component", "TDS"):
        frappe.db.set_value("Salary Component", "TDS",
                            "is_income_tax_component", 1)

    components = frappe.db.sql(
        "select name from `tabSalary Component` where variable_based_on_taxable_salary = 1",
        as_dict=1)
    for component in components:
        frappe.db.set_value("Salary Component", component.name,
                            "is_income_tax_component", 1)

    if erpnext.get_region() == "India":
        if frappe.db.exists("Salary Component", "Provident Fund"):
            frappe.db.set_value("Salary Component", "Provident Fund",
                                "component_type", "Provident Fund")
        if frappe.db.exists("Salary Component", "Professional Tax"):
            frappe.db.set_value("Salary Component", "Professional Tax",
                                "component_type", "Professional Tax")
def contact_custom():
    if not frappe.db.exists("Custom Field",
                            dict(dt="Contact", fieldname="mautic_segments")):
        data = customization_data('contact.json')

        for customization in data['custom_fields']:
            frappe.set_user("Administrator")
            create_custom_field('Contact', frappe._dict(customization))
Example #21
0
def create_print_zero_amount_taxes_custom_field():
	create_custom_field('Print Settings', {
		'label': _('Print taxes with zero amount'),
		'fieldname': 'print_taxes_with_zero_amount',
		'fieldtype': 'Check',
		'default': 0,
		'insert_after': 'allow_print_for_cancelled'
	})
Example #22
0
def create_print_zero_amount_taxes_custom_field():
    create_custom_field('Print Settings', {
        'label': _('Print taxes with zero amount'),
        'fieldname': 'print_taxes_with_zero_amount',
        'fieldtype': 'Check',
        'default': 0,
        'insert_after': 'allow_print_for_cancelled'
    })
Example #23
0
def create_print_uom_after_qty_custom_field():
    create_custom_field('Print Settings', {
        'label': _('Print UOM after Quantity'),
        'fieldname': 'print_uom_after_quantity',
        'fieldtype': 'Check',
        'default': 0,
        'insert_after': 'compact_item_print'
    })
Example #24
0
def create_compact_item_print_custom_field():
    create_custom_field('Print Settings', {
        'label': _('Compact Item Print'),
        'fieldname': 'compact_item_print',
        'fieldtype': 'Check',
        'default': 1,
        'insert_after': 'with_letterhead'
    })
Example #25
0
def create_compact_item_print_custom_field():
	create_custom_field('Print Settings', {
		'label': _('Compact Item Print'),
		'fieldname': 'compact_item_print',
		'fieldtype': 'Check',
		'default': 1,
		'insert_after': 'with_letterhead'
	})
Example #26
0
 def create_custom_fields(doctypes):
     for doctype in doctypes:
         df = {
             "fieldtype": "Data",
             "fieldname": "tally_guid",
             "read_only": 1,
             "label": "Tally GUID"
         }
         create_custom_field(doctype, df)
Example #27
0
    def test_assignment_rule_condition(self):
        frappe.db.sql("DELETE FROM `tabAssignment Rule`")

        # Add expiry_date custom field
        from frappe.custom.doctype.custom_field.custom_field import create_custom_field

        df = dict(fieldname="expiry_date",
                  label="Expiry Date",
                  fieldtype="Date")
        create_custom_field("Note", df)

        assignment_rule = frappe.get_doc(
            dict(
                name="Assignment with Due Date",
                doctype="Assignment Rule",
                document_type="Note",
                assign_condition="public == 0",
                due_date_based_on="expiry_date",
                assignment_days=self.days,
                users=[
                    dict(user="******"),
                ],
            )).insert()

        expiry_date = frappe.utils.add_days(frappe.utils.nowdate(), 2)
        note1 = make_note({"expiry_date": expiry_date})
        note2 = make_note({"expiry_date": expiry_date})

        note1_todo = frappe.get_all("ToDo",
                                    filters=dict(reference_type="Note",
                                                 reference_name=note1.name,
                                                 status="Open"))[0]

        note1_todo_doc = frappe.get_doc("ToDo", note1_todo.name)
        self.assertEqual(frappe.utils.get_date_str(note1_todo_doc.date),
                         expiry_date)

        # due date should be updated if the reference doc's date is updated.
        note1.expiry_date = frappe.utils.add_days(expiry_date, 2)
        note1.save()
        note1_todo_doc.reload()
        self.assertEqual(frappe.utils.get_date_str(note1_todo_doc.date),
                         note1.expiry_date)

        # saving one note's expiry should not update other note todo's due date
        note2_todo = frappe.get_all(
            "ToDo",
            filters=dict(reference_type="Note",
                         reference_name=note2.name,
                         status="Open"),
            fields=["name", "date"],
        )[0]
        self.assertNotEqual(frappe.utils.get_date_str(note2_todo.date),
                            note1.expiry_date)
        self.assertEqual(frappe.utils.get_date_str(note2_todo.date),
                         expiry_date)
        assignment_rule.delete()
Example #28
0
	def create_custom_fields(self):
		"""create custom field to store remote docname and remote site url"""
		for entry in self.producer_doctypes:
			if not entry.use_same_name:
				if not frappe.db.exists('Custom Field', {'fieldname': 'remote_docname', 'dt': entry.ref_doctype}):
					df = dict(fieldname='remote_docname', label='Remote Document Name', fieldtype='Data', read_only=1, print_hide=1)
					create_custom_field(entry.ref_doctype, df)
				if not frappe.db.exists('Custom Field', {'fieldname': 'remote_site_name', 'dt': entry.ref_doctype}):
					df = dict(fieldname='remote_site_name', label='Remote Site', fieldtype='Data', read_only=1, print_hide=1)
					create_custom_field(entry.ref_doctype, df)
Example #29
0
def add_custom_fields():
    df = dict(fieldname='auto_repeat',
              label='Auto Repeat',
              fieldtype='Link',
              insert_after='sender',
              options='Auto Repeat',
              hidden=1,
              print_hide=1,
              read_only=1)
    create_custom_field('ToDo', df)
Example #30
0
def apply_custom_fields():
    create_custom_field(
        "Healthcare Practitioner",
        {
            "fieldname": "vc_color",
            "label": "Color",
            "insert_after": "office_phone"
        },
    )
    return True
Example #31
0
def make_custom_fields():
	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
		fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description', print_hide=1)
	
	custom_fields = {
		'Address': [
			dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
				insert_after='fax'),
			dict(fieldname='gst_state', label='GST State', fieldtype='Select',
				options='\n'.join(states), insert_after='gstin'),
			dict(fieldname='gst_state_number', label='GST State Number',
				fieldtype='Int', insert_after='gst_state', read_only=1),
		],
		'Purchase Invoice': [
			dict(fieldname='supplier_gstin', label='Supplier GSTIN',
				fieldtype='Data', insert_after='supplier_address',
				options='supplier_address.gstin', print_hide=1),
			dict(fieldname='company_gstin', label='Company GSTIN',
				fieldtype='Data', insert_after='shipping_address',
				options='shipping_address.gstin', print_hide=1),
		],
		'Sales Invoice': [
			dict(fieldname='customer_gstin', label='Customer GSTIN',
				fieldtype='Data', insert_after='shipping_address',
				options='shipping_address_name.gstin', print_hide=1),
			dict(fieldname='company_gstin', label='Company GSTIN',
				fieldtype='Data', insert_after='company_address',
				options='company_address.gstin', print_hide=1),
			dict(fieldname='invoice_copy', label='Invoice Copy',
				fieldtype='Select', insert_after='select_print_heading', print_hide=1, allow_on_submit=1,
				options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier')
		],
		'Item': [
			dict(fieldname='gst_hsn_code', label='HSN/SAC',
				fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
		],
		'Quotation Item': [hsn_sac_field],
		'Supplier Quotation Item': [hsn_sac_field],
		'Sales Order Item': [hsn_sac_field],
		'Delivery Note Item': [hsn_sac_field],
		'Sales Invoice Item': [hsn_sac_field],
		'Purchase Order Item': [hsn_sac_field],
		'Purchase Receipt Item': [hsn_sac_field],
		'Purchase Invoice Item': [hsn_sac_field]
	}

	for doctype, fields in custom_fields.items():
		for df in fields:
			field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": df["fieldname"]})
			if not field:
				create_custom_field(doctype, df)
			else:
				custom_field = frappe.get_doc("Custom Field", field)
				custom_field.update(df)
				custom_field.save()
Example #32
0
def make_currency_in_budget_account(currency):
    df = {
        "fieldname": "budget_amount_in_" + scrub(currency),
        "label": "Budget Amount in " + currency,
        "fieldtype": "Currency",
        "insert_after": "budget_amount",
        "default": "0",
        "owner": "Administrator"
    }
    create_custom_field("Budget Account", df)
    frappe.clear_cache(doctype="Budget Account")
    def fetch_to_customize(self):
        self.clear_existing_doc()
        if not self.doc_type:
            return

        meta = frappe.get_meta(self.doc_type)

        if self.doc_type in core_doctypes_list:
            return frappe.msgprint(_("Core DocTypes cannot be customized."))

        if meta.issingle:
            return frappe.msgprint(_("Single DocTypes cannot be customized."))

        if meta.custom:
            return frappe.msgprint(
                _("Only standard DocTypes are allowed to be customized from Customize Form."
                  ))

        # doctype properties
        for property in doctype_properties:
            self.set(property, meta.get(property))

        for d in meta.get("fields"):
            new_d = {
                "fieldname": d.fieldname,
                "is_custom_field": d.get("is_custom_field"),
                "name": d.name
            }
            for property in docfield_properties:
                new_d[property] = d.get(property)
            self.append("fields", new_d)

        # load custom translation
        translation = self.get_name_translation()
        self.label = translation.translated_text if translation else ''

        #If allow_auto_repeat is set, add auto_repeat custom field.
        if self.allow_auto_repeat:
            all_fields = [df.fieldname for df in meta.fields]

            if "auto_repeat" in all_fields:
                return

            insert_after = self.fields[len(self.fields) - 1].fieldname
            create_custom_field(
                self.doc_type,
                dict(fieldname='auto_repeat',
                     label='Auto Repeat',
                     fieldtype='Link',
                     options='Auto Repeat',
                     insert_after=insert_after,
                     read_only=1,
                     no_copy=1,
                     print_hide=1))
Example #34
0
def create_print_zero_amount_taxes_custom_field():
    create_custom_field(
        "Print Settings",
        {
            "label": _("Print taxes with zero amount"),
            "fieldname": "print_taxes_with_zero_amount",
            "fieldtype": "Check",
            "default": 0,
            "insert_after": "allow_print_for_cancelled",
        },
    )
Example #35
0
def create_print_uom_after_qty_custom_field():
    create_custom_field(
        "Print Settings",
        {
            "label": _("Print UOM after Quantity"),
            "fieldname": "print_uom_after_quantity",
            "fieldtype": "Check",
            "default": 0,
            "insert_after": "compact_item_print",
        },
    )
Example #36
0
def create_compact_item_print_custom_field():
    create_custom_field(
        "Print Settings",
        {
            "label": _("Compact Item Print"),
            "fieldname": "compact_item_print",
            "fieldtype": "Check",
            "default": 1,
            "insert_after": "with_letterhead",
        },
    )
	def make_custom_fields_for_mappings(self):
		label = self.name + ' ID'
		fieldname = frappe.scrub(label)

		df = {
			'label': label,
			'fieldname': fieldname,
			'fieldtype': 'Data',
			'hidden': 1,
			'read_only': 1,
			'unique': 1
		}

		for m in self.mappings:
			mapping = frappe.get_doc('Data Migration Mapping', m.mapping)
			create_custom_field(mapping.local_doctype, df)
			mapping.migration_id_field = fieldname
			mapping.save()

		# Create custom field in Deleted Document
		create_custom_field('Deleted Document', df)
Example #38
0
def add_custom_fields():
	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
		fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description')

	custom_fields = {
		'Address': [
			dict(fieldname='gst_state_number', label='GST State Number',
				fieldtype='Int', insert_after='gst_state'),
		],
		'Sales Invoice': [
			dict(fieldname='invoice_copy', label='Invoice Copy',
				fieldtype='Select', insert_after='project', print_hide=1, allow_on_submit=1,
				options='ORIGINAL FOR RECIPIENT\nDUPLICATE FOR TRANSPORTER\nTRIPLICATE FOR SUPPLIER'),
		],
		'Sales Order Item': [hsn_sac_field],
		'Delivery Note Item': [hsn_sac_field],
		'Purchase Order Item': [hsn_sac_field],
		'Purchase Receipt Item': [hsn_sac_field]
	}

	for doctype, fields in custom_fields.items():
		for df in fields:
			create_custom_field(doctype, df)
Example #39
0
def make_custom_fields():
	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
		fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description',
		allow_on_submit=1, print_hide=1)
	invoice_gst_fields = [
		dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
			insert_after='select_print_heading', print_hide=1, collapsible=1),
		dict(fieldname='invoice_copy', label='Invoice Copy',
			fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
			options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
		dict(fieldname='reverse_charge', label='Reverse Charge',
			fieldtype='Select', insert_after='invoice_copy', print_hide=1,
			options='Y\nN', default='N'),
		dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='reverse_charge'),
		dict(fieldname='invoice_type', label='Invoice Type',
			fieldtype='Select', insert_after='reverse_charge', print_hide=1,
			options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
		dict(fieldname='export_type', label='Export Type',
			fieldtype='Select', insert_after='invoice_type', print_hide=1,
			depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
			options='\nWith Payment of Tax\nWithout Payment of Tax'),
		dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
			fieldtype='Data', insert_after='export_type', print_hide=1)
	]
	
	purchase_invoice_gst_fields = [
			dict(fieldname='supplier_gstin', label='Supplier GSTIN',
				fieldtype='Data', insert_after='supplier_address',
				options='supplier_address.gstin', print_hide=1),
			dict(fieldname='company_gstin', label='Company GSTIN',
				fieldtype='Data', insert_after='shipping_address',
				options='shipping_address.gstin', print_hide=1)
		]
		
	sales_invoice_gst_fields = [
			dict(fieldname='customer_gstin', label='Customer GSTIN',
				fieldtype='Data', insert_after='shipping_address',
				options='shipping_address_name.gstin', print_hide=1),
			dict(fieldname='place_of_supply', label='Place of Supply',
				fieldtype='Data', insert_after='customer_gstin', print_hide=1,
				options='shipping_address_name.gst_state_number', read_only=1),
			dict(fieldname='company_gstin', label='Company GSTIN',
				fieldtype='Data', insert_after='company_address',
				options='company_address.gstin', print_hide=1)
		]
	
	custom_fields = {
		'Address': [
			dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
				insert_after='fax'),
			dict(fieldname='gst_state', label='GST State', fieldtype='Select',
				options='\n'.join(states), insert_after='gstin'),
			dict(fieldname='gst_state_number', label='GST State Number',
				fieldtype='Int', insert_after='gst_state', read_only=1),
		],
		'Purchase Invoice': purchase_invoice_gst_fields + invoice_gst_fields,
		'Sales Invoice': sales_invoice_gst_fields + invoice_gst_fields,
		"Delivery Note": sales_invoice_gst_fields,
		'Item': [
			dict(fieldname='gst_hsn_code', label='HSN/SAC',
				fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
		],
		'Quotation Item': [hsn_sac_field],
		'Supplier Quotation Item': [hsn_sac_field],
		'Sales Order Item': [hsn_sac_field],
		'Delivery Note Item': [hsn_sac_field],
		'Sales Invoice Item': [hsn_sac_field],
		'Purchase Order Item': [hsn_sac_field],
		'Purchase Receipt Item': [hsn_sac_field],
		'Purchase Invoice Item': [hsn_sac_field]
	}

	for doctype, fields in custom_fields.items():
		for df in fields:
			field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": df["fieldname"]})
			if not field:
				create_custom_field(doctype, df)
			else:
				custom_field = frappe.get_doc("Custom Field", field)
				custom_field.update(df)
				custom_field.save()
Example #40
0
def add_custom_fields():
	df = dict(
		fieldname='auto_repeat', label='Auto Repeat', fieldtype='Link', insert_after='sender',
		options='Auto Repeat')
	create_custom_field('ToDo', df)